Question

Quelqu'un peut-il me s'il vous plaît pointer dans la direction d'un exemple la création d'un SamlAssertion qui comprend un AudienceRestriction dans le nœud Conditions?

ci-dessous est un exemple de mon code où je voudrais le mettre:

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

Le XML souhaité ressemble à ceci:

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

Je vois qu'il ya un constructeur pour la classe SamlConditions qui permet pour un 3ème paramètre, les conditions, et qu'il ya une classe SamlAudienceRestriction, mais je ne peux pas sembler comprendre comment relier les deux. Je pense que si je devais voir un peu de code, il deviendrait me douloureusement évident, mais malheureusement, mon google-foo me manque aujourd'hui.

Était-ce utile?

La solution

Je jure que j'ai passé plusieurs heures à essayer de comprendre cela avant de poster ... mais apparemment était exactement l'affichage ce que je devais voir la réponse. Voici le code que je l'ai fait pour créer la restriction d'audience pour le 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
    );

Si quelqu'un voit quelque chose de mal, ou sait d'une façon meilleure / plus efficace, s'il vous plaît laissez-moi savoir.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top