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;
}
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);
}
}
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;
}
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);
}
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);
});
}
Aggregations