I am trying to connect to a web service using WS-Security UsernameToken spec 1.0 using apache cxf 2.4.0.
I copied the code from CXF documents, but I get: org.apache.cxf.ws.policy.PolicyException: username is not available
MyService_Service ss = new MyService_Service(wsdlURL, SERVICE_NAME); MyService port = ss.getBasicHttpBindingMyService (); Client client = ClientProxy.getClient(port); 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, ClientPasswordHandler.class.getName()); WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); cxfEndpoint.getOutInterceptors().add(wssOut);
I also implemented the ClientPasswordHandler class, again from the docs, but it looks like the username is never sent (according to the error). Here is the password handler:
public class ClientPasswordHandler implements CallbackHandler { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]; pc.setPassword("Password"); } }
Is there a way to see if a WSS4Jinterceptor is being applied and a UsernameToken is being sent?
java web-services ws-security cxf
bwsmith
source share