'Remove <?xml version="1.0" encoding="UTF-8"?> From SAML Request

I'm currently using spring-security-saml2-service-provider to build SAML integration with 3rd party, and I want to remove the XML header from the SAML auth request is there any way to remove the header, I tried to customize the request by using

  OpenSamlInitializationService.requireInitialize(factory -> {
            AuthnRequestMarshaller marshaller = new AuthnRequestMarshaller() {
                @Override
                public Element marshall(XMLObject object, Element element) throws MarshallingException {

                   configureAuthnRequest((AuthnRequest) object);

                    return super.marshall(object,element);
                }

                public Element marshall(XMLObject object, Document document) throws MarshallingException {
                   
                    configureAuthnRequest((AuthnRequest) object);
      
                    return super.marshall(object, document);
                }

                private void configureAuthnRequest(AuthnRequest authnRequest) {

                    NameIDPolicyBuilder nameIDPolicy = new NameIDPolicyBuilder();
                    nameIDPolicy.buildObject("urn:oasis:names:tc:SAML:2.0:nameid-format:transient",""
                            ,"");

                   
                }
            };

            QName SAML_ELEMENT_NAME = new QName("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest", "samlp");
            factory.getMarshallerFactory().registerMarshaller(SAML_ELEMENT_NAME, marshaller);
        });
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source