【问题标题】:Claims-based Sharepoint site and Apache CXF STSClient communication基于声明的 Sharepoint 站点和 Apache CXF STSClient 通信
【发布时间】:2016-11-14 17:30:04
【问题描述】:

我们目前正在开展一个项目,我们需要在使用基于声明的身份验证的 Sharepoint 2016 站点中访问 Sharepoint Foundation Web 服务 API。用于提供声明的安全令牌服务是托管在 Win2k12 服务器上的 ADFS 2.0。用户需要提供他的电子邮件地址才能进行身份验证并获取安全令牌以进行进一步操作。

注意:由于这是一个开发设置,我们正在为 ADFS 端点使用自签名证书

我们使用 Apache CXF 2.7.12 和 JDK 8 作为客户端开发堆栈来访问此 Web 服务。当我们请求令牌时,会在 WARNING 级别记录与 HttpsToken 断言失败相关的异常,然后什么也没有发生。调用没有完成,我们必须终止进程。

由于这是我们第一次使用 CXF;请求有关如何解决此问题的帮助和指导。我们参考了以下网站进行初步调查,但似乎都没有帮助我们解决这个特定问题:

Using Apache CXF to connect CRM Dynamics

Apache CXF Client Configuration options

以下是 URL 上可用的 Sharepoint 站点的 WS-Policy

<wsp:Policy wsu:Id="UserNameWSTrustBinding_IWSTrust13Async_policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding>
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken/>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedEncryptedSupportingTokens>
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SignedEncryptedSupportingTokens>
<sp:EndorsingSupportingTokens>
<wsp:Policy>
<sp:KeyValueToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never" wsp:Optional="true"/>
<sp:SignedParts>
<sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
</sp:SignedParts>
</wsp:Policy>
</sp:EndorsingSupportingTokens>
<sp:Wss11>
<wsp:Policy/>
</sp:Wss11>
<sp:Trust13>
<wsp:Policy>
<sp:MustSupportIssuedTokens/>
<sp:RequireClientEntropy/>
<sp:RequireServerEntropy/>
</wsp:Policy></sp:Trust13>
<wsaw:UsingAddressing/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>

我们现在配置 STSClient 如下:

STSClient spSTSClient = new STSClient(bus);
spSTSClient.setTrust(new Trust10(SP12Constants.INSTANCE));
spSTSClient.setSoap12();


//would we also also need to set the token type and key type?

// spSTSClient.setTokenType("urn:oasis:names:tc:SAML:2.0:assertion");
//spSTSClient.setKeyType("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer");        

spSTSClient.setWsdlLocation("https://myadfsserver.com/adfs/services/trust/mex");
spSTSClient.setServiceName("{http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice}SecurityTokenService");
    spSTSClient.setEndpointName("{http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice}UserNameWSTrustBinding_IWSTrust13Async");
            spSTSClient.setAddressingNamespace("http://www.w3.org/2005/08/addressing");    String sharePointUsername = “user@mysharepoint.COM";
String sharePointPassword = “foobar#”;

SecurityToken secToken = spsSTSClient.requestSecurityToken("http://mysharepointsite.com/_trust");

requestSecurityToken 调用会引发如下所示的警告:

WARNING: Interceptor for {http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice}SecurityTokenService#{http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice}Trust13IssueAsync has thrown exception, unwinding now
org.apache.cxf.ws.policy.PolicyException: Assertion of type {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}HttpsToken could not be asserted: Not an HTTPs connection
    at org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider$HttpsTokenOutInterceptor.assertHttps(HttpsTokenInterceptorProvider.java:144)
    at org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider$HttpsTokenOutInterceptor.handleMessage(HttpsTokenInterceptorProvider.java:87)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:570)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:479)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:382)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:335)

【问题讨论】:

    标签: java apache web-services sharepoint cxf


    【解决方案1】:

    WSDL 要求使用 TransportBinding,但您没有使用“https” URL,例如:“http://mysharepointsite.com/_trust

    【讨论】:

    • 感谢您的回复。我意识到这是代码中的错字。但是,即使在进行此更改之后;问题仍然存在。解决此问题的唯一方法是使用空 WSP 策略指定策略覆盖。但我知道这是一个Hack。有关故障排除的任何其他提示都会很棒。此外,使用这个空策略 XML,Https 错误消失了,但现在我收到一条错误消息,提示 {docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}TransportBinding: Received Timestamp does not match the requirements.这意味着什么?
    猜你喜欢
    • 2011-07-15
    • 2012-12-24
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 2011-10-04
    相关资源
    最近更新 更多