【问题标题】:PolicyException: None of the policy alternatives can be satisfied in WCF Service CallPolicyException:在 WCF 服务调用中不能满足任何策略替代方案
【发布时间】:2014-03-17 09:22:02
【问题描述】:

我使用 Apache axis 1.4 创建了 Web 服务客户端。我正在访问的 wcf 服务是 STS 服务,它需要 AppliesTo 参数及其返回 SAML 令牌。我在搜索时浏览了各种博客和网站,以及我是如何来到这个kanbancoding Part 3 所以我通过它并在我的代码中进行更改,但现在我得到 org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives can be meet. 我的

【问题讨论】:

    标签: java wsdl axis wcf-security


    【解决方案1】:

    经过大量尝试和错误后,我弄清楚了调用 WCF STS 服务到底需要什么。凝视时,我在 Docs.Oasis OOasis WS Trust 1.3 上找到了一个文档,其中详细解释了需要在肥皂消息中发送哪些数据,是的,在 kanbancoding 的帮助下,这是我调用 STS 的方法

    private static void getSecurityToken() {
            try {
                // Use the empty constructor – no need to specify wsdl
                SecurityTokenService src = new SecurityTokenService();
    
                // Pull the class used to negotiate WS Trust directly from the
                // SecurityTokenService
                IWSTrust13Sync trust = src.getBasicHttpBindingIWSTrust13Sync();
    
                JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
                factory.setServiceClass(IWSTrust13Sync.class);
                factory.setAddress(ServiceURL);
                IWSTrust13Sync service = (IWSTrust13Sync) factory.create();
    
                // Obtain a reference to the CXF endpoint using the ClientProxy helper:
                Client client = ClientProxy.getClient(service);
    
                // Set up logging if desired
                client.getOutInterceptors().add(new LoggingOutInterceptor());
                client.getInInterceptors().add(new LoggingInInterceptor());
                client.getRequestContext().put("com.sun.xml.ws.connect.timeout", 1 * 60 * 1000);
                client.getRequestContext().put("com.sun.xml.ws.request.timeout", 5 * 60 * 1000);
    
                // Specify the user we want to authenticate
                client.getRequestContext().put("ws-security.username", UserName);
                client.getRequestContext().put("ws-security.password", Password);
    
                HTTPConduit http = (HTTPConduit) client.getConduit();
                http.getAuthorization().setUserName(UserName);
                http.getAuthorization().setPassword(Password);
                http.getClient().setConnectionTimeout(36000);
                http.getClient().setAllowChunking(false);
    
                RequestSecurityTokenType token = new RequestSecurityTokenType();
    
                Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                Element tokenType = document.createElementNS("http://docs.oasis-open.org/ws-sx/ws-trust/200512",
                        "TokenType");
                tokenType.setTextContent("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0");
    
                token.getAny().add(tokenType);
    
                Element requestType = document.createElementNS("http://docs.oasis-open.org/ws-sx/ws-trust/200512",
                        "RequestType");
                requestType.setTextContent("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue");
                token.getAny().add(requestType);
    
                Document appliesTodoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                Element appliesTo = appliesTodoc.createElementNS("http://schemas.xmlsoap.org/ws/2004/09/policy",
                        "AppliesTo");
    
                Element endPoint = appliesTodoc.createElementNS("http://schemas.xmlsoap.org/ws/2004/08/addressing",
                        "EndpointReference");
    
                Element address = appliesTodoc.createElementNS("http://schemas.xmlsoap.org/ws/2004/08/addressing",
                        "Address");
                address.setTextContent("http://localhost");
    
                endPoint.appendChild(address);
                appliesTo.appendChild(endPoint);
    
                token.getAny().add(appliesTo);
    
                //Now specify what claims we want back.
                Document claimsDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    
                Element claims = claimsDoc.createElementNS("http://docs.oasis-open.org/ws-sx/ws-trust/200512", "Claims");
                claims.setAttribute("Dialect", "http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice");
    
                // Add claims to token request
                //token.getAny().add(claims);
    
                RequestSecurityTokenResponseCollectionType result = service.trust13Issue(token);
    
                //parseResponse(result);
                List<RequestSecurityTokenResponseType> response = result.getRequestSecurityTokenResponse();
    
                Iterator<RequestSecurityTokenResponseType> itr = response.iterator();
    
                while (itr.hasNext()) {
                    RequestSecurityTokenResponseType obj = itr.next();
                    List<Object> responseObject = obj.getAny();
                    Iterator<Object> ObjItr = responseObject.iterator();
                    while (ObjItr.hasNext()) {
                        System.out.println("Result " + ObjItr.next());
                    }
    
                }
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

    但在我想要的方面没有完全成功,但是我得到的回应是在 Apache CFX 日志中而不是在结果对象中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多