@Override public GroupModel getGroupById(String id) { return model.getGroupById(id, this); }
@Override public GroupModel getGroupById(String id) { return session.realms().getGroupById(id, this); }
@Override public List<GroupModel> getDefaultGroups() { List<String> entities = realm.getDefaultGroups(); if (entities == null || entities.isEmpty()) return Collections.EMPTY_LIST; List<GroupModel> defaultGroups = new LinkedList<>(); for (String id : entities) { defaultGroups.add(session.realms().getGroupById(id, this)); } return Collections.unmodifiableList(defaultGroups); }
@Override public List<GroupModel> getDefaultGroups() { Collection<GroupEntity> entities = realm.getDefaultGroups(); if (entities == null || entities.isEmpty()) return Collections.EMPTY_LIST; List<GroupModel> defaultGroups = new LinkedList<>(); for (GroupEntity entity : entities) { defaultGroups.add(session.realms().getGroupById(entity.getId(), this)); } return Collections.unmodifiableList(defaultGroups); }
protected boolean isUpdated() { if (updated != null) return true; if (!invalidated) return false; updated = cacheSession.getRealmDelegate().getGroupById(cached.getId(), realm); if (updated == null) throw new IllegalStateException("Not found in database"); return true; }
@Override public List<GroupModel> getGroups(RealmModel realm) { RealmEntity ref = em.getReference(RealmEntity.class, realm.getId()); return ref.getGroups().stream() .map(g -> session.realms().getGroupById(g.getId(), realm)) .sorted(Comparator.comparing(GroupModel::getName)) .collect(Collectors.collectingAndThen( Collectors.toList(), Collections::unmodifiableList)); }
@Override public List<GroupModel> getTopLevelGroups(RealmModel realm) { RealmEntity ref = em.getReference(RealmEntity.class, realm.getId()); return ref.getGroups().stream() .filter(g -> g.getParent() == null) .map(g -> session.realms().getGroupById(g.getId(), realm)) .sorted(Comparator.comparing(GroupModel::getName)) .collect(Collectors.collectingAndThen( Collectors.toList(), Collections::unmodifiableList)); }
private GroupModel getGroupModel() { return cacheSession.getRealmDelegate().getGroupById(cached.getId(), realm); } }
@Override public List<GroupModel> searchForGroupByName(RealmModel realm, String search, Integer first, Integer max) { TypedQuery<String> query = em.createNamedQuery("getGroupIdsByNameContaining", String.class) .setParameter("realm", realm.getId()) .setParameter("search", search); if(Objects.nonNull(first) && Objects.nonNull(max)) { query= query.setFirstResult(first).setMaxResults(max); } List<String> groups = query.getResultList(); if (Objects.isNull(groups)) return Collections.EMPTY_LIST; List<GroupModel> list = new ArrayList<>(); for (String id : groups) { GroupModel groupById = session.realms().getGroupById(id, realm); while(Objects.nonNull(groupById.getParentId())) { groupById = session.realms().getGroupById(groupById.getParentId(), realm); } if(!list.contains(groupById)) { list.add(groupById); } } list.sort(Comparator.comparing(GroupModel::getName)); return Collections.unmodifiableList(list); }
@Override public Set<GroupModel> getGroups(RealmModel realm, String userId) { FederatedUser userEntity = getUserById(userId); if (userEntity == null || userEntity.getGroupIds() == null || userEntity.getGroupIds().isEmpty()) return Collections.EMPTY_SET; Set<GroupModel> groups = new HashSet<>(); for (String groupId : userEntity.getGroupIds()) { GroupModel group = session.realms().getGroupById(groupId, realm); if (group != null) groups.add(group); } return groups; }
protected void getDelegateForUpdate() { if (updated == null) { cacheSession.registerGroupInvalidation(getId()); updated = cacheSession.getDelegate().getGroupById(getId(), realm); if (updated == null) throw new IllegalStateException("Not found in database"); } }
@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 GroupModel getGroupById(String id, RealmModel realm) { CachedGroup cached = cache.get(id, CachedGroup.class); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached == null) { Long loaded = cache.getCurrentRevision(id); GroupModel model = getRealmDelegate().getGroupById(id, realm); if (model == null) return null; if (invalidations.contains(id)) return model; cached = new CachedGroup(loaded, realm, model); cache.addRevisioned(cached, startupRevision); } else if (invalidations.contains(id)) { return getRealmDelegate().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 Set<GroupModel> getGroups() { if (updated != null) return updated.getGroups(); Set<GroupModel> groups = new LinkedHashSet<>(); for (String id : cached.getGroups(modelSupplier)) { GroupModel groupModel = keycloakSession.realms().getGroupById(id, realm); if (groupModel == null) { // chance that role was removed, so just delete to persistence and get user invalidated getDelegateForUpdate(); return updated.getGroups(); } groups.add(groupModel); } return groups; }
@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 Set<GroupModel> getGroups() { if (updated != null) return updated.getGroups(); Set<GroupModel> groups = new HashSet<GroupModel>(); for (String id : cached.getGroups()) { GroupModel groupModel = keycloakSession.realms().getGroupById(id, realm); if (groupModel == null) { // chance that role was removed, so just delete to persistence and get user invalidated getDelegateForUpdate(); return updated.getGroups(); } groups.add(groupModel); } return groups; }
@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<GroupModel> getSubGroups() { if (isUpdated()) return updated.getSubGroups(); Set<GroupModel> subGroups = new HashSet<>(); for (String id : cached.getSubGroups(modelSupplier)) { 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 (isUpdated()) return updated.getParent(); if (cached.getParentId() == null) return null; return keycloakSession.realms().getGroupById(cached.getParentId(), realm); }
GroupModel group = session.realms().getGroupById(id, realm); if (group == null) { invalidations.add(cacheKey);