Search in sources :

Example 1 with RequiredActionProviderModel

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

the class JpaUserProvider method addUser.

@Override
public UserModel addUser(RealmModel realm, String id, String username, boolean addDefaultRoles, boolean addDefaultRequiredActions) {
    if (id == null) {
        id = KeycloakModelUtils.generateId();
    }
    UserEntity entity = new UserEntity();
    entity.setId(id);
    entity.setCreatedTimestamp(System.currentTimeMillis());
    entity.setUsername(username.toLowerCase());
    entity.setRealmId(realm.getId());
    em.persist(entity);
    em.flush();
    UserAdapter userModel = new UserAdapter(session, realm, em, entity);
    if (addDefaultRoles) {
        userModel.grantRole(realm.getDefaultRole());
        // No need to check if user has group as it's new user
        realm.getDefaultGroupsStream().forEach(userModel::joinGroupImpl);
    }
    if (addDefaultRequiredActions) {
        realm.getRequiredActionProvidersStream().filter(RequiredActionProviderModel::isEnabled).filter(RequiredActionProviderModel::isDefaultAction).map(RequiredActionProviderModel::getAlias).forEach(userModel::addRequiredAction);
    }
    return userModel;
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel) UserEntity(org.keycloak.models.jpa.entities.UserEntity)

Example 2 with RequiredActionProviderModel

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

the class DefaultRequiredActions method addDeleteAccountAction.

public static void addDeleteAccountAction(RealmModel realm) {
    if (realm.getRequiredActionProviderByAlias("delete_account") == null) {
        RequiredActionProviderModel deleteAccount = new RequiredActionProviderModel();
        deleteAccount.setEnabled(false);
        deleteAccount.setAlias("delete_account");
        deleteAccount.setName("Delete Account");
        deleteAccount.setProviderId("delete_account");
        deleteAccount.setDefaultAction(false);
        deleteAccount.setPriority(60);
        realm.addRequiredActionProvider(deleteAccount);
    }
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel)

Example 3 with RequiredActionProviderModel

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

the class MapRequiredActionProviderEntity method toModel.

static RequiredActionProviderModel toModel(MapRequiredActionProviderEntity entity) {
    if (entity == null)
        return null;
    RequiredActionProviderModel model = new RequiredActionProviderModel();
    model.setId(entity.getId());
    model.setAlias(entity.getAlias());
    model.setName(entity.getName());
    model.setProviderId(entity.getProviderId());
    Integer priority = entity.getPriority();
    model.setPriority(priority == null ? 0 : priority);
    Boolean enabled = entity.isEnabled();
    model.setEnabled(enabled == null ? false : enabled);
    Boolean defaultAction = entity.isDefaultAction();
    model.setDefaultAction(defaultAction == null ? false : defaultAction);
    model.setConfig(entity.getConfig());
    return model;
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel)

Example 4 with RequiredActionProviderModel

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

the class MigrateTo12_0_0 method addDeleteAccountAction.

private static void addDeleteAccountAction(RealmModel realm) {
    RequiredActionProviderModel deleteAccount = new RequiredActionProviderModel();
    deleteAccount.setEnabled(false);
    deleteAccount.setAlias("delete_account");
    deleteAccount.setName("Delete Account");
    deleteAccount.setProviderId("delete_account");
    deleteAccount.setDefaultAction(false);
    deleteAccount.setPriority(60);
    realm.addRequiredActionProvider(deleteAccount);
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel)

Example 5 with RequiredActionProviderModel

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

the class MigrateTo4_2_0 method migrateRealm.

protected void migrateRealm(RealmModel realm) {
    // Set default priority of required actions in alphabetical order
    AtomicInteger priority = new AtomicInteger(10);
    realm.getRequiredActionProvidersStream().sorted(comparing(RequiredActionProviderModel::getName)).forEachOrdered(model -> {
        LOG.debugf("Setting priority '%d' for required action '%s' in realm '%s'", priority.get(), model.getAlias(), realm.getName());
        model.setPriority(priority.get());
        priority.addAndGet(10);
        // Save
        realm.updateRequiredActionProvider(model);
    });
}
Also used : RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

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