簡體   English   中英

WCF服務身份驗證+ Sitecore

[英]WCF Service Authentication + Sitecore

我們目前正在Sitecore中實施WCF服務以執行某些任務。 但是,我們希望保護和驗證這些交互,以保持Sitecore安全模型的完整性。

我們使用以下配置進行身份驗證(僅相關配置和匿名化):

<service name="Services.MailService" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="wsHttpBinding" contract="Interfaces.IMailService"/>
</service>
<behavior name="serviceBehavior">
    <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Services.Authentication.CustomServiceAuthentication, MyLibrary" />
    </serviceCredentials>
</behavior>
<wsHttpBinding>
    <binding>
        <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" />
            <transport clientCredentialType="None">
            </transport>
        </security>
    </binding>
</wsHttpBinding>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>

定制驗證器從UserNamePasswordValidator繼承,並使用標准Sitecore.Security.Authentication.AuthenticationManager.Login()方法登錄用戶。 在此確切時刻,用戶確實已登錄,並顯示為Sitecore.Context.User。 但是當到達WCF方法本身時,此身份驗證就消失了。 (由於匿名用戶而導致來自Sitecore的訪問異常沒有添加項權限)

經過一些測試和研究了交互之后,我注意到問題是WCF使用了多個消息,因此使用了多個HttpContext。 Cookie和登錄名不會在請求之間保留。 更深入地看,我注意到System.ServiceModel.ServiceSecurityContext.Current確實保留了安全登錄名,但是只有在輸入WCF方法后才會顯示(如果無法在Sitecore httpBeginRequest管道中使用此方法來標識和登錄UserResolver上的用戶) )

如何確保整個調用過程中對asp.net和wcf都進行了正確的身份驗證?

最后,由於我們將InstanceContextMode設置為PerCall,因此通過在服務的構造函數中包含以下內容來解決此問題:

// Handle login for Sitecore to sync with the WCF security context
if (ServiceSecurityContext.Current != null)
{
    AuthenticationManager.Login(
    string.Format("{0}\\{1}", "yoursitecoredomain", ServiceSecurityContext.Current.PrimaryIdentity.Name));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM