2009-08-28 5 views
3

「条件」ノードにAudienceRestrictionを含むSamlAssertionを作成する例の方に私を指摘できますか?以下AudienceRestriction in SAML Assertion

私はそれを置きたいと思うでしょう私のコードの例です:

//Create the SAML Assertion 
SamlAssertion samlAssert = new SamlAssertion(); 
samlAssert.AssertionId = Convert.ToBase64String(encoding.GetBytes(System.Guid.NewGuid().ToString())); 
samlAssert.Issuer = "http://www.example.com/"; 

// Set up the conditions of the assertion - Not Before and Not After 
samlAssert.Conditions = new SamlConditions(DateTime.Now, DateTime.Now.AddMinutes(5)); 

希望XMLは、このようなものになります。

<Assertion xmlns="urn:oasis:names:tc:SAML:1.0:assertion" AssertionID="_e835eca079133299b2f8a2a63ad72fe8" IssueInstant="2007-02-07T20:22:58.165Z" Issuer="http://www.example.com/" MajorVersion="1" MinorVersion="1"> 
<Conditions NotBefore="2007-02-07T20:22:58.162Z" NotOnOrAfter="2007-02-07T20:24:58.162Z"> 
    <AudienceRestrictionCondition> 
    <Audience>http://www.example2.com</Audience> 
    </AudienceRestrictionCondition> 
</Conditions> 

を私はSamlConditionsクラスのコンストラクタがあることを見ます3番目のパラメータ、条件、そしてSamlAudienceRestrictionクラスがありますが、2つを接続する方法を理解できないようです。私は少しコードを見なければならないと思うが、それは痛いほど明白になるだろうが、残念ながら、私のgoogle-fooは今日私に失敗している。

+0

これを生成するためにどのライブラリを使用していますか? ComponentSpace?ありがとう。 – dana

答えて

5

私は数時間を費やして投稿する前にこれを理解しようとしていると誓っています...しかし明らかに投稿は正確に私が答えを見るのに必要なものでした。以下は、私がSAMLのために観客の制限を作成するためにやったコードは次のとおりです。

//Create the SAML Assertion 
SamlAssertion samlAssert = new SamlAssertion(); 
samlAssert.AssertionId = Convert 
    .ToBase64String(
    encoding.GetBytes(System.Guid.NewGuid().ToString())); 
samlAssert.Issuer = "http://www.example.com/"; 

// Set up the conditions of the assertion - Not Before and Not After 
Uri[] approvedAudiences = {new Uri("http://www.example2.com")}; 
List<SamlCondition> conditions = new List<SamlCondition>(); 
conditions.Add(new SamlAudienceRestrictionCondition(approvedAudiences)); 
samlAssert.Conditions = new SamlConditions(
    DateTime.Now, 
    DateTime.Now.AddMinutes(5), 
    conditions 
    ); 

誰が間違った何かを見ている、またはより良い/より効率的な方法を知っている場合は、私に知らせてください。

+0

ええ、AudienceRestriction - かなり紛らわしいクラス - は、SamlAudienceRestrictionConditionクラスとSaml2AudienceRestrictionクラスのより一般的なものでなければなりません –

関連する問題