Search in sources :

Example 6 with NameIDPolicyType

use of org.keycloak.dom.saml.v2.protocol.NameIDPolicyType 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 7 with NameIDPolicyType

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

the class AuthnRequestNameIdFormatTest method testRedirectLoginNameIdPolicyEmail.

@Test
public void testRedirectLoginNameIdPolicyEmail() throws Exception {
    NameIDPolicyType nameIdPolicy = new NameIDPolicyType();
    nameIdPolicy.setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_EMAIL.getUri());
    testLoginWithNameIdPolicy(Binding.REDIRECT, Binding.REDIRECT, nameIdPolicy, is("bburke@redhat.com"));
}
Also used : NameIDPolicyType(org.keycloak.dom.saml.v2.protocol.NameIDPolicyType) Test(org.junit.Test)

Example 8 with NameIDPolicyType

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

the class AuthnRequestNameIdFormatTest method testRedirectLoginNameIdPolicyUnspecified.

@Test
public void testRedirectLoginNameIdPolicyUnspecified() throws Exception {
    NameIDPolicyType nameIdPolicy = new NameIDPolicyType();
    nameIdPolicy.setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_UNSPECIFIED.getUri());
    testLoginWithNameIdPolicy(Binding.REDIRECT, Binding.REDIRECT, nameIdPolicy, is("bburke"));
}
Also used : NameIDPolicyType(org.keycloak.dom.saml.v2.protocol.NameIDPolicyType) Test(org.junit.Test)

Example 9 with NameIDPolicyType

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

the class AuthnRequestNameIdFormatTest method testPostLoginNameIdPolicyPersistent.

@Test
public void testPostLoginNameIdPolicyPersistent() throws Exception {
    NameIDPolicyType nameIdPolicy = new NameIDPolicyType();
    nameIdPolicy.setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.getUri());
    testLoginWithNameIdPolicy(Binding.POST, Binding.POST, nameIdPolicy, startsWith("G-"));
}
Also used : NameIDPolicyType(org.keycloak.dom.saml.v2.protocol.NameIDPolicyType) Test(org.junit.Test)

Example 10 with NameIDPolicyType

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

the class AuthnRequestNameIdFormatTest method testRedirectLoginNameIdPolicyPersistent.

@Test
public void testRedirectLoginNameIdPolicyPersistent() throws Exception {
    NameIDPolicyType nameIdPolicy = new NameIDPolicyType();
    nameIdPolicy.setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.getUri());
    testLoginWithNameIdPolicy(Binding.REDIRECT, Binding.REDIRECT, nameIdPolicy, startsWith("G-"));
}
Also used : NameIDPolicyType(org.keycloak.dom.saml.v2.protocol.NameIDPolicyType) Test(org.junit.Test)

Aggregations

NameIDPolicyType (org.keycloak.dom.saml.v2.protocol.NameIDPolicyType)11 Test (org.junit.Test)8 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)4 URI (java.net.URI)2 List (java.util.List)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 QName (javax.xml.namespace.QName)2 Matchers (org.hamcrest.Matchers)2 ClientsResource (org.keycloak.admin.client.resource.ClientsResource)2 SubjectType (org.keycloak.dom.saml.v2.assertion.SubjectType)2 AuthnRequestType (org.keycloak.dom.saml.v2.protocol.AuthnRequestType)2 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)2 IOException (java.io.IOException)1 KeyPair (java.security.KeyPair)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Status (javax.ws.rs.core.Response.Status)1 Header (org.apache.http.Header)1 HttpHeaders (org.apache.http.HttpHeaders)1