質問

私はしばらくの間、これに対して頭を打ち負かしていて、進歩を始めています。しかし、SAML 2アサーション(XML)の文字列表現をアサーションオブジェクトに変換するのに苦労しました。

私は有効になっているようです org.w3c.dom.Document 適切なデータがあり、私は有効になっているようです SAMLObjectBuilder<Assertion> ビルダーの工場からですが、私がそれらをまとめようとすると、私が得るのは空白の主張です。件名、発行者、発行時間などがすべてです null, 、それらは明らかにXMLに設定されています。

誰かが私が間違っていることを見て、解決策を提案することができますか?

Document doc = loadXMLFromString(saml);

XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();

SAMLObjectBuilder<Assertion> assertionBuilder =
  (SAMLObjectBuilder<Assertion>)
  builderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME);

Assertion assertion = assertionBuilder.buildObject(doc.getDocumentElement());

String nameID = assertion.getSubject().getNameID().getValue();

nameIdの割り当てで、 assertion.getSubject() 戻り値 null, 、表現の残りの部分に失敗します。

私が使用している例は、SSTC-SAML-Tech-Overview-2.0-Draft-03、10ページの完全なXMLです。

関数 loadXMLFromString() 上記はほとんどが借りられています Javaでは、ファイルの代わりにXMLを文字列として解析するにはどうすればよいですか?

役に立ちましたか?

解決

他の誰かが同じ問題に直面していて、これを駆け抜けている場合、答えはここにあります。

https://wiki.shibboleth.net/confluence/display/opensaml/ostwousrmanjavacreatefromxml

未測定の例を挙げてください:

String inCommonMDFile = "/data/org/opensaml/saml2/metadata/InCommon-metadata.xml";

// Initialize the library
DefaultBootstrap.bootstrap(); 

// Get parser pool manager
BasicParserPool ppMgr = new BasicParserPool();
ppMgr.setNamespaceAware(true);

// Parse metadata file
InputStream in = MetadataTest.class.getResourceAsStream(inCommonMDFile);
Document inCommonMDDoc = ppMgr.parse(in);
Element metadataRoot = inCommonMDDoc.getDocumentElement();

// Get apropriate unmarshaller
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(metadataRoot);

// Unmarshall using the document root element, an EntitiesDescriptor in this case
EntitiesDescriptor inCommonMD = (EntitiesDescriptor) unmarshaller.unmarshall(metadataRoot);

次に、ドキュメントインスタンスを置き換えます inCommonMDDoc そして、決勝の結果を見てください unmarshall() 電話。ご了承ください unmarshall() andを返します Object 適切なタイプにキャストする必要があります。ヒント:使用できます typeof どんなタイプかわからないが、相続に注意してください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top