Search in sources :

Example 16 with RequiredActionProviderModel

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

the class RepresentationToModel method toModel.

public static RequiredActionProviderModel toModel(RequiredActionProviderRepresentation rep) {
    RequiredActionProviderModel model = new RequiredActionProviderModel();
    model.setConfig(removeEmptyString(rep.getConfig()));
    model.setPriority(rep.getPriority());
    model.setDefaultAction(rep.isDefaultAction());
    model.setEnabled(rep.isEnabled());
    model.setProviderId(rep.getProviderId());
    model.setName(rep.getName());
    model.setAlias(rep.getAlias());
    return model;
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel)

Example 17 with RequiredActionProviderModel

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

the class DefaultRequiredActions method addUpdateLocaleAction.

public static void addUpdateLocaleAction(RealmModel realm) {
    if (realm.getRequiredActionProviderByAlias("update_user_locale") == null) {
        RequiredActionProviderModel updateUserLocale = new RequiredActionProviderModel();
        updateUserLocale.setEnabled(true);
        updateUserLocale.setAlias("update_user_locale");
        updateUserLocale.setName("Update User Locale");
        updateUserLocale.setProviderId("update_user_locale");
        updateUserLocale.setDefaultAction(false);
        updateUserLocale.setPriority(1000);
        realm.addRequiredActionProvider(updateUserLocale);
    }
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel)

Example 18 with RequiredActionProviderModel

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

the class DefaultRequiredActions method addActions.

public static void addActions(RealmModel realm) {
    if (realm.getRequiredActionProviderByAlias(UserModel.RequiredAction.VERIFY_EMAIL.name()) == null) {
        RequiredActionProviderModel verifyEmail = new RequiredActionProviderModel();
        verifyEmail.setEnabled(true);
        verifyEmail.setAlias(UserModel.RequiredAction.VERIFY_EMAIL.name());
        verifyEmail.setName("Verify Email");
        verifyEmail.setProviderId(UserModel.RequiredAction.VERIFY_EMAIL.name());
        verifyEmail.setDefaultAction(false);
        verifyEmail.setPriority(50);
        realm.addRequiredActionProvider(verifyEmail);
    }
    if (realm.getRequiredActionProviderByAlias(UserModel.RequiredAction.UPDATE_PROFILE.name()) == null) {
        RequiredActionProviderModel updateProfile = new RequiredActionProviderModel();
        updateProfile.setEnabled(true);
        updateProfile.setAlias(UserModel.RequiredAction.UPDATE_PROFILE.name());
        updateProfile.setName("Update Profile");
        updateProfile.setProviderId(UserModel.RequiredAction.UPDATE_PROFILE.name());
        updateProfile.setDefaultAction(false);
        updateProfile.setPriority(40);
        realm.addRequiredActionProvider(updateProfile);
    }
    if (realm.getRequiredActionProviderByAlias(UserModel.RequiredAction.CONFIGURE_TOTP.name()) == null) {
        RequiredActionProviderModel totp = new RequiredActionProviderModel();
        totp.setEnabled(true);
        totp.setAlias(UserModel.RequiredAction.CONFIGURE_TOTP.name());
        totp.setName("Configure OTP");
        totp.setProviderId(UserModel.RequiredAction.CONFIGURE_TOTP.name());
        totp.setDefaultAction(false);
        totp.setPriority(10);
        realm.addRequiredActionProvider(totp);
    }
    if (realm.getRequiredActionProviderByAlias(UserModel.RequiredAction.UPDATE_PASSWORD.name()) == null) {
        RequiredActionProviderModel updatePassword = new RequiredActionProviderModel();
        updatePassword.setEnabled(true);
        updatePassword.setAlias(UserModel.RequiredAction.UPDATE_PASSWORD.name());
        updatePassword.setName("Update Password");
        updatePassword.setProviderId(UserModel.RequiredAction.UPDATE_PASSWORD.name());
        updatePassword.setDefaultAction(false);
        updatePassword.setPriority(30);
        realm.addRequiredActionProvider(updatePassword);
    }
    if (realm.getRequiredActionProviderByAlias("terms_and_conditions") == null) {
        RequiredActionProviderModel termsAndConditions = new RequiredActionProviderModel();
        termsAndConditions.setEnabled(false);
        termsAndConditions.setAlias("terms_and_conditions");
        termsAndConditions.setName("Terms and Conditions");
        termsAndConditions.setProviderId("terms_and_conditions");
        termsAndConditions.setDefaultAction(false);
        termsAndConditions.setPriority(20);
        realm.addRequiredActionProvider(termsAndConditions);
    }
    addUpdateLocaleAction(realm);
    addDeleteAccountAction(realm);
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel)

Example 19 with RequiredActionProviderModel

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

the class MapUserProvider method addUser.

@Override
public UserModel addUser(RealmModel realm, String id, String username, boolean addDefaultRoles, boolean addDefaultRequiredActions) {
    LOG.tracef("addUser(%s, %s, %s, %s, %s)%s", realm, id, username, addDefaultRoles, addDefaultRequiredActions, getShortStackTrace());
    DefaultModelCriteria<UserModel> mcb = criteria();
    mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId()).compare(SearchableFields.USERNAME, Operator.EQ, username);
    if (tx.getCount(withCriteria(mcb)) > 0) {
        throw new ModelDuplicateException("User with username '" + username + "' in realm " + realm.getName() + " already exists");
    }
    if (id != null && tx.read(id) != null) {
        throw new ModelDuplicateException("User exists: " + id);
    }
    MapUserEntity entity = new MapUserEntityImpl();
    entity.setId(id);
    entity.setRealmId(realm.getId());
    entity.setEmailConstraint(KeycloakModelUtils.generateId());
    entity.setUsername(username.toLowerCase());
    entity.setCreatedTimestamp(Time.currentTimeMillis());
    entity = tx.create(entity);
    final UserModel userModel = entityToAdapterFunc(realm).apply(entity);
    if (addDefaultRoles) {
        userModel.grantRole(realm.getDefaultRole());
        // No need to check if user has group as it's new user
        realm.getDefaultGroupsStream().forEach(userModel::joinGroup);
    }
    if (addDefaultRequiredActions) {
        realm.getRequiredActionProvidersStream().filter(RequiredActionProviderModel::isEnabled).filter(RequiredActionProviderModel::isDefaultAction).map(RequiredActionProviderModel::getAlias).forEach(userModel::addRequiredAction);
    }
    return userModel;
}
Also used : UserModel(org.keycloak.models.UserModel) RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel) ModelDuplicateException(org.keycloak.models.ModelDuplicateException)

Aggregations

RequiredActionProviderModel (org.keycloak.models.RequiredActionProviderModel)19 Path (javax.ws.rs.Path)7 NotFoundException (javax.ws.rs.NotFoundException)6 NoCache (org.jboss.resteasy.annotations.cache.NoCache)5 POST (javax.ws.rs.POST)4 Consumes (javax.ws.rs.Consumes)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 Produces (javax.ws.rs.Produces)2 UserModel (org.keycloak.models.UserModel)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1