@Override public Map<String, List<String>> getAttributes() { return cached.getAttributes(); }
@Override public int hashCode() { return cached.getId().hashCode(); }
@Override public String getName() { if (updated != null) return updated.getName(); return cached.getName(); }
@Override public GroupModel getGroupById(String id, RealmModel realm) { if (!cache.isEnabled()) return getDelegate().getGroupById(id, realm); CachedGroup cached = cache.getGroup(id); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached == null) { GroupModel model = getDelegate().getGroupById(id, realm); if (model == null) return null; if (groupInvalidations.contains(id)) return model; cached = new CachedGroup(realm, model); cache.addCachedGroup(cached); } else if (groupInvalidations.contains(id)) { return getDelegate().getGroupById(id, realm); } else if (managedGroups.containsKey(id)) { return managedGroups.get(id); } GroupAdapter adapter = new GroupAdapter(cached, this, session, realm); managedGroups.put(id, adapter); return adapter; }
@Override public String getParentId() { if (updated != null) return updated.getParentId(); return cached.getParentId(); }
@Override public boolean hasRole(RoleModel role) { if (updated != null) return updated.hasRole(role); if (cached.getRoleMappings().contains(role.getId())) return true; Set<RoleModel> mappings = getRoleMappings(); for (RoleModel mapping: mappings) { if (mapping.hasRole(role)) return true; } return false; }
@Override public Set<GroupModel> getSubGroups() { if (updated != null) return updated.getSubGroups(); Set<GroupModel> subGroups = new HashSet<>(); for (String id : cached.getSubGroups()) { GroupModel subGroup = keycloakSession.realms().getGroupById(id, realm); if (subGroup == null) { // chance that role was removed, so just delegate to persistence and get user invalidated getDelegateForUpdate(); return updated.getSubGroups(); } subGroups.add(subGroup); } return subGroups; }
@Override public GroupModel getParent() { if (updated != null) return updated.getParent(); if (cached.getParentId() == null) return null; return keycloakSession.realms().getGroupById(cached.getParentId(), realm); }
@Override public Set<RoleModel> getRoleMappings() { if (updated != null) return updated.getRoleMappings(); Set<RoleModel> roles = new HashSet<RoleModel>(); for (String id : cached.getRoleMappings()) { RoleModel roleById = keycloakSession.realms().getRoleById(id, realm); if (roleById == null) { // chance that role was removed, so just delegate to persistence and get user invalidated getDelegateForUpdate(); return updated.getRoleMappings(); } roles.add(roleById); } return roles; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof GroupModel)) return false; GroupModel that = (GroupModel) o; if (!cached.getId().equals(that.getId())) return false; return true; }
@Override public List<String> getAttribute(String name) { List<String> values = cached.getAttributes().get(name); if (values == null) return null; return values; }
@Override public String getFirstAttribute(String name) { if (updated != null) return updated.getFirstAttribute(name); return cached.getAttributes().getFirst(name); }
@Override public String getId() { if (updated != null) return updated.getId(); return cached.getId(); }