Search in sources :

Example 36 with AuthnRequestType

use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.

the class KcSamlBrokerTest method loginInResponseToEmpty.

// KEYCLOAK-17935
@Test
public void loginInResponseToEmpty() throws Exception {
    AuthnRequestType loginRep = SamlClient.createLoginRequestDocument(AbstractSamlTest.SAML_CLIENT_ID_SALES_POST + ".dot/ted", getConsumerRoot() + "/sales-post/saml", null);
    Document doc = SAML2Request.convert(loginRep);
    new SamlClientBuilder().authnRequest(getConsumerSamlEndpoint(bc.consumerRealmName()), doc, Binding.POST).build().login().idp(bc.getIDPAlias()).build().processSamlResponse(// AuthnRequest to producer IdP
    Binding.POST).targetAttributeSamlRequest().build().login().user(bc.getUserLogin(), bc.getUserPassword()).build().processSamlResponse(// Response from producer IdP
    Binding.POST).transformDocument(this::clearInResponseTo).build().execute(// Response from consumer IdP
    hr -> assertThat(hr, statusCodeIsHC(Response.Status.BAD_REQUEST)));
}
Also used : AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) SamlClientBuilder(org.keycloak.testsuite.util.SamlClientBuilder) Document(org.w3c.dom.Document) AbstractSamlTest(org.keycloak.testsuite.saml.AbstractSamlTest) Test(org.junit.Test)

Example 37 with AuthnRequestType

use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.

the class SAML2Request method createAuthnRequestType.

/**
 * Create an authentication request
 *
 * @param id
 * @param assertionConsumerURL
 * @param destination
 * @param issuerValue
 * @param protocolBindingUri
 *
 * @return
 *
 * @throws ConfigurationException
 */
public AuthnRequestType createAuthnRequestType(String id, String assertionConsumerURL, String destination, String issuerValue, URI protocolBinding) throws ConfigurationException {
    XMLGregorianCalendar issueInstant = XMLTimeUtil.getIssueInstant();
    AuthnRequestType authnRequest = new AuthnRequestType(id, issueInstant);
    authnRequest.setAssertionConsumerServiceURL(URI.create(assertionConsumerURL));
    authnRequest.setProtocolBinding(protocolBinding);
    if (destination != null) {
        authnRequest.setDestination(URI.create(destination));
    }
    // Create an issuer
    NameIDType issuer = new NameIDType();
    issuer.setValue(issuerValue);
    authnRequest.setIssuer(issuer);
    // Create a default NameIDPolicy
    NameIDPolicyType nameIDPolicy = new NameIDPolicyType();
    nameIDPolicy.setAllowCreate(Boolean.TRUE);
    nameIDPolicy.setFormat(this.nameIDFormat == null ? null : URI.create(this.nameIDFormat));
    authnRequest.setNameIDPolicy(nameIDPolicy);
    return authnRequest;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) NameIDPolicyType(org.keycloak.dom.saml.v2.protocol.NameIDPolicyType) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType)

Example 38 with AuthnRequestType

use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.

the class SAML2Request method getAuthnRequestType.

/**
 * Get the AuthnRequestType from an input stream
 *
 * @param is Inputstream containing the AuthnRequest
 *
 * @return
 *
 * @throws ParsingException
 * @throws ProcessingException
 * @throws ConfigurationException
 * @throws IllegalArgumentException inputstream is null
 */
public AuthnRequestType getAuthnRequestType(InputStream is) throws ConfigurationException, ProcessingException, ParsingException {
    if (is == null)
        throw logger.nullArgumentError("InputStream");
    Document samlDocument = DocumentUtil.getDocument(is);
    SAMLParser samlParser = SAMLParser.getInstance();
    JAXPValidationUtil.checkSchemaValidation(samlDocument);
    AuthnRequestType requestType = (AuthnRequestType) samlParser.parse(samlDocument);
    samlDocumentHolder = new SAMLDocumentHolder(requestType, samlDocument);
    return requestType;
}
Also used : SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) SAMLParser(org.keycloak.saml.processing.core.parsers.saml.SAMLParser) Document(org.w3c.dom.Document)

Example 39 with AuthnRequestType

use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.

the class SAML2AuthnRequestBuilder method createAuthnRequest.

public AuthnRequestType createAuthnRequest() {
    AuthnRequestType res = this.authnRequestType;
    res.setIssuer(issuer);
    res.setDestination(URI.create(this.destination));
    if (!this.extensions.isEmpty()) {
        ExtensionsType extensionsType = new ExtensionsType();
        for (NodeGenerator extension : this.extensions) {
            extensionsType.addExtension(extension);
        }
        res.setExtensions(extensionsType);
    }
    return res;
}
Also used : AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) ExtensionsType(org.keycloak.dom.saml.v2.protocol.ExtensionsType)

Example 40 with AuthnRequestType

use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.

the class SAMLRequestedAuthnContextParser method instantiateElement.

/**
 * Parse the attributes at the authnrequesttype element
 *
 * @param startElement
 *
 * @return
 *
 * @throws ParsingException
 */
@Override
protected RequestedAuthnContextType instantiateElement(XMLEventReader xmlEventReader, StartElement startElement) throws ParsingException {
    RequestedAuthnContextType context = new RequestedAuthnContextType();
    Attribute comparison = startElement.getAttributeByName(SAMLProtocolQNames.ATTR_COMPARISON.getQName());
    if (comparison != null) {
        context.setComparison(AuthnContextComparisonType.fromValue(comparison.getValue()));
    }
    return context;
}
Also used : Attribute(javax.xml.stream.events.Attribute) RequestedAuthnContextType(org.keycloak.dom.saml.v2.protocol.RequestedAuthnContextType)

Aggregations

AuthnRequestType (org.keycloak.dom.saml.v2.protocol.AuthnRequestType)56 Test (org.junit.Test)41 Document (org.w3c.dom.Document)36 SamlClientBuilder (org.keycloak.testsuite.util.SamlClientBuilder)30 AbstractSamlTest (org.keycloak.testsuite.saml.AbstractSamlTest)21 Element (org.w3c.dom.Element)16 Closeable (java.io.Closeable)13 SAMLDocumentHolder (org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder)13 IdentityProviderAttributeUpdater (org.keycloak.testsuite.updaters.IdentityProviderAttributeUpdater)13 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)10 ConfigurationException (org.keycloak.saml.common.exceptions.ConfigurationException)8 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)7 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)7 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)7 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 Matchers.containsString (org.hamcrest.Matchers.containsString)5 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)5 SAML2Request (org.keycloak.saml.processing.api.saml.v2.request.SAML2Request)4 URI (java.net.URI)3