Skip to content

Instantly share code, notes, and snippets.

@pinei
Created September 4, 2015 19:54
Show Gist options
  • Select an option

  • Save pinei/503cc68c449acab34a77 to your computer and use it in GitHub Desktop.

Select an option

Save pinei/503cc68c449acab34a77 to your computer and use it in GitHub Desktop.
Username token profile with CXF for SOAP Clients
import org.apache.cxf.endpoint.*;
import org.apache.cxf.ws.security.policy.model.Header;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
// ...
private static void addUsernameTokenProfileCXF(PapiWebService papiWebServicePort, String username) {
Client client = org.apache.cxf.frontend.ClientProxy.getClient(papiWebServicePort);
Endpoint cxfEndpoint = client.getEndpoint();
Map<String,Object> outProps = new HashMap<String,Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, username);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,
ClientPasswordCallback.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
try {
assert Class.forName("org.apache.cxf.ws.security.policy.interceptors.UsernameTokenInterceptorProvider").getName() != null;
}
catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment