2

我正在尝试实现以下场景:

  1. 客户将其凭证传递给 STS。
  2. STS 应用自定义 AuthorizationPolicy 来确定可供特定用户使用的声明集并颁发安全令牌。
  3. 客户端将令牌传递给业务服务,业务服务根据他们从令牌中获得的声明集来确定用户的权限。

看起来第一步是主要问题。正如MSDN建议的那样,wsFederationHttpBinding 的消息元素没有 clientCredentialsType。因此,每当我的 AuthorizationPolicy 检查 evaluationContext.Properties["Identities"] 时,它都会在其中看到 WindowsIdentity。我想针对自定义存储(DB)对用户进行身份验证。

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

4

1 回答 1

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");
    }
}
于 2009-04-24T12:16:57.047 回答