2011-01-05 13 views
9

से SAML विशेषताओं को पढ़ना मैं XML फ़ाइल से SAML टोकन लोड कर रहा हूं।SAML टोकन

string certificatePath = @"D:\Projects\SAMLDemo\Server.pfx"; 
X509Certificate2 cert = new X509Certificate2(certificatePath, "shani"); 

string samlFilePath = @"D:\Projects\SAMLDemo\saml.xml"; 
XmlReader reader = XmlReader.Create(samlFilePath); 

List<SecurityToken> tokens = new List<SecurityToken>(); 
tokens.Add(new X509SecurityToken(cert)); 

SecurityTokenResolver outOfBandTokenResolver = SecurityTokenResolver.CreateDefaultSecurityTokenResolver(new ReadOnlyCollection<SecurityToken>(tokens), true); 
SecurityToken securityToken = WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, outOfBandTokenResolver); 

SamlSecurityToken deserializedSaml = securityToken as SamlSecurityToken; 

मैं deserializedSaml से SAML विशेषताओं को कैसे पढ़ सकता हूं?

मुझे विशेषताओं के लिए स्ट्रिंग मानों की आवश्यकता है।

+0

विषय पंक्ति में "सी #" डालने की वास्तव में कोई ज़रूरत नहीं है, क्योंकि आपको टैग में यह मिला है। –

+0

यह SAML 1 या 2 है? 'System.IdentityModel' क्लास प्रलेखन 2. – Rory

+0

आह के बजाय SAML 1.1 का संदर्भ देता है, अब मैं देखता हूं .नेट 4.5 में 'Saml2XXX' जैसे नाम वर्ग हैं, उदा। 'Saml2Assertion' http://msdn.microsoft.com/en-us/library/microsoft.identitymodel.tokens.saml2.saml2assertion.aspx – Rory

उत्तर

9

यह काम नहीं करता है?

foreach (SamlStatement statement in deserializedSaml.Assertion.Statements) 
{ 
    SamlAttributeStatement attributeStatement = statement as SamlAttributeStatement; 
    if (null != attributeStatement) 
    { 
    foreach (SamlAttribute attribute in attributeStatement.Attributes) 
    { 
     DoWhateverYouLikeWith(attribute); 
    } 
    } 
} 
संबंधित मुद्दे