0

We are trying to change our user password soap webservice to use openID Connect. So the webservice authentication code is looking in the header for an Authorization header that contains "Bearer ".

I am just trying to write a webservice and this is currently how we setup the username and password.

public void bindPort(javax.xml.ws.BindingProvider binding)
{
  String endpointUrl = (String) binding.getRequestContext().get(
    BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
  binding.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
    getEndpointUrl(endpointUrl, m_webserviceUrl));
  binding.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, m_user );
  binding.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);

I have done some googleing and found the WSBindingProvider but as it is a com.sun class we are not allowed to use them due to the diverse platforms we support.

I saw another post that looks like it answers this question, but the code looks horrible and it is quite old (2012), so I am hoping a better solution must have been provided since then. Add SOAP header object using pure JAX-WS

Community
  • 1
  • 1
WendyG
  • 570
  • 5
  • 29

1 Answers1

1

You can pass HTTP headers by putting them into the request context. For example:

Map<String, List<String>> headers = new LinkedHashMap<>();

headers.put("Authorization", Collections.singletonList("Bearer " + token));

binding.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
William
  • 66
  • 5