use of org.keycloak.models.cache.UserCache in project keycloak by keycloak.
the class UserCredentialStoreManager method removeStoredCredential.
@Override
public boolean removeStoredCredential(RealmModel realm, UserModel user, String id) {
throwExceptionIfInvalidUser(user);
boolean removalResult = getStoreForUser(user).removeStoredCredential(realm, user, id);
UserCache userCache = session.userCache();
if (userCache != null) {
userCache.evict(realm, user);
}
return removalResult;
}
use of org.keycloak.models.cache.UserCache in project keycloak by keycloak.
the class UserCredentialStoreManager method updateCredentialLabel.
@Override
public void updateCredentialLabel(RealmModel realm, UserModel user, String credentialId, String userLabel) {
throwExceptionIfInvalidUser(user);
CredentialModel credential = getStoredCredentialById(realm, user, credentialId);
credential.setUserLabel(userLabel);
getStoreForUser(user).updateCredential(realm, user, credential);
UserCache userCache = session.userCache();
if (userCache != null) {
userCache.evict(realm, user);
}
}
use of org.keycloak.models.cache.UserCache in project keycloak by keycloak.
the class UserStorageManager method deleteInvalidUser.
protected void deleteInvalidUser(final RealmModel realm, final UserModel user) {
String userId = user.getId();
String userName = user.getUsername();
UserCache userCache = session.userCache();
if (userCache != null) {
userCache.evict(realm, user);
}
// This needs to be running in separate transaction because removing the user may end up with throwing
// PessimisticLockException which also rollbacks Jpa transaction, hence when it is running in current transaction
// it will become not usable for all consequent jpa calls. It will end up with Transaction is in rolled back
// state error
runJobInTransaction(session.getKeycloakSessionFactory(), session -> {
RealmModel realmModel = session.realms().getRealm(realm.getId());
if (realmModel == null)
return;
UserModel deletedUser = session.userLocalStorage().getUserById(realmModel, userId);
if (deletedUser != null) {
try {
new UserManager(session).removeUser(realmModel, deletedUser, session.userLocalStorage());
logger.debugf("Removed invalid user '%s'", userName);
} catch (ModelException ex) {
// Ignore exception, possible cause may be concurrent deleteInvalidUser calls which means
// ModelException exception may be ignored because users will be removed with next call or is
// already removed
logger.debugf(ex, "ModelException thrown during deleteInvalidUser with username '%s'", userName);
}
}
});
}
use of org.keycloak.models.cache.UserCache in project keycloak by keycloak.
the class MigrateTo1_4_0 method migrateUsers.
private void migrateUsers(KeycloakSession session, RealmModel realm) {
session.userLocalStorage().getUsersStream(realm, false).forEach(user -> {
String email = KeycloakModelUtils.toLowerCaseSafe(user.getEmail());
if (email != null && !email.equals(user.getEmail())) {
user.setEmail(email);
UserCache userCache = session.userCache();
if (userCache != null) {
userCache.evict(realm, user);
}
}
});
}
Aggregations