我想使用一个使用oasis风格的用户名令牌配置文件的web服务(http://www.oasis-open.org/committees/download.php/16782/wss-v1.1-spec-os…).
我能够用CXF和Weblogic客户端做到这一点,但我想使用纯Metro客户端。
你知道我该怎么做吗?
谢谢。CXF示例:
serviceClientPort = clientFactory.buildClientPort(wsdlUrl,null);
org.apache.cxf.endpoint.Client clientProxy = ClientProxy.getClient(serviceClientPort);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = clientProxy.getEndpoint();
Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, "someuser");
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,CapHardcodedPassProvider.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
Weblogic client:
CallService callService = new CallService(wsdlUrl,CAP_QNAME);
CallServicePort port = callService.getCallServiceSoapPort(new WebServiceFeature[] { cpf });
BindingProvider bindingProvider = (BindingProvider) port;
Map<String, Object> rc = (Map<String, Object>) bindingProvider.getRequestContext();
List<CredentialProvider> credProviders = new ArrayList<CredentialProvider>();
credProviders.add(new ClientUNTCredentialProvider(USERNAME.getBytes(), PASSWORD.getBytes()));
private void addUsernameTokenProfile(WebService webServicePort, String username, String password) {
try
{
final String SECURITY_NAMESPACE =
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
SOAPFactory soapFactory = SOAPFactory.newInstance();
QName securityQName = new QName(SECURITY_NAMESPACE, "Security");
SOAPElement security = soapFactory.createElement(securityQName);
QName tokenQName = new QName(SECURITY_NAMESPACE, "UsernameToken");
SOAPElement token = soapFactory.createElement(tokenQName);
QName userQName = new QName(SECURITY_NAMESPACE, "Username");
SOAPElement soapUsername = soapFactory.createElement(userQName);
soapUsername.addTextNode(username);
QName passwordQName = new QName(SECURITY_NAMESPACE, "Password");
SOAPElement soapPassword = soapFactory.createElement(passwordQName);
soapPassword.addTextNode(password);
token.addChildElement(soapUsername);
token.addChildElement(soapPassword);
security.addChildElement(token);
Header header = Headers.create(security);
((WSBindingProvider) webServicePort).setOutboundHeaders(header);
}}