Java Code Examples for org.keycloak.models.RealmModel#getFlowByAlias()
The following examples show how to use
org.keycloak.models.RealmModel#getFlowByAlias() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MigrateTo1_5_0.java From keycloak with Apache License 2.0 | 6 votes |
protected void migrateRealm(RealmModel realm) { DefaultAuthenticationFlows.migrateFlows(realm); // add reset credentials flo 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); } for (ClientModel client : realm.getClients()) { client.setClientAuthenticatorType(KeycloakModelUtils.getDefaultClientAuthenticatorType()); } }
Example 2
Source File: MigrateTo1_7_0.java From keycloak with Apache License 2.0 | 6 votes |
protected void migrateRealm(KeycloakSession session, RealmModel realm) { // Set default accessToken timeout for implicit flow realm.setAccessTokenLifespanForImplicitFlow(Constants.DEFAULT_ACCESS_TOKEN_LIFESPAN_FOR_IMPLICIT_FLOW_TIMEOUT); // Add 'admin-cli' builtin client MigrationProvider migrationProvider = session.getProvider(MigrationProvider.class); migrationProvider.setupAdminCli(realm); // add firstBrokerLogin flow and set it to all identityProviders DefaultAuthenticationFlows.migrateFlows(realm); AuthenticationFlowModel firstBrokerLoginFlow = realm.getFlowByAlias(DefaultAuthenticationFlows.FIRST_BROKER_LOGIN_FLOW); List<IdentityProviderModel> identityProviders = realm.getIdentityProviders(); for (IdentityProviderModel identityProvider : identityProviders) { if (identityProvider.getFirstBrokerLoginFlowId() == null) { identityProvider.setFirstBrokerLoginFlowId(firstBrokerLoginFlow.getId()); realm.updateIdentityProvider(identityProvider); } } }
Example 3
Source File: RepresentationToModel.java From keycloak with Apache License 2.0 | 6 votes |
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.isAutheticatorFlow()); 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; }
Example 4
Source File: DefaultAuthenticationFlows.java From keycloak with Apache License 2.0 | 5 votes |
public static void addFlows(RealmModel realm) { if (realm.getFlowByAlias(BROWSER_FLOW) == null) browserFlow(realm); if (realm.getFlowByAlias(DIRECT_GRANT_FLOW) == null) directGrantFlow(realm, false); if (realm.getFlowByAlias(REGISTRATION_FLOW) == null) registrationFlow(realm); if (realm.getFlowByAlias(RESET_CREDENTIALS_FLOW) == null) resetCredentialsFlow(realm); if (realm.getFlowByAlias(CLIENT_AUTHENTICATION_FLOW) == null) clientAuthFlow(realm); if (realm.getFlowByAlias(FIRST_BROKER_LOGIN_FLOW) == null) firstBrokerLoginFlow(realm, false); if (realm.getFlowByAlias(SAML_ECP_FLOW) == null) samlEcpProfile(realm); if (realm.getFlowByAlias(DOCKER_AUTH) == null) dockerAuthenticationFlow(realm); if (realm.getFlowByAlias(HTTP_CHALLENGE_FLOW) == null) httpChallengeFlow(realm); }
Example 5
Source File: DefaultAuthenticationFlows.java From keycloak with Apache License 2.0 | 5 votes |
public static void migrateFlows(RealmModel realm) { if (realm.getFlowByAlias(BROWSER_FLOW) == null) browserFlow(realm, true); if (realm.getFlowByAlias(DIRECT_GRANT_FLOW) == null) directGrantFlow(realm, true); if (realm.getFlowByAlias(REGISTRATION_FLOW) == null) registrationFlow(realm); if (realm.getFlowByAlias(RESET_CREDENTIALS_FLOW) == null) resetCredentialsFlow(realm); if (realm.getFlowByAlias(CLIENT_AUTHENTICATION_FLOW) == null) clientAuthFlow(realm); if (realm.getFlowByAlias(FIRST_BROKER_LOGIN_FLOW) == null) firstBrokerLoginFlow(realm, true); if (realm.getFlowByAlias(SAML_ECP_FLOW) == null) samlEcpProfile(realm); if (realm.getFlowByAlias(DOCKER_AUTH) == null) dockerAuthenticationFlow(realm); if (realm.getFlowByAlias(HTTP_CHALLENGE_FLOW) == null) httpChallengeFlow(realm); }
Example 6
Source File: RepresentationToModel.java From keycloak with Apache License 2.0 | 4 votes |
public static IdentityProviderModel toModel(RealmModel realm, IdentityProviderRepresentation representation, KeycloakSession session) { IdentityProviderFactory providerFactory = (IdentityProviderFactory) session.getKeycloakSessionFactory().getProviderFactory( IdentityProvider.class, representation.getProviderId()); if (providerFactory == null) { providerFactory = (IdentityProviderFactory) session.getKeycloakSessionFactory().getProviderFactory( SocialIdentityProvider.class, representation.getProviderId()); } if (providerFactory == null) { throw new IllegalArgumentException("Invalid identity provider id [" + representation.getProviderId() + "]"); } IdentityProviderModel identityProviderModel = providerFactory.createConfig(); identityProviderModel.setInternalId(representation.getInternalId()); identityProviderModel.setAlias(representation.getAlias()); identityProviderModel.setDisplayName(representation.getDisplayName()); identityProviderModel.setProviderId(representation.getProviderId()); identityProviderModel.setEnabled(representation.isEnabled()); identityProviderModel.setLinkOnly(representation.isLinkOnly()); identityProviderModel.setTrustEmail(representation.isTrustEmail()); identityProviderModel.setAuthenticateByDefault(representation.isAuthenticateByDefault()); identityProviderModel.setStoreToken(representation.isStoreToken()); identityProviderModel.setAddReadTokenRoleOnCreate(representation.isAddReadTokenRoleOnCreate()); identityProviderModel.setConfig(removeEmptyString(representation.getConfig())); String flowAlias = representation.getFirstBrokerLoginFlowAlias(); if (flowAlias == null) { flowAlias = DefaultAuthenticationFlows.FIRST_BROKER_LOGIN_FLOW; } AuthenticationFlowModel flowModel = realm.getFlowByAlias(flowAlias); if (flowModel == null) { throw new ModelException("No available authentication flow with alias: " + flowAlias); } identityProviderModel.setFirstBrokerLoginFlowId(flowModel.getId()); flowAlias = representation.getPostBrokerLoginFlowAlias(); if (flowAlias == null || flowAlias.trim().length() == 0) { identityProviderModel.setPostBrokerLoginFlowId(null); } else { flowModel = realm.getFlowByAlias(flowAlias); if (flowModel == null) { throw new ModelException("No available authentication flow with alias: " + flowAlias); } identityProviderModel.setPostBrokerLoginFlowId(flowModel.getId()); } identityProviderModel.validate(realm); return identityProviderModel; }