【问题标题】:WCF Service Authentication + SitecoreWCF 服务身份验证 + Sitecore
【发布时间】:2014-10-29 09:55:16
【问题描述】:

我们目前正在 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?

【问题讨论】:

  • 我猜是因为身份验证依赖于消息,而不是它没有被拾取的传输级别......
  • 您找到解决方案了吗?同样的问题
  • @geedubb 我添加了我们用来解决问题的答案

标签: asp.net wcf authentication sitecore


【解决方案1】:

最后我们通过在服务的构造函数中包含以下内容来解决这个问题,因为我们的 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));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多