9

私はしばらくこれに頭を悩ませてきました、そして進歩し始めています。しかし、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、式の残りの部分は失敗します。

私が使用している例は、10ページのsstc-saml-tech-overview-2.0-draft-03の完全なXMLです。

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

4

1 に答える 1

9

他の誰かが同じ問題に直面していて、これに遭遇した場合、ここに答えがあります。

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

次に、Documentインスタンスを置き換えてinCommonMDDoc、最後のunmarshall()呼び出しの結果を確認します。適切なタイプにキャストする必要があるをunmarshall()返すことに注意してください。ヒント:タイプがわからない場合Objectはuseを使用できますが、継承には注意してください。typeof

于 2011-01-12T14:24:00.743 に答える