用于具有 usernametoken 配置文件的安全 Web 服务的 JAXWS Metro 客户端

发布于 2024-11-28 04:31:30 字数 1603 浏览 1 评论 0原文

我想使用一个使用 oasis 风格的用户名令牌配置文件的网络服务( 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 客户端:

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()));

i want to consume a webservice that uses oasis style username token profile ( http://www.oasis-open.org/committees/download.php/16782/wss-v1.1-spec-os... ).

I was able to do it with CXF and Weblogic clients BUT iw woul like to use a pure Metro client.

Do you know how can I do that ?

Thanks.

CXF sample:

 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()));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢你一世 2024-12-05 04:31:31
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);
}}
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);
}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文