WCF使用自定义STS

时间:2015-04-26 18:44:32

标签: wcf wif role sts-securitytokenservice

我通过覆盖SecurityTokenService并使用WCF托管它来创建STS。我也创建了一个依赖方和测试客户端。客户端成功重定向到STS(如果我在GetOutputIdentity方法中放置断点,程序将停止)。现在我需要拒绝我的RP中除一个角色以外的所有用户的访问权限。我该怎么做?她是我的配置:

protected override ClaimsIdentity GetOutputClaimsIdentity(ClaimsPrincipal principal, 
        RequestSecurityToken request, 
        Scope scope)
    {
        string authenticationType = principal.Identity.AuthenticationType;

        var outputIdentity = new ClaimsIdentity(authenticationType);

        outputIdentity.AddClaim(new Claim(ClaimTypes.Role, role));
        outputIdentity.AddClaim(new Claim(ClaimTypes.Name, userName));
        return outputIdentity;
    }

依赖方配置:

<customBinding>
        <binding name="secureBinding">
          <security authenticationMode="IssuedToken" requireDerivedKeys="false" >
            <issuedTokenParameters>
              <issuer address="http://localhost:1318/Services/SecurityTokenService.svc">
              </issuer>
              <issuerMetadata address="http://localhost:1318/Services/SecurityTokenService.svc/mex"></issuerMetadata>
            </issuedTokenParameters>
          </security>
          <httpTransport></httpTransport>
        </binding>
      </customBinding>

1 个答案:

答案 0 :(得分:0)

您可以使用自定义AuthorizationManager来验证RP的每次调用。此类提供 CheckAccess 方法,根据传入的声明实现自定义验证。