簡體   English   中英

使用和ADFS實現ACS作為STS

[英]Implementing ACS with and ADFS as STS

我們正在嘗試使用ACS示例4(來自http://claimsid.codeplex.com/ )作為ADFS項目的模板。 對ADFS身份驗證服務的被動請求沒有問題。 在示例中,聯合提供程序是自定義STS,並且示例工作正常。

現在我們希望用自己的ADFS替換自定義聯合提供程序(示例中的Adatum FP)。

我們現在的設置如下(隱藏名稱空間)

  • ServiceClient:控制台應用程序,調用服務
  • 服務:WCF Webservice,返回字符串的Single方法。 這是默認[Ordertracking.Services in sample]
  • Services.Authentication:我們的自定義身份提供商。 這是默認的[Litware.SimulatedIssuer in sample]
  • ADFS:我們的聯邦提供商[FederationProvider.Adatum in example]

ServiceClient想要調用服務,並且從配置中知道它必須從IP(Services.Authentication)獲取令牌。 然后將令牌傳遞給ADFS,ADFS驗證令牌並將新令牌發送回ServiceClient。 客戶端new將FP令牌傳遞給服務,並且服務(作為ADFS上的依賴方)根據ADFS驗證令牌,並執行服務方法。

問題:

用ADFS替換示例中的STS似乎打破了集成。 我們似乎正在從IP中正確獲取令牌,但是在將IP令牌傳遞給ADFS時遇到了問題。 看來我們的Audience Uri有問題,但我們補充道

https://'adfs fqdn'/ adfs / services / Trust / 13 / IssuedTokenMixedSymmetricBasic256

客戶端異常我們在客戶端中使用此InnerException InnerException獲取MessageSecurityException {“ID3242:無法對安全令牌進行身份驗證或授權。”}

[System.ServiceModel.FaultException]: {"ID3242: The security token could not be authenticated or authorized."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "ID3242: The security token could not be authenticated or authorized."
Source: null
StackTrace: null
TargetSite: null

ADFS調試日志

<TraceRecord xmlns="http://schemas.microsoft.com/2009/10/IdentityModel/TraceRecord" Severity="Error">
    <Description>Handled exception.</Description>
    <AppDomain>Microsoft.IdentityServer.ServiceHost.exe</AppDomain>
    <Exception>
        <ExceptionType>Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</ExceptionType>
        <Message>ID1038: The AudienceRestrictionCondition was not valid because the specified Audience is not present in AudienceUris. Audience: 'https://<adfs fqdn>/adfs/services/Trust/13/IssuedTokenMixedSymmetricBasic256'</Message>
        <StackTrace>
  at Microsoft.IdentityModel.Tokens.SamlSecurityTokenRequirement.ValidateAudienceRestriction(IList`1 allowedAudienceUris, IList`1 tokenAudiences) at Microsoft.IdentityModel.Tokens.Saml2.Saml2SecurityTokenHandler.ValidateConditions(Saml2Conditions conditions, Boolean enforceAudienceRestriction) at Microsoft.IdentityModel.Tokens.Saml2.Saml2SecurityTokenHandler.ValidateToken(SecurityToken token) at Microsoft.IdentityServer.Service.Tokens.MSISSaml2TokenHandler.ValidateToken(SecurityToken token) at Microsoft.IdentityModel.Tokens.WrappedSaml2SecurityTokenAuthenticator.ValidateTokenCore(SecurityToken token) at System.IdentityModel.Selectors.SecurityTokenAuthenticator.ValidateToken(SecurityToken token) at Microsoft.IdentityModel.Tokens.WrappedSamlSecurityTokenAuthenticator.ValidateTokenCore(SecurityToken token) at System.IdentityModel.Selectors.SecurityTokenAuthenticator.ValidateToken(SecurityToken token) at System.ServiceModel.Security.ReceiveSecurityHeader.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver, IList`1 allowedTokenAuthenticators, SecurityTokenAuthenticator&amp;amp; usedTokenAuthenticator) at
  ....
        </StackTrace>
    </Exception>
</TraceRecord>

我們已將觀眾uri添加到我們的IP Web.config:

<audienceUris mode="Always">
    <add value="https://<adfs fqdn>/adfs/services/Trust/13/IssuedTokenMixedSymmetricBasic256" />
</audienceUris>

如有必要,我們可以發布ADFS配置的其他配置文件和屏幕截圖。

這需要一些工作,但我們終於解決了這個問題。 我們不是配置它,而是在代碼中構建連接。 我想我們可能在客戶端配置中的某個地方出現了錯誤。

對嘗試此操作的任何人提出一些建議 - 首先在代碼中構建連接。 XML配置有點難以使用。

我們在leastprivilege.com上找到了一些示例代碼

private static SecurityToken GetIdPToken()
    {

        var factory = new WSTrustChannelFactory(
            new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
            "https://systemidp.dk/Issuer.svc");
        factory.TrustVersion = TrustVersion.WSTrust13;

        factory.Credentials.UserName.UserName = "LITWARE\\rick";
        factory.Credentials.UserName.Password = "thisPasswordIsNotChecked";

        var rst = new RequestSecurityToken
        {
            RequestType = WSTrust13Constants.RequestTypes.Issue,
            AppliesTo = new EndpointAddress("https://adfsfqdn/adfs/services/trust"),
            KeyType = WSTrust13Constants.KeyTypes.Symmetric,
            ReplyTo = "https://adfsfqdn/adfs/services/trust/13/issuedtokenmixedsymmetricbasic256/"
        };
        factory.ConfigureChannelFactory();
        var channel = factory.CreateChannel();
        return channel.Issue(rst);
    }

    private static SecurityToken GetRSTSToken(SecurityToken idpToken)
    {
        var binding = new IssuedTokenWSTrustBinding();
        binding.SecurityMode = SecurityMode.TransportWithMessageCredential;

        var factory = new WSTrustChannelFactory(
            binding,
            "https://adfsfqdn/adfs/services/trust/13/issuedtokenmixedsymmetricbasic256/");
        factory.TrustVersion = TrustVersion.WSTrust13;
        factory.Credentials.SupportInteractive = false;

        var rst = new RequestSecurityToken
        {
            RequestType = WSTrust13Constants.RequestTypes.Issue,
            AppliesTo = new EndpointAddress("https://services.dk/WebService.svc"),
            KeyType = WSTrust13Constants.KeyTypes.Symmetric
        };

        factory.ConfigureChannelFactory();
        var channel = factory.CreateChannelWithIssuedToken(idpToken);
        return channel.Issue(rst);
    }

使用令牌創建WCF調用

var ipdtoken = GetIdPToken();
var stsToken = GetRSTSToken(ipdtoken);
var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Message.EstablishSecurityContext = false;
var factory = new ChannelFactory<IWebService>(binding, "https://services.dk/WebService.svc");

factory.ConfigureChannelFactory();
factory.Credentials.SupportInteractive = false;

var serviceChannel = factory.CreateChannelWithIssuedToken(stsToken);

var s = serviceChannel.GetUserInformation();

您的IP上的audienceUri配置看起來很好。 我認為ADFS是一個拋出ID3242錯誤的人。 您是否可以檢查以確保在ADFS服務器上的Claim Provider Trusts下正確配置了IP?

如果您的IP聯合元數據很方便,您也可以嘗試在ADFS中重新創建它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM