2011-03-23 58 views
2

我有一個使用的wsHttpBinding與信息安全和Windows身份驗證的WCF服務。模擬聲明的身份驗證的SharePoint 2010

控制檯應用程序服務客戶端能夠調用服務,並且我可以看到ServiceSecurityContext.Current.WindowsIdentity和Thread.CurrentPrincipal.Identity都代表正確的用戶。

的currentprincipal是IClaimsIdentity,符合市場預期。我得到否定的錯誤提示模擬的標識無法傳遞到數據庫或SharePoint服務器的訪問:

的問題,當我嘗試打開SharePoint網站出現。這一切都在同一臺機器上,所以不應該有任何雙跳認證問題。

這難道不是對一個聲明應用託管服務做無頭驗證的正確方法?

+0

如何打開SP Web?你使用接受SPUserToken的構造函數重載嗎? – Timores 2011-03-23 12:48:44

+0

我也試過了。看來我的IClaimsIdentity是Microsoft.IdentityModel.WindowsClaimsIdentity,而不是Microsoft.IdentityModel.ClaimsIdentity。如果IClaimsIdentity對象只是ClaimsIdentity,SharePoint的SPUserToken構造器將引發異常。 – BoldBob 2011-03-23 13:14:13

+0

我想你需要改變主張。您是否嘗試從WindowsClaimsIdentity實例化ClaimsIdentity? – Timores 2011-03-23 14:21:59

回答

0

目前,我有部署在啓用聲明的SharePoint 2010網站WCF服務。 WCF服務沒什麼特別,我使用提供的Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory作爲WCF服務工廠。因此,我使用工廠提供的開箱即用的BasicHttpBinding。

我的客戶的app.config如下所示:

<configuration> 
    <system.serviceModel> 
    <bindings> 
     <binding name="BasicHttpBinding_MyServices" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="200524288" maxBufferPoolSize="200524288" maxReceivedMessageSize="200524288" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
     </binding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost/_vti_bin/MyServices/MyService.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyServices" 
     contract="ServiceClient.MyService.IMyService" 
     name="BasicHttpBinding_IMyService" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

當我看着Thread.CurrentPrincipal.Identity,它是正確的。它是我當前執行的用戶的ClaimsIdentity。然後,我可以直接打開一個新的SPSite實例,而無需創建或使用SPUserToken。

一個關鍵一點要注意:我沒有連接到WCF服務之前,冒充我的身份。如果這就是您正在做的事情,除非您的SharePoint服務器與您的聲明提供商建立了信任關係,否則它不可能正常工作。

相關問題