Caches the id-to-user mapping for the evaluation in the current session (#31794)
Closes #31519 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
parent
5284641b9d
commit
aa91f60278
1 changed files with 23 additions and 9 deletions
|
@ -168,20 +168,34 @@ public class DefaultEvaluation implements Evaluation {
|
||||||
return user.isMemberOf(group);
|
return user.isMemberOf(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final String USER_CACHE_SESSION_ATTRIBUTE = DefaultEvaluation.class.getName() + ".userCache";
|
||||||
private UserModel getUser(String id, KeycloakSession session) {
|
private UserModel getUser(String id, KeycloakSession session) {
|
||||||
RealmModel realm = session.getContext().getRealm();
|
@SuppressWarnings("unchecked") HashMap<String, UserModel> cache = (HashMap<String, UserModel>) session.getAttribute(USER_CACHE_SESSION_ATTRIBUTE);
|
||||||
UserModel user = session.users().getUserById(realm, id);
|
if (cache == null) {
|
||||||
|
cache = new HashMap<>();
|
||||||
|
session.setAttribute(USER_CACHE_SESSION_ATTRIBUTE, cache);
|
||||||
|
}
|
||||||
|
UserModel user = cache.get(id);
|
||||||
|
|
||||||
if (Objects.isNull(user)) {
|
if (Objects.isNull(user)) {
|
||||||
user = session.users().getUserByUsername(realm ,id);
|
if (cache.containsKey(id)) {
|
||||||
}
|
return null;
|
||||||
if (Objects.isNull(user)) {
|
}
|
||||||
user = session.users().getUserByEmail(realm, id);
|
RealmModel realm = session.getContext().getRealm();
|
||||||
}
|
user = session.users().getUserById(realm, id);
|
||||||
if (Objects.isNull(user)) {
|
if (Objects.isNull(user)) {
|
||||||
user = session.users().getServiceAccount(realm.getClientById(id));
|
user = session.users().getUserByUsername(realm, id);
|
||||||
|
}
|
||||||
|
if (Objects.isNull(user)) {
|
||||||
|
user = session.users().getUserByEmail(realm, id);
|
||||||
|
}
|
||||||
|
if (Objects.isNull(user)) {
|
||||||
|
user = session.users().getServiceAccount(realm.getClientById(id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cache.put(id, user);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue