Search in sources :

Example 1 with USER_EMAIL

use of org.keycloak.testsuite.broker.BrokerTestConstants.USER_EMAIL in project keycloak by keycloak.

the class KcSamlBrokerFrontendUrlTest method testFrontendUrlInDestinationExpected.

@Test
public void testFrontendUrlInDestinationExpected() throws URISyntaxException {
    SAMLDocumentHolder samlResponse = clientBuilderTrustingAllCertificates().idpInitiatedLogin(new URI(proxy.getUrl() + "/realms/" + bc.consumerRealmName() + "/protocol/saml"), "sales-post").build().login().idp(IDP_SAML_ALIAS).build().processSamlResponse(// AuthnRequest to producer IdP
    SamlClient.Binding.POST).targetAttributeSamlRequest().build().login().user(USER_LOGIN, USER_PASSWORD).build().processSamlResponse(SamlClient.Binding.POST).transformObject(saml2Object -> {
        assertThat(saml2Object, Matchers.isSamlResponse(JBossSAMLURIConstants.STATUS_SUCCESS));
        ResponseType response = (ResponseType) saml2Object;
        assertThat(response.getDestination(), startsWith(proxy.getUrl()));
        return saml2Object;
    }).build().updateProfile().username(USER_LOGIN).email(USER_EMAIL).firstName("Firstname").lastName("Lastname").build().followOneRedirect().getSamlResponse(SamlClient.Binding.POST);
    assertThat(samlResponse.getSamlObject(), Matchers.isSamlResponse(JBossSAMLURIConstants.STATUS_SUCCESS));
}
Also used : ReverseProxy(org.keycloak.testsuite.util.ReverseProxy) USER_PASSWORD(org.keycloak.testsuite.broker.BrokerTestConstants.USER_PASSWORD) IDP_SAML_ALIAS(org.keycloak.testsuite.broker.BrokerTestConstants.IDP_SAML_ALIAS) URISyntaxException(java.net.URISyntaxException) AssertEvents(org.keycloak.testsuite.AssertEvents) HashMap(java.util.HashMap) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) KeyStoreException(java.security.KeyStoreException) USER_EMAIL(org.keycloak.testsuite.broker.BrokerTestConstants.USER_EMAIL) ArrayList(java.util.ArrayList) BrokerTestTools.getConsumerRoot(org.keycloak.testsuite.broker.BrokerTestTools.getConsumerRoot) Map(java.util.Map) SamlClient(org.keycloak.testsuite.util.SamlClient) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) Errors(org.keycloak.events.Errors) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers(org.keycloak.testsuite.util.Matchers) JBossSAMLURIConstants(org.keycloak.saml.common.constants.JBossSAMLURIConstants) Test(org.junit.Test) EventType(org.keycloak.events.EventType) KeyManagementException(java.security.KeyManagementException) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) URLEncoder(java.net.URLEncoder) List(java.util.List) Rule(org.junit.Rule) USER_LOGIN(org.keycloak.testsuite.broker.BrokerTestConstants.USER_LOGIN) Ignore(org.junit.Ignore) Response(javax.ws.rs.core.Response) REALM_CONS_NAME(org.keycloak.testsuite.broker.BrokerTestConstants.REALM_CONS_NAME) BrokerTestTools.waitForPage(org.keycloak.testsuite.broker.BrokerTestTools.waitForPage) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TrustAllStrategy(org.apache.http.conn.ssl.TrustAllStrategy) SamlClientBuilder(org.keycloak.testsuite.util.SamlClientBuilder) SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) URI(java.net.URI) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) Test(org.junit.Test)

Example 2 with USER_EMAIL

use of org.keycloak.testsuite.broker.BrokerTestConstants.USER_EMAIL in project keycloak by keycloak.

the class KcSamlBrokerSessionNotOnOrAfterTest method testConsumerIdpInitiatedLoginContainsSessionNotOnOrAfter.

@Test
public void testConsumerIdpInitiatedLoginContainsSessionNotOnOrAfter() throws Exception {
    SAMLDocumentHolder samlResponse = new SamlClientBuilder().idpInitiatedLogin(getConsumerSamlEndpoint(REALM_CONS_NAME), "sales-post").build().login().idp(IDP_SAML_ALIAS).build().processSamlResponse(// AuthnRequest to producer IdP
    SamlClient.Binding.POST).targetAttributeSamlRequest().build().login().user(USER_LOGIN, USER_PASSWORD).build().processSamlResponse(SamlClient.Binding.POST).build().updateProfile().username(USER_LOGIN).email(USER_EMAIL).firstName("Firstname").lastName("Lastname").build().followOneRedirect().getSamlResponse(SamlClient.Binding.POST);
    assertThat(samlResponse.getSamlObject(), Matchers.isSamlResponse(JBossSAMLURIConstants.STATUS_SUCCESS));
    ResponseType resp = (ResponseType) samlResponse.getSamlObject();
    Set<StatementAbstractType> statements = resp.getAssertions().get(0).getAssertion().getStatements();
    AuthnStatementType authType = statements.stream().filter(statement -> statement instanceof AuthnStatementType).map(s -> (AuthnStatementType) s).findFirst().orElse(null);
    assertThat(authType, notNullValue());
    assertThat(authType.getSessionNotOnOrAfter(), notNullValue());
    assertThat(authType.getSessionNotOnOrAfter(), is(XMLTimeUtil.add(authType.getAuthnInstant(), adminClient.realm(REALM_CONS_NAME).toRepresentation().getSsoSessionMaxLifespan() * 1000)));
}
Also used : AuthnStatementType(org.keycloak.dom.saml.v2.assertion.AuthnStatementType) XMLTimeUtil(org.keycloak.saml.processing.core.saml.v2.util.XMLTimeUtil) USER_PASSWORD(org.keycloak.testsuite.broker.BrokerTestConstants.USER_PASSWORD) IDP_SAML_ALIAS(org.keycloak.testsuite.broker.BrokerTestConstants.IDP_SAML_ALIAS) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers(org.keycloak.testsuite.util.Matchers) JBossSAMLURIConstants(org.keycloak.saml.common.constants.JBossSAMLURIConstants) Set(java.util.Set) Test(org.junit.Test) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) USER_EMAIL(org.keycloak.testsuite.broker.BrokerTestConstants.USER_EMAIL) Assert.assertThat(org.junit.Assert.assertThat) USER_LOGIN(org.keycloak.testsuite.broker.BrokerTestConstants.USER_LOGIN) AuthnStatementType(org.keycloak.dom.saml.v2.assertion.AuthnStatementType) StatementAbstractType(org.keycloak.dom.saml.v2.assertion.StatementAbstractType) REALM_CONS_NAME(org.keycloak.testsuite.broker.BrokerTestConstants.REALM_CONS_NAME) SamlClient(org.keycloak.testsuite.util.SamlClient) Matchers.is(org.hamcrest.Matchers.is) SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) SamlClientBuilder(org.keycloak.testsuite.util.SamlClientBuilder) SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) SamlClientBuilder(org.keycloak.testsuite.util.SamlClientBuilder) StatementAbstractType(org.keycloak.dom.saml.v2.assertion.StatementAbstractType) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)2 JBossSAMLURIConstants (org.keycloak.saml.common.constants.JBossSAMLURIConstants)2 SAMLDocumentHolder (org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder)2 IDP_SAML_ALIAS (org.keycloak.testsuite.broker.BrokerTestConstants.IDP_SAML_ALIAS)2 REALM_CONS_NAME (org.keycloak.testsuite.broker.BrokerTestConstants.REALM_CONS_NAME)2 USER_EMAIL (org.keycloak.testsuite.broker.BrokerTestConstants.USER_EMAIL)2 USER_LOGIN (org.keycloak.testsuite.broker.BrokerTestConstants.USER_LOGIN)2 USER_PASSWORD (org.keycloak.testsuite.broker.BrokerTestConstants.USER_PASSWORD)2 Matchers (org.keycloak.testsuite.util.Matchers)2 SamlClient (org.keycloak.testsuite.util.SamlClient)2 SamlClientBuilder (org.keycloak.testsuite.util.SamlClientBuilder)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URLEncoder (java.net.URLEncoder)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1