需要处理WS-Security客户端。我使用cxf 3.1.11版本在java代码下面写了。
WSSSecurityProperties properties = new WSSSecurityProperties();
properties.addAction(WSSConstants.USERNAMETOKEN);
properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
properties.setTokenUser("test");
properties.setCallbackHandler(new UTPasswordCallback());
properties.addAction(WSSConstants.TIMESTAMP);
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.addAction(WSSConstants.USERNAMETOKEN);
inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
inProperties.setCallbackHandler(new UTPasswordCallback());
inProperties.addAction(WSSConstants.TIMESTAMP);
GreetingDetailsService detailsService = new GreetingDetailsService();
GreetingDetails details = detailsService.getGreetingDetailsPort();
Client client = ClientProxy.getClient(details);
client.getOutInterceptors().add(new WSS4JStaxOutInterceptor(properties));
client.getInInterceptors().add(new WSS4JStaxInInterceptor(inProperties));
肥皂要求:
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-4F89DE365A2FAA9F8E14957130295985">
<wsse:Username>test</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">abcdefgh</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">m83qX0a/bD3xOLXGOLR1bA==</wsse:Nonce>
<wsu:Created>2017-05-25T11:50:29.598Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
运行java代码时出现org.apache.cxf.binding.soap.SoapFault: "A security error was encountered when verifying the message"
错误消息
请建议我如何处理这个问题。