Search in sources :

Example 51 with AuthenticationExecutionModel

use of org.keycloak.models.AuthenticationExecutionModel in project keycloak by keycloak.

the class KcSamlDefaultIdpTest method configureFlow.

private void configureFlow(String defaultIdpValue) {
    String newFlowAlias;
    HashMap<String, String> defaultIdpConfig = new HashMap<String, String>();
    if (defaultIdpValue != null && !defaultIdpValue.isEmpty()) {
        defaultIdpConfig.put(IdentityProviderAuthenticatorFactory.DEFAULT_PROVIDER, defaultIdpValue);
        newFlowAlias = "Browser - Default IdP " + defaultIdpValue;
    } else
        newFlowAlias = "Browser - Default IdP OFF";
    testingClient.server("consumer").run(session -> FlowUtil.inCurrentRealm(session).copyBrowserFlow(newFlowAlias));
    testingClient.server("consumer").run(session -> {
        List<AuthenticationExecutionModel> executions = FlowUtil.inCurrentRealm(session).selectFlow(newFlowAlias).getExecutions();
        int index = IntStream.range(0, executions.size()).filter(t -> IdentityProviderAuthenticatorFactory.PROVIDER_ID.equals(executions.get(t).getAuthenticator())).findFirst().orElse(-1);
        assertTrue("Identity Provider Redirector execution not found", index >= 0);
        FlowUtil.inCurrentRealm(session).selectFlow(newFlowAlias).updateExecution(index, config -> {
            AuthenticatorConfigModel authConfig = new AuthenticatorConfigModel();
            authConfig.setId(UUID.randomUUID().toString());
            authConfig.setAlias("cfg" + authConfig.getId().hashCode());
            authConfig.setConfig(defaultIdpConfig);
            session.getContext().getRealm().addAuthenticatorConfig(authConfig);
            config.setAuthenticatorConfig(authConfig.getId());
        }).defineAsBrowserFlow();
    });
}
Also used : IntStream(java.util.stream.IntStream) IdentityProviderAuthenticatorFactory(org.keycloak.authentication.authenticators.browser.IdentityProviderAuthenticatorFactory) Assert(org.keycloak.testsuite.Assert) RealmResource(org.keycloak.admin.client.resource.RealmResource) Assert.assertNotNull(org.junit.Assert.assertNotNull) By(org.openqa.selenium.By) UIUtils(org.keycloak.testsuite.util.UIUtils) WebElement(org.openqa.selenium.WebElement) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) UUID(java.util.UUID) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) BrokerTestTools.getConsumerRoot(org.keycloak.testsuite.broker.BrokerTestTools.getConsumerRoot) List(java.util.List) AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) BrokerTestTools.waitForPage(org.keycloak.testsuite.broker.BrokerTestTools.waitForPage) AuthenticatorConfigModel(org.keycloak.models.AuthenticatorConfigModel) FlowUtil(org.keycloak.testsuite.util.FlowUtil) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticatorConfigModel(org.keycloak.models.AuthenticatorConfigModel)

Aggregations

AuthenticationExecutionModel (org.keycloak.models.AuthenticationExecutionModel)51 AuthenticationFlowModel (org.keycloak.models.AuthenticationFlowModel)32 AuthenticatorConfigModel (org.keycloak.models.AuthenticatorConfigModel)11 Path (javax.ws.rs.Path)8 NoCache (org.jboss.resteasy.annotations.cache.NoCache)8 HashMap (java.util.HashMap)7 Response (javax.ws.rs.core.Response)7 RealmModel (org.keycloak.models.RealmModel)7 BadRequestException (javax.ws.rs.BadRequestException)6 NotFoundException (javax.ws.rs.NotFoundException)6 POST (javax.ws.rs.POST)6 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)5 Consumes (javax.ws.rs.Consumes)5 Before (org.junit.Before)5 ClientModel (org.keycloak.models.ClientModel)4 List (java.util.List)3 UserModel (org.keycloak.models.UserModel)3 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)2 Logger (org.jboss.logging.Logger)2