WCF、声明、ADFS 3.0

WCF, Claims, ADFS 3.0

我想了解使用 WCF、Claims 和 ADFS 3.0 开发框架需要什么。内部用户将针对 Active Directory 进行身份验证,外部用户将针对 SQL 服务器 table 进行身份验证,并且授权存储在数据库 tables 中实现组和权限。我正在使用 WCF 而不是 Web Api 或 OWIN 创建 API。

我对使用 Identity Server 或第 3 方产品不感兴趣,我只想知道如何创建自定义安全令牌服务以读取我的成员身份 table 并通过我的组和权限设置声明table.

我找不到这方面的任何信息。 Visual Studio 2015 没有身份和访问控制而且似乎没有使用 WCF,只能使用 Web Api、OWIN 和 MVC?

当我像您一样开发声明感知 WCF 应用程序时,我 运行 通过这个 link 让我理解了它是如何工作的。唯一与您的需求不太相似的是它不是 ADFS 3.0。

而且我认为您不能同时将 ADFS 用于内部用户和 SQL 用于外部 "like membership" time/together .我所知道的是,您可以信任其他公司的 ADFS 作为其他身份提供者。

如果您指的是如何构建声明感知 WCF,这里有一些可用链接。

尽管如此,支持 .Net 4.5 和 4.6 的 link 仍然有效,并且 WIF 已经是框架的一部分,不像以前需要安装 WIF。

下面是我的 WCF 服务配置片段:

绑定

<bindings>
    <ws2007FederationHttpBinding>
        <binding name="ws2007FederationHttpBinding">
            <security mode="TransportWithMessageCredential">
                <message establishSecurityContext="false" negotiateServiceCredential="false">
                    <issuerMetadata address="https://<adfs server>:9643/adfs/services/trust/mex"/>
                    <issuer address="https://<asfs aserver>:9643/adfs/services/trust/13/usernamemixed"/>
                </message>
            </security>
        </binding>
    </ws2007FederationHttpBinding>
</bindings>

身份配置

<system.identityModel>
    <identityConfiguration name="serviceidentity">
        <audienceUris mode="Never">
            <add value="https://localhost/FedSecurity/"/>
        </audienceUris>
        <issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry">
            <authority name="http://<asfs aserver>:9643/adfs/services/trust">
                <keys >
                    <add thumbprint="8D6BF173ERERERFDFE9CE9CD0FB57FB57A5D68403EA88" name="http://<asfs aserver>:9643/adfs/services/trust" />
                </keys>
                <validIssuers>
                    <add name="http://<asfs aserver>:9643/adfs/services/trust" />
                </validIssuers>
            </authority>
        </issuerNameRegistry>
        <!--certificationValidationMode set to "None" by the the Identity and Access Tool for Visual Studio. For development purposes.-->
        <certificateValidation certificateValidationMode="None" />
    </identityConfiguration>
</system.identityModel>

我的 WCF 客户端的片段配置

<system.serviceModel>
        <bindings>
            <ws2007FederationHttpBinding>
                <binding name="ws2007FederationHttpBinding">
                    <security mode="TransportWithMessageCredential">
                        <message establishSecurityContext="false">
                            <issuer address="https://<adfs server>:9643/adfs/services/trust/13/usernamemixed"
                                binding="ws2007HttpBinding" bindingConfiguration="https://<adfs server>:9643/adfs/services/trust/13/usernamemixed" />
                            <issuerMetadata address="https://<adfs server>:9643/adfs/services/trust/mex" />
                            <tokenRequestParameters>
                                <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
                                    <trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/SymmetricKey</trust:KeyType>
                                    <trust:KeySize xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">256</trust:KeySize>
                                    <trust:KeyWrapAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p</trust:KeyWrapAlgorithm>
                                    <trust:EncryptWith xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptWith>
                                    <trust:SignWith xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2000/09/xmldsig#hmac-sha1</trust:SignWith>
                                    <trust:CanonicalizationAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/10/xml-exc-c14n#</trust:CanonicalizationAlgorithm>
                                    <trust:EncryptionAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptionAlgorithm>
                                </trust:SecondaryParameters>
                            </tokenRequestParameters>
                        </message>
                    </security>
                </binding>
            </ws2007FederationHttpBinding>
            <ws2007HttpBinding>
                <binding name="https://<adfs server>:9643/adfs/services/trust/13/usernamemixed">
                    <security mode="TransportWithMessageCredential">
                        <transport clientCredentialType="None" />
                        <message clientCredentialType="UserName" establishSecurityContext="false" />
                    </security>
                </binding>
            </ws2007HttpBinding>
        </bindings>
        <client>
            <endpoint address="https://localhost/FedSecurity/CloudService.svc"
                binding="ws2007FederationHttpBinding" bindingConfiguration="ws2007FederationHttpBinding"
                contract="CloudBeta.ICloudSevice" name="ws2007FederationHttpBinding" />
        </client>
</system.serviceModel>

附加信息:

  • 我使用了 ADFS 2.0 和 UserName 身份验证,并添加了凭据 我们的活动目录
  • 依赖方的添加不是这里讨论的,而是需要的。
  • 令牌 encryption/decryption 的证书也是必需的(AFDS 的一方)
  • 在 ADFS 中添加声明

希望以上信息对您有所帮助!

这篇文章对你来说似乎是一个好的开始,http://southworks.com/blog/2007/03/11/the-holly-grail-of-enterprise-soa-security/

这是我在 MVC 应用程序中使用的代码(不是 WCF,但需要完成的许多事情都是相同的)

var claims = new List<Claim>()
            {
                new Claim(ClaimTypes.Name, result.UserName),
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", result.Email),
                new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider",
                    result.Email),
                new Claim("UserId", result.Id.ToString(CultureInfo.InvariantCulture)),
                new Claim("UserName", result.UserName),
                new Claim("FirstName", result.FirstName)
            };

        //load claims from database here
        claims.AddRange(result.Roles.Select(role => new Claim(ClaimTypes.Role, role.Name)));

        var id = new ClaimsIdentity(claims, "Forms");
        var cp = new ClaimsPrincipal(id);
        var token = new SessionSecurityToken(cp)
        {
            IsPersistent = false

        };

        Session["authToken"] = token;

        var sam = FederatedAuthentication.SessionAuthenticationModule;
        sam.WriteSessionTokenToCookie(token);