Search in sources :

Example 26 with AuthenticatorConfigModel

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

the class RepresentationToModel method toModel.

private static AuthenticationExecutionModel toModel(RealmModel realm, AuthenticationFlowModel parentFlow, AuthenticationExecutionExportRepresentation rep) {
    AuthenticationExecutionModel model = new AuthenticationExecutionModel();
    if (rep.getAuthenticatorConfig() != null) {
        AuthenticatorConfigModel config = realm.getAuthenticatorConfigByAlias(rep.getAuthenticatorConfig());
        model.setAuthenticatorConfig(config.getId());
    }
    model.setAuthenticator(rep.getAuthenticator());
    model.setAuthenticatorFlow(rep.isAuthenticatorFlow());
    if (rep.getFlowAlias() != null) {
        AuthenticationFlowModel flow = realm.getFlowByAlias(rep.getFlowAlias());
        model.setFlowId(flow.getId());
    }
    model.setPriority(rep.getPriority());
    try {
        model.setRequirement(AuthenticationExecutionModel.Requirement.valueOf(rep.getRequirement()));
        model.setParentFlow(parentFlow.getId());
    } catch (IllegalArgumentException iae) {
        // retro-compatible for previous OPTIONAL being changed to CONDITIONAL
        if ("OPTIONAL".equals(rep.getRequirement())) {
            MigrateTo8_0_0.migrateOptionalAuthenticationExecution(realm, parentFlow, model, false);
        }
    }
    return model;
}
Also used : AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel) AuthenticatorConfigModel(org.keycloak.models.AuthenticatorConfigModel)

Example 27 with AuthenticatorConfigModel

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

the class RepresentationToModel method toModel.

public static AuthenticationExecutionModel toModel(RealmModel realm, AuthenticationExecutionRepresentation rep) {
    AuthenticationExecutionModel model = new AuthenticationExecutionModel();
    model.setId(rep.getId());
    model.setFlowId(rep.getFlowId());
    model.setAuthenticator(rep.getAuthenticator());
    model.setPriority(rep.getPriority());
    model.setParentFlow(rep.getParentFlow());
    model.setAuthenticatorFlow(rep.isAuthenticatorFlow());
    model.setRequirement(AuthenticationExecutionModel.Requirement.valueOf(rep.getRequirement()));
    if (rep.getAuthenticatorConfig() != null) {
        AuthenticatorConfigModel cfg = realm.getAuthenticatorConfigByAlias(rep.getAuthenticatorConfig());
        model.setAuthenticatorConfig(cfg.getId());
    }
    return model;
}
Also used : AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticatorConfigModel(org.keycloak.models.AuthenticatorConfigModel)

Example 28 with AuthenticatorConfigModel

use of org.keycloak.models.AuthenticatorConfigModel 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

AuthenticatorConfigModel (org.keycloak.models.AuthenticatorConfigModel)28 AuthenticationExecutionModel (org.keycloak.models.AuthenticationExecutionModel)13 AuthenticationFlowModel (org.keycloak.models.AuthenticationFlowModel)9 RealmModel (org.keycloak.models.RealmModel)9 HashMap (java.util.HashMap)6 NotFoundException (javax.ws.rs.NotFoundException)5 Path (javax.ws.rs.Path)5 NoCache (org.jboss.resteasy.annotations.cache.NoCache)5 List (java.util.List)4 Consumes (javax.ws.rs.Consumes)4 Response (javax.ws.rs.core.Response)4 KeycloakSession (org.keycloak.models.KeycloakSession)4 UserModel (org.keycloak.models.UserModel)4 Map (java.util.Map)3 Optional (java.util.Optional)3 POST (javax.ws.rs.POST)3 Before (org.junit.Before)3 Authenticator (org.keycloak.authentication.Authenticator)3 Collections (java.util.Collections)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2