Opensaml xmlns is not generated on nameIDPolicy and AuthnContext

喜欢而已 提交于 2020-01-05 07:09:11

问题


Hi i want my xml look like this:

<samlp:NameIDPolicy 
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
    Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
    AllowCreate="true">
</samlp:NameIDPolicy>

my setup with opensaml is:

// NameIDPolicy
nameIdPolicyBuilder = new NameIDPolicyBuilder();
nameIdPolicy = nameIdPolicyBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:protocol", "NameIDPolicy", "samlp");
nameIdPolicy.setFormat("urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress");
nameIdPolicy.setAllowCreate(new Boolean(true));

// Creation of AuthRequestObject
issueInstant = new DateTime();
authRequestBuilder = new AuthnRequestBuilder();
authRequest = authRequestBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest", "samlp");
authRequest.setForceAuthn(new Boolean(false));
authRequest.setIsPassive(new Boolean(false));
authRequest.setIssueInstant(issueInstant);
authRequest.setProtocolBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
authRequest.setAssertionConsumerServiceURL(consumerUrl);
authRequest.setIssuer(issuer);
authRequest.setNameIDPolicy(nameIdPolicy);
authRequest.setRequestedAuthnContext(requestedAuthnContext);

but the result is:

<samlp:NameIDPolicy 
    AllowCreate="true" 
    Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" />

Same happens to AuthnContext object.

Code i use for encoding the Request:

private String encodeAuthnRequest(AuthnRequest authnRequest) throws MarshallingException, IOException {

    org.opensaml.core.xml.io.Marshaller marshaller = null;
    org.w3c.dom.Element authDOM = null;
    java.io.StringWriter requestWriter = null;
    String requestMessage = null;
    java.util.zip.Deflater deflater = null;
    java.io.ByteArrayOutputStream byteArrayOutputStream = null;
    java.util.zip.DeflaterOutputStream deflaterOutputStream = null;
    String encodedRequestMessage = null;


    marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(authnRequest.getElementQName());


    authDOM = marshaller.marshall(authnRequest); // converting to a DOM

    requestWriter = new StringWriter();
    org.opensaml.xml.util.XMLHelper.writeNode(authDOM, requestWriter);
    requestMessage = requestWriter.toString(); // DOM to string

    deflater = new Deflater(Deflater.DEFLATED, true);
    byteArrayOutputStream = new ByteArrayOutputStream();
    deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater);
    deflaterOutputStream.write(requestMessage.getBytes()); // compressing
    deflaterOutputStream.close();

    encodedRequestMessage = org.opensaml.xml.util.Base64.encodeBytes(byteArrayOutputStream.toByteArray(), org.opensaml.xml.util.Base64.DONT_BREAK_LINES);
    encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, "UTF-8").trim(); // encoding
                                                                                        // string

    return encodedRequestMessage;

}

来源:https://stackoverflow.com/questions/41116985/opensaml-xmlns-is-not-generated-on-nameidpolicy-and-authncontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!