diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java index 7f3ae6a084..c8fee2dbf3 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserAdapter.java @@ -192,8 +192,10 @@ public class UserAdapter implements CachedUserModel { @Override public void removeAttribute(String name) { - getDelegateForUpdate(); - updated.removeAttribute(name); + if (getFirstAttribute(name) != null) { + getDelegateForUpdate(); + updated.removeAttribute(name); + } } @Override @@ -229,8 +231,10 @@ public class UserAdapter implements CachedUserModel { @Override public void removeRequiredAction(RequiredAction action) { - getDelegateForUpdate(); - updated.removeRequiredAction(action); + if (getRequiredActionsStream().anyMatch(s -> Objects.equals(s, action.name()))) { + getDelegateForUpdate(); + updated.removeRequiredAction(action); + } } @Override @@ -241,8 +245,10 @@ public class UserAdapter implements CachedUserModel { @Override public void removeRequiredAction(String action) { - getDelegateForUpdate(); - updated.removeRequiredAction(action); + if (getRequiredActionsStream().anyMatch(s -> Objects.equals(s, action))) { + getDelegateForUpdate(); + updated.removeRequiredAction(action); + } } @Override