【发布时间】:2014-09-03 05:49:33
【问题描述】:
我有一个类似于以下的 XML 文件。
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
Destination="https://hostname.example.com:4444/fed/idp/samlv20"
ID="id-OPIfhD3il2eK816THPlj2Nk38KM-"
IssueInstant="2014-09-02T14:36:02Z"
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Version="2.0"
>
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
>https://federation.example.com/sp</saml:Issuer>
<samlp:NameIDPolicy AllowCreate="true"
Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"
/>
<samlp:RequestedAuthnContext Comparison="exact">
<saml:AuthnContextClassRef xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
</samlp:RequestedAuthnContext>
</samlp:AuthnRequest>
如何使用JDOM从上述XML中获取内容“https://federation.example.com/sp”?
我正在尝试下面的代码并能够成功检索“IssueInstant”和“ProtocolBinding”。但无法检索内容“https://federation.example.com/sp”。请帮忙。
private String[] getRequestAttributes(String xmlString) throws SamlException {
Document doc = Util.createJdomDoc(xmlString);
if (doc != null) {
String[] samlRequestAttributes = new String[2];
samlRequestAttributes[0] = doc.getRootElement().getAttributeValue(
"IssueInstant");
samlRequestAttributes[2] = doc.getRootElement().getAttributeValue(
"ProtocolBinding");
return samlRequestAttributes;
}
}
【问题讨论】: