Search in sources :

Example 1 with SamlInvocationContext

use of org.keycloak.adapters.saml.profile.SamlInvocationContext in project keycloak by keycloak.

the class EcpAuthenticationHandler method handle.

@Override
public AuthOutcome handle(OnSessionCreated onCreateSession) {
    String header = facade.getRequest().getHeader(PAOS_HEADER);
    if (header != null) {
        return doHandle(new SamlInvocationContext(), onCreateSession);
    } else {
        try {
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage soapMessage = messageFactory.createMessage(null, facade.getRequest().getInputStream());
            SOAPBody soapBody = soapMessage.getSOAPBody();
            Node authnRequestNode = soapBody.getFirstChild();
            Document document = DocumentUtil.createDocument();
            document.appendChild(document.importNode(authnRequestNode, true));
            String samlResponse = PostBindingUtil.base64Encode(DocumentUtil.asString(document));
            return doHandle(new SamlInvocationContext(null, samlResponse, null), onCreateSession);
        } catch (Exception e) {
            throw new RuntimeException("Error creating fault message.", e);
        }
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) SamlInvocationContext(org.keycloak.adapters.saml.profile.SamlInvocationContext) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException)

Aggregations

MessageFactory (javax.xml.soap.MessageFactory)1 SOAPBody (javax.xml.soap.SOAPBody)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 SamlInvocationContext (org.keycloak.adapters.saml.profile.SamlInvocationContext)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1