3

Conditions ノードに AudienceRestriction を含む SamlAssertion を作成する例の方向性を教えてください。

以下は、配置したいコードの例です。

//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>

3 番目のパラメーターである条件を許可するSamlConditionsクラスのコンストラクターがあり、 SamlAudienceRestriction クラスがあることがわかりますが、2 つを接続する方法がわかりません。少しコードを見れば、それは痛々しいほど明白になると思いますが、残念ながら、私の google-foo は今日私を失敗させています.

4

1 に答える 1

6

投稿する前にこれを理解するのに数時間を費やしたことを誓います...しかし、どうやら投稿は私が答えを見るのに必要なものだったようです。以下は、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
    );

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

于 2009-08-28T21:19:15.910 に答える