2

Windows AzureのAppFabric STSによって生成されたSAML2トークンを受け入れる、「構成不要WIF」を試しています。そのように私がやっていることはトークン情報のため、現在のリクエストをチェックし解析しているコードからWindows Identity Foundationを構成する

、:

 if (Request.Form.Get(WSFederationConstants.Parameters.Result) != null) 
     { 
      SignInResponseMessage message = 
       WSFederationMessage.CreateFromFormPost(System.Web.HttpContext.Current.Request) as SignInResponseMessage; 

      var securityTokenHandlers = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection();      

      XmlTextReader xmlReader = new XmlTextReader(
       new StringReader(message.Result)); 

      SecurityToken token = securityTokenHandlers.ReadToken(xmlReader); 

      if (token != null) 
      { 
       ClaimsIdentityCollection claims = securityTokenHandlers.ValidateToken(token); 
       IPrincipal principal = new ClaimsPrincipal(claims); 
      } 
     } 

上記のコードはSecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollectionを(使用しています)。 SAMLトークンを検証して処理するためのcolection。ただし、アプリケーションが正しく構成されていないため、これは機能しません。私のsecurityTokenHandlersコレクションで、XMLから次の設定をプログラマチックに指定するにはどうすればよいですか?

<microsoft.identityModel> 
<service> 
    <audienceUris> 
    <add value="http://www.someapp.net/" /> 
    </audienceUris> 
    <federatedAuthentication> 
    <wsFederation passiveRedirectEnabled="true" issuer="https://rd-test.accesscontrol.appfabriclabs.com/v2/wsfederation" realm="http://www.thisapp.net" requireHttps="false" /> 
    <cookieHandler requireSsl="false" /> 
    </federatedAuthentication> 
    <applicationService> 
    <claimTypeRequired> 
     <claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" optional="true" /> 
     <claimType type="http://schemas.microsoft.com/ws/2008/06/identity/claims/role" optional="true" /> 
    </claimTypeRequired> 
    </applicationService> 
    <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> 
    <trustedIssuers> 
     <add thumbprint="XYZ123" name="https://somenamespace.accesscontrol.appfabriclabs.com/" /> 
    </trustedIssuers> 
    </issuerNameRegistry> 
</service> 

答えて

0

を修正することによりthe RedirectingToIdentityProvider eventで、送り出された時点で変更することができますXMLで物事のいくつかは:解決策を見つけたと説明したモジュールでそれを実装しました(そしてリンクされた)ここに:http://blog.maartenballiauw.be/post/2011/02/14/Authenticate-Orchard-users-with-AppFabric-Access-Control-Service.aspx

+0

リンクが再び動作します – maartenba

0

だけ考え、これが機能するかどうか全く分からない:(あなたのケースでは空である)実際のXMLで取得し、中クラスを介して、実行時にそれを変更する方法がありませんMicrosoft.IdentityModel.Configuration

また、あなたがサインイン要求がSignInRequestMessage FYI

+0

WsFederationAuthenticationModuleを使用していないので、Web.configにモジュールやIdentityModelの設定を登録しないでください。あなたが言及した実行時の設定の変更を調べ、カスタムIssuerTokenValidatorsなどを書いていることについて他の何かを見つけました。何かがうまくいくなら、私はそれを参照として投稿します。 – maartenba

2

私は同じことに苦労していて、WIF 3.5/4.0の実用的な解決策を見つけました。 maartenbaのリンクが死んでいるようだから、ここで私の解決策を投稿したいと思っていました。

当社の要件は以下の通りであった。

  • コンフィギュ完全
  • 最大許容.NETバージョン4.0(我々はアプリでデフォルトのweb.configファイルを出荷として)コードで(それゆえ、私は使用していますWIF 3.5/4.0)
  • 私は解に到達するために使用何

:ダイナミックWIF設定Pについて

  • 情報ダニエル・ウー(Daniel Wu)によって導かれる here
  • This method 実行時にHTTPモジュールを登録するには、David Ebboが説明します。私も より洗練された方法を試しましたexplained by Rick Strahl、 しかし、残念なことに私のためのトリックをしなかった。

編集2016年9月2日:代わり別個追加デビッドエボの例のように、クラス「予備出願は スタートコード」もの静的コンストラクタに登録することができる WIF関連HTTPモジュール`HttpApplication 'クラスの 私はコードをこの幾分 クリーナーソリューションに適合させました。

解決方法何もない in web.config。大部分のコードはglobal.asax.csにあります。コンフィギュレーションは、ハードコードされたこのサンプルである:

using System; 
using System.IdentityModel.Selectors; 
using System.Security.Cryptography.X509Certificates; 
using System.Web; 
using Microsoft.IdentityModel.Tokens; 
using Microsoft.IdentityModel.Web; 

namespace TestADFS 
{ 
    public class SessionAuthenticationModule : Microsoft.IdentityModel.Web.SessionAuthenticationModule 
    { 
    protected override void InitializePropertiesFromConfiguration(string serviceName) 
    { 
    } 
    } 
    public class WSFederationAuthenticationModule : Microsoft.IdentityModel.Web.WSFederationAuthenticationModule 
    { 
    protected override void InitializePropertiesFromConfiguration(string serviceName) 
    { 
     ServiceConfiguration = FederatedAuthentication.ServiceConfiguration; 
     PassiveRedirectEnabled = true; 
     RequireHttps = true; 
     Issuer = "https://nl-joinadfstest.joinadfstest.local/adfs/ls/"; 
     Realm = "https://67px95j.decos.com/testadfs"; 
    } 
    } 

    public class Global : HttpApplication 
    { 
    static Global() 
    { 
     Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(SessionAuthenticationModule)); 
     Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(WSFederationAuthenticationModule)); 
    } 

    protected void Application_Start(object sender, EventArgs e) 
    { 
     FederatedAuthentication.ServiceConfigurationCreated += FederatedAuthentication_ServiceConfigurationCreated; 
    } 

    internal void FederatedAuthentication_ServiceConfigurationCreated(object sender, Microsoft.IdentityModel.Web.Configuration.ServiceConfigurationCreatedEventArgs e) 
    { 
     X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); 
     store.Open(OpenFlags.ReadOnly); 
     X509Certificate2Collection coll = store.Certificates.Find(X509FindType.FindByThumbprint, "245537E9BB2C086D3C880982FA86267FBD66B9A3", false); 
     if (coll.Count > 0) 
     e.ServiceConfiguration.ServiceCertificate = coll[0]; 
     store.Close(); 
     AudienceRestriction ar = new AudienceRestriction(AudienceUriMode.Always); 
     ar.AllowedAudienceUris.Add(new Uri("https://67px95j.decos.com/testadfs")); 
     e.ServiceConfiguration.AudienceRestriction = ar; 
     ConfigurationBasedIssuerNameRegistry inr = new ConfigurationBasedIssuerNameRegistry(); 
     inr.AddTrustedIssuer("6C9B96D90257B65B6F181C2478D869473DC359EA", "http://NL-JOINADFSTEST.joinadfstest.local/adfs/services/trust"); 
     e.ServiceConfiguration.IssuerNameRegistry = inr; 
     e.ServiceConfiguration.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; 
    } 

    protected void Application_AuthenticateRequest(object sender, EventArgs e) 
    { 
     FederatedAuthentication.WSFederationAuthenticationModule.ServiceConfiguration = FederatedAuthentication.ServiceConfiguration; 
    } 
    } 
} 

使用

私のアプリは、古典的なパイプラインモードで実行されている、asp.net Webフォームで、フォーム認証だけでなく、ADFSログインをサポートしています。そのため、認証はすべての.aspxページに共通の基底クラスで処理されます:ApplicationRootUrlは「/」で終わるアプリケーションのパスで、このコードで

protected override void OnInit(EventArgs e) 
    { 
     if (NeedsAuthentication && !User.Identity.IsAuthenticated) 
     { 
     SignInRequestMessage sirm = new SignInRequestMessage(
      new Uri("https://nl-joinadfstest.joinadfstest.local/adfs/ls/"), 
      ApplicationRootUrl) 
     { 
      Context = ApplicationRootUrl, 
      HomeRealm = ApplicationRootUrl 
     }; 
     Response.Redirect(sirm.WriteQueryString()); 
     } 
     base.OnInit(e); 
    } 

(「/」クラシックパイプラインで重要ですモード)。

混在モードでのログアウトの安定した実装はあまり簡単ではなかったので、そのコードも示したいと思います。技術的にそれは動作しますが、私はまだすぐにADFSのアカウントをログアウトした後、再度ログインIEの問題があります。

 if (User.Identity.IsAuthenticated) 
     { 
     if (User.Identity.AuthenticationType == "Forms") 
     { 
      FormsAuthentication.SignOut(); 
      Session.Clear(); 
      Session.Abandon(); 
      ResetCookie(FormsAuthentication.FormsCookieName); 
      ResetCookie("ASP.NET_SessionId"); 
      Response.Redirect(ApplicationRootUrl + "Default.aspx"); 
      HttpContext.Current.ApplicationInstance.CompleteRequest(); 
     } 
     else 
     { 
      FederatedAuthentication.SessionAuthenticationModule.SignOut(); 
      FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie(); 
      Uri uri = new Uri(ApplicationRootUrl + "Default.aspx"); 
      WSFederationAuthenticationModule.FederatedSignOut(
      new Uri("https://nl-joinadfstest.joinadfstest.local/adfs/ls/"), 
      uri); // 1st url is single logout service binding from adfs metadata 
     } 
     } 

ResetCookieは、応答クッキーをクリアし、過去に有効期限を設定するヘルパー関数です)

+0

IEの問題は、ADFSがボックスから構成されているために、そのブラウザ用のADFSフォームベースの認証ではなくWIAが試行されたためです。 ADFSサーバー上のこのPowerShell cmdは、これが行われたブラウザを示します。 'Get-AdfsProperties | -ExpandProperty WIASupportedUserAgents' すべてのブラウザでWIAを無効にするには、ブラウザ以外のクライアントにのみ設定を変更します。 'Set-AdfsProperties -WIASupportedUserAgents(" MSAuthHost/1.0/In-Domain "、" MSIPC "、" Windows Rights Management Client ")' これは私の問題を解決しました –

関連する問題