4

次のような SAML アサーションの XML があります。

<saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_9b6e6302-d6a8-47f0-9155-1051a05edbfb" Issuer="http://example.com/adfs/services/trust" IssueInstant="2013-04-29T19:35:51.197Z" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
...
</saml:Assertion>

次のようなコードを使用して、この XML から SecurityToken を取得しようとしています。

// Loading the XML referenced above.
XDocument doc = XDocument.Load(new StringReader(assertion));

// Creating config to use in TokenHandlers below; required if not using a SecurityTokenHandlerCollection.
SecurityTokenHandlerConfiguration config = new SecurityTokenHandlerConfiguration();
config.AudienceRestriction.AllowedAudienceUris.Add(new Uri("https://localhost/Orchard/"));
config.CertificateValidator = X509CertificateValidator.None;

// Both of these lines throw Exceptions, as explained below.
new Saml11SecurityTokenHandler() { Configuration = config }.ReadToken(doc.CreateReader());
new Saml2SecurityTokenHandler() { Configuration = config }.ReadToken(doc.CreateReader());

を使用してトークンを読み取ろうとするとSaml11SecurityTokenHandler、次の例外が発生します。

ID4075: SAML アサーションに必要な「MajorVersion」属性がありません。

を使用してトークンを読み取ろうとするとSaml2SecurityTokenHandler、別の例外が発生します。

名前空間名が「urn:oasis:names:tc:SAML:2.0:assertion」の要素「Assertion」が見つかりませんでした。

Saml2SecurityTokenHandlerこれは SAML 1.1 アサーションであるため、当然のことです。しかし、SAML 1.1 TokenHandler がこのアサーションを読み取れないのはなぜでしょうか?

EDIT : リーダーは空に見えます。何故ですか? docコンテンツがあります。

string notEmpty = doc.FirstNode.ToString();
string empty = doc.CreateReader().ReadOuterXml();
4

1 に答える 1