gpt4 book ai didi

java - 策略异常 : None of the policy alternatives can be satisfied in WCF Service Call

转载 作者:行者123 更新时间:2023-12-01 13:16:08 32 4
gpt4 key购买 nike

我使用 Apache axis 1.4 创建了 Web 服务客户端。我正在访问的 wcf 服务是 STS 服务,需要 AppliesTo 参数及其返回的 SAML token 。我在搜索时浏览了各种博客和网站,以及我是如何找到这个的kanbancoding Part 3因此,我仔细检查并在代码中进行了更改,但现在我得到了org.apache.cxf.ws.policy.PolicyException:没有任何策略替代方案可以得到满足。我的

最佳答案

经过多次尝试和错误,我弄清楚我到底需要什么来调用 WCF STS 服务。我在 Docs.Oasis O Oasis 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 Log 中得到响应,而不是在结果对象中。

关于java - 策略异常 : None of the policy alternatives can be satisfied in WCF Service Call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22450568/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com