سؤال

هل يمكن لشخص ما توجيهني في اتجاه مثال على إنشاء 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>

أرى أن هناك مُنشئًا SamlConditions الفئة التي تسمح بمعلمة ثالثة ، والشروط ، وأن هناك فئة Samlaudiencerestriction ، لكن لا يمكنني معرفة كيفية توصيل الاثنين. أعتقد أنه إذا كنت سأرى القليل من التعليمات البرمجية ، فسيصبح ذلك واضحًا بشكل مؤلم بالنسبة لي ، لكن لسوء الحظ ، فإن Google-Foo الخاص بي تفشلني اليوم.

هل كانت مفيدة؟

المحلول

أقسم أنني قضيت عدة ساعات في محاولة لمعرفة هذا الأمر قبل النشر ... ولكن يبدو أن النشر كان بالضبط ما كنت بحاجة لرؤية الإجابة. فيما يلي الرمز الذي قمت به لإنشاء قيود الجمهور على 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
    );

إذا رأى أي شخص أي خطأ ، أو يعرف طريقة أفضل/أكثر كفاءة ، فيرجى إخبارنا بذلك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top