Search in sources :

Example 56 with AuthenticationFlowModel

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

the class MigrateTo1_5_0 method migrateRealm.

protected void migrateRealm(KeycloakSession session, RealmModel realm) {
    // add reset credentials flo
    DefaultAuthenticationFlows.migrateFlows(realm);
    realm.setOTPPolicy(OTPPolicy.DEFAULT_POLICY);
    realm.setBrowserFlow(realm.getFlowByAlias(DefaultAuthenticationFlows.BROWSER_FLOW));
    realm.setRegistrationFlow(realm.getFlowByAlias(DefaultAuthenticationFlows.REGISTRATION_FLOW));
    realm.setDirectGrantFlow(realm.getFlowByAlias(DefaultAuthenticationFlows.DIRECT_GRANT_FLOW));
    AuthenticationFlowModel resetFlow = realm.getFlowByAlias(DefaultAuthenticationFlows.RESET_CREDENTIALS_FLOW);
    if (resetFlow == null) {
        DefaultAuthenticationFlows.resetCredentialsFlow(realm);
    } else {
        realm.setResetCredentialsFlow(resetFlow);
    }
    AuthenticationFlowModel clientAuthFlow = realm.getFlowByAlias(DefaultAuthenticationFlows.CLIENT_AUTHENTICATION_FLOW);
    if (clientAuthFlow == null) {
        DefaultAuthenticationFlows.clientAuthFlow(realm);
    } else {
        realm.setClientAuthenticationFlow(clientAuthFlow);
    }
    realm.getClientsStream().forEach(MigrationUtils::setDefaultClientAuthenticatorType);
}
Also used : AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel)

Example 57 with AuthenticationFlowModel

use of org.keycloak.models.AuthenticationFlowModel 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 58 with AuthenticationFlowModel

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

the class RepresentationToModel method toModel.

public static AuthenticationFlowModel toModel(AuthenticationFlowRepresentation rep) {
    AuthenticationFlowModel model = new AuthenticationFlowModel();
    model.setId(rep.getId());
    model.setBuiltIn(rep.isBuiltIn());
    model.setTopLevel(rep.isTopLevel());
    model.setProviderId(rep.getProviderId());
    model.setAlias(rep.getAlias());
    model.setDescription(rep.getDescription());
    return model;
}
Also used : AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel)

Example 59 with AuthenticationFlowModel

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

the class KeycloakModelUtils method deepFindAuthenticationExecutions.

/**
 * Recursively find all AuthenticationExecutionModel from specified flow or all it's subflows
 *
 * @param realm
 * @param flow
 * @param result input should be empty list. At the end will be all executions added to this list
 */
public static void deepFindAuthenticationExecutions(RealmModel realm, AuthenticationFlowModel flow, List<AuthenticationExecutionModel> result) {
    realm.getAuthenticationExecutionsStream(flow.getId()).forEachOrdered(execution -> {
        if (execution.isAuthenticatorFlow()) {
            AuthenticationFlowModel subFlow = realm.getAuthenticationFlowById(execution.getFlowId());
            deepFindAuthenticationExecutions(realm, subFlow, result);
        } else {
            result.add(execution);
        }
    });
}
Also used : AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel)

Example 60 with AuthenticationFlowModel

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

the class TestingResourceProvider method getClientAuthFlow.

@GET
@Path("/get-client-auth-flow")
@Produces(MediaType.APPLICATION_JSON)
public AuthenticationFlowRepresentation getClientAuthFlow(@QueryParam("realmName") String realmName) {
    RealmModel realm = getRealmByName(realmName);
    AuthenticationFlowModel flow = realm.getClientAuthenticationFlow();
    if (flow == null)
        return null;
    return ModelToRepresentation.toRepresentation(realm, flow);
}
Also used : RealmModel(org.keycloak.models.RealmModel) AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

AuthenticationFlowModel (org.keycloak.models.AuthenticationFlowModel)60 AuthenticationExecutionModel (org.keycloak.models.AuthenticationExecutionModel)32 Path (javax.ws.rs.Path)14 RealmModel (org.keycloak.models.RealmModel)13 NoCache (org.jboss.resteasy.annotations.cache.NoCache)12 NotFoundException (javax.ws.rs.NotFoundException)9 AuthenticatorConfigModel (org.keycloak.models.AuthenticatorConfigModel)8 Consumes (javax.ws.rs.Consumes)7 POST (javax.ws.rs.POST)7 AuthenticationProcessor (org.keycloak.authentication.AuthenticationProcessor)7 BadRequestException (javax.ws.rs.BadRequestException)6 Produces (javax.ws.rs.Produces)6 Before (org.junit.Before)5 ClientModel (org.keycloak.models.ClientModel)5 HashMap (java.util.HashMap)4 GET (javax.ws.rs.GET)4 Response (javax.ws.rs.core.Response)3 IdentityProviderModel (org.keycloak.models.IdentityProviderModel)3 ModelException (org.keycloak.models.ModelException)3 ArrayList (java.util.ArrayList)2