I'm using Apache-CXF to create my web service client that uses ws-security with a UsernameToken
authentification.
In order to use the same credentials for every request I just add the following properties to my BindingProvider
(i.e. the ws-port):
Map<String, Object> ctx = bindingProvider.getRequestContext();
ctx.put(SecurityConstants.USERNAME, "myUserName");
ctx.put(SecurityConstants.PASSWORD, "myPassword");
However, how can I set a different user and password on every request? Is it possible to add some kind of supplier function to the UsernameTokenInterceptor
to provide the credential on a per-thread basis (e.g. by readinig them out of a ThreadLocal
variable)?
As workaround I implemented a SOAPHandler<SOAPMessageContext>
that modifies the Username
and Password
value in the Security/UsernameToken
part of the SOAPHeader
. However, I'd prefer to either add an existing SOAPHandler
that creates the whole security section or to provide a supplier function to the UsernameTokenInterceptor
.