Search in sources :

Example 1 with SAML2Request

use of org.keycloak.saml.processing.api.saml.v2.request.SAML2Request in project keycloak by keycloak.

the class SamlSPFacade method getSamlAuthnRequest.

/*
    * https://idp.ssocircle.com/sso/toolbox/samlEncode.jsp
    *
    * returns (https instead of http in case ssl is required)
    * 
    * <samlp:AuthnRequest 
    *     xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" 
    *     xmlns="urn:oasis:names:tc:SAML:2.0:assertion" 
    *     AssertionConsumerServiceURL="http://localhost:8280/employee/" 
    *     Destination="http://localhost:8180/auth/realms/demo/protocol/saml" 
    *     ForceAuthn="false" 
    *     ID="ID_4d8e5ce2-7206-472b-a897-2d837090c005" 
    *     IsPassive="false" 
    *     IssueInstant="2015-03-06T22:22:17.854Z" 
    *     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">saml-employee</saml:Issuer> 
    *         <samlp:NameIDPolicy AllowCreate="true" Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"/> 
    * </samlp:AuthnRequest> 
    */
private URI getSamlAuthnRequest(HttpServletRequest req) {
    try {
        BaseSAML2BindingBuilder binding = new BaseSAML2BindingBuilder();
        SAML2Request samlReq = new SAML2Request();
        String appServerUrl = ServletTestUtils.getUrlBase() + "/employee/";
        String authServerUrl = ServletTestUtils.getAuthServerUrlBase() + "/auth/realms/demo/protocol/saml";
        AuthnRequestType loginReq;
        loginReq = samlReq.createAuthnRequestType(UUID.randomUUID().toString(), appServerUrl, authServerUrl, "http://localhost:8280/employee/");
        loginReq.getNameIDPolicy().setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_UNSPECIFIED.getUri());
        return binding.redirectBinding(SAML2Request.convert(loginReq)).requestURI(authServerUrl);
    } catch (IOException | ConfigurationException | ParsingException | ProcessingException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) ConfigurationException(org.keycloak.saml.common.exceptions.ConfigurationException) ParsingException(org.keycloak.saml.common.exceptions.ParsingException) BaseSAML2BindingBuilder(org.keycloak.saml.BaseSAML2BindingBuilder) IOException(java.io.IOException) SAML2Request(org.keycloak.saml.processing.api.saml.v2.request.SAML2Request) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Example 2 with SAML2Request

use of org.keycloak.saml.processing.api.saml.v2.request.SAML2Request in project keycloak by keycloak.

the class SamlClient method createLoginRequestDocument.

/**
 * Creates a SAML login request document with the given parameters. See SAML &lt;AuthnRequest&gt; description for more details.
 *
 * @param issuer
 * @param assertionConsumerURL
 * @param destination
 * @return
 */
public static AuthnRequestType createLoginRequestDocument(String issuer, String assertionConsumerURL, URI destination) {
    try {
        SAML2Request samlReq = new SAML2Request();
        AuthnRequestType loginReq = samlReq.createAuthnRequestType(UUID.randomUUID().toString(), assertionConsumerURL, destination == null ? null : destination.toString(), issuer);
        return loginReq;
    } catch (ConfigurationException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) ConfigurationException(org.keycloak.saml.common.exceptions.ConfigurationException) SAML2Request(org.keycloak.saml.processing.api.saml.v2.request.SAML2Request)

Example 3 with SAML2Request

use of org.keycloak.saml.processing.api.saml.v2.request.SAML2Request in project keycloak by keycloak.

the class CreateAuthnRequestStepBuilder method createLoginRequestDocument.

protected Document createLoginRequestDocument() {
    if (this.forceLoginRequestDocument != null) {
        return this.forceLoginRequestDocument;
    }
    try {
        SAML2Request samlReq = new SAML2Request();
        AuthnRequestType loginReq = samlReq.createAuthnRequestType(UUID.randomUUID().toString(), assertionConsumerURL, this.authServerSamlUrl.toString(), issuer, requestBinding.getBindingUri());
        if (protocolBinding != null) {
            loginReq.setProtocolBinding(protocolBinding);
        }
        return SAML2Request.convert(loginReq);
    } catch (ConfigurationException | ParsingException | ProcessingException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) ConfigurationException(org.keycloak.saml.common.exceptions.ConfigurationException) ParsingException(org.keycloak.saml.common.exceptions.ParsingException) SAML2Request(org.keycloak.saml.processing.api.saml.v2.request.SAML2Request) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Aggregations

AuthnRequestType (org.keycloak.dom.saml.v2.protocol.AuthnRequestType)3 ConfigurationException (org.keycloak.saml.common.exceptions.ConfigurationException)3 SAML2Request (org.keycloak.saml.processing.api.saml.v2.request.SAML2Request)3 ParsingException (org.keycloak.saml.common.exceptions.ParsingException)2 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)2 IOException (java.io.IOException)1 BaseSAML2BindingBuilder (org.keycloak.saml.BaseSAML2BindingBuilder)1