wsFederationHttpBinding,将自定义用户标识传递给STS

时间:2009-04-22 15:35:49

标签: .net wcf wcf-security

我正在尝试实施以下方案:

  1. 客户将其问卷传递给STS。
  2. STS应用自定义AuthorizationPolicy来确定特定用户可用的权利要求集并发出安全令牌。
  3. 客户端将令牌传递给业务服务,业务服务根据他们从令牌获得的一组声明来确定用户的权限。
  4. 看起来第一步是主要问题。由于 MSDN建议wsFederationHttpBinding的message元素没有clientCredentialsType。因此,只要我的AuthorizationPolicy检查了evaluationContext.Properties [“Identities”],它就会在其中看到WindowsIdentity。我想根据自定义存储(DB)对用户进行身份验证。

    有没有办法用wsFederationHttpBinding来完成它?

1 个答案:

答案 0 :(得分:1)

嗯,这是答案

STS配置:

<behaviors>
     <serviceBehaviors>
         <behavior name="STSBehaviour">
             <!--Custom credentials processing-->
             <serviceCredentials>
                 <userNameAuthentication userNamePasswordValidationMode="Custom" 
                                         customUserNamePasswordValidatorType="SecurityTokenService.UserNameValidator, SecurityTokenService"/>
             </serviceCredentials>
             <!--------------------------------->
         </behavior>
    </serviceBehaviors>
</behaviors>
<bindings>
    <wsHttpBinding>
        <binding name="wsHttpUsername">
            ...
            <security mode="Message">
                <message clientCredentialType="UserName"
                         negotiateServiceCredential="false"
                         establishSecurityContext="false" />
            </security>
            ...
        </binding>
    </wsHttpBinding>
</bindings>
<services>
    <service behaviorConfiguration ="STSBehaviour"
               name="Microsoft.ServiceModel.Samples.SecurityTokenService" >
           ....
    </service>
</services>

用户名验证器

public class UserNameValidator : UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        if (!VerifyCredentials(userName, password))
            throw new SecurityException("Invalid credentials");
    }
}