2009-08-28 89 views
3

有人可以请我指出创建SamlAssertion的示例的方向,该示例在Conditions节点中包含AudienceRestriction?SAML Assertion中的AudienceRestriction

下面

就是我希望把它放在我的代码示例:

//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类它允许第三个参数,条件,还有一个SamlAudienceRestriction类,但我似乎无法弄清楚如何连接这两个。我想如果我看到一些代码,这对我来说会变得很痛苦,但不幸的是,我的google-foo今天让我失望。

+0

你用什么库来生成这个库? ComponentSpace?谢谢。 – dana 2012-03-02 18:08:46

回答

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类的更一般的对应物 – 2014-05-23 20:32:26