@Override public RoleContainerModel getContainer() { if (cached instanceof CachedRealmRole) { return realm; } else { CachedClientRole appRole = (CachedClientRole) cached; return realm.getClientById(appRole.getClientId()); } }
@Override public ClientModel getClient() { return realm.getClientById(entity.getClientId()); }
@Override public RoleContainerModel getContainer() { if (cached instanceof CachedRealmRole) { return realm; } else { CachedClientRole appRole = (CachedClientRole)cached; return realm.getClientById(appRole.getIdClient()); } }
@Override public ClientModel getClient() { return realm.getClientById(entity.getClient()); }
@Override public ClientModel getClientById(String id) { if (updated != null) return updated.getClientById(id); return cacheSession.getClientById(id, this); }
@Override public ClientModel getClient() { return realm.getClientById(entity.getClientId()); }
@Override public ClientModel getClient() { return getRealm().getClientById(entity.getClientUUID()); }
@Override public ClientModel getClientById(String id) { if (isUpdated()) return updated.getClientById(id); return cacheSession.getClientById(id, this); }
@Override public void onExport(Policy policy, PolicyRepresentation representation, AuthorizationProvider authorization) { ClientPolicyRepresentation userRep = toRepresentation(policy, authorization); Map<String, String> config = new HashMap<>(); try { RealmModel realm = authorization.getRealm(); config.put("clients", JsonSerialization.writeValueAsString(userRep.getClients().stream().map(id -> realm.getClientById(id).getClientId()).collect(Collectors.toList()))); } catch (IOException cause) { throw new RuntimeException("Failed to export user policy [" + policy.getName() + "]", cause); } representation.setConfig(config); }
@Override public Map<String, AuthenticatedClientSessionModel> getAuthenticatedClientSessions() { AuthenticatedClientSessionStore clientSessionEntities = entity.getAuthenticatedClientSessions(); Map<String, AuthenticatedClientSessionModel> result = new HashMap<>(); List<String> removedClientUUIDS = new LinkedList<>(); if (clientSessionEntities != null) { clientSessionEntities.forEach((String key, UUID value) -> { // Check if client still exists ClientModel client = realm.getClientById(key); if (client != null) { final AuthenticatedClientSessionAdapter clientSession = provider.getClientSession(this, client, value, offline); if (clientSession != null) { result.put(key, clientSession); } } else { removedClientUUIDS.add(key); } }); } removeAuthenticatedClientSessions(removedClientUUIDS); return Collections.unmodifiableMap(result); }
@Override public RoleContainerModel getContainer() { if (role.isClientRole()) { return realm.getClientById(role.getClient().getId()); } else { return realm; } }
@Override public AuthenticatedClientSessionModel getAuthenticatedClientSessionByClient(String clientUUID) { AuthenticatedClientSessionStore clientSessionEntities = entity.getAuthenticatedClientSessions(); final UUID clientSessionId = clientSessionEntities.get(clientUUID); if (clientSessionId == null) { return null; } ClientModel client = realm.getClientById(clientUUID); if (client != null) { return provider.getClientSession(this, client, clientSessionId, offline); } removeAuthenticatedClientSessions(Collections.singleton(clientUUID)); return null; }
@Override public ClientModel getMasterAdminClient() { return cached.getMasterAdminClient()==null ? null : cacheSession.getRealm(Config.getAdminRealm()).getClientById(cached.getMasterAdminClient()); }
@Override public ClientModel getMasterAdminClient() { return cached.getMasterAdminClient()==null ? null : cacheSession.getRealm(Config.getAdminRealm()).getClientById(cached.getMasterAdminClient()); }
@Override public RoleModel getRoleById(String id, RealmModel realm) { MongoRoleEntity role = getMongoStore().loadEntity(MongoRoleEntity.class, id, invocationContext); if (role == null) return null; if (role.getRealmId() != null && !role.getRealmId().equals(realm.getId())) return null; if (role.getClientId() != null && realm.getClientById(role.getClientId()) == null) return null; return new RoleAdapter(session, realm, role, null, invocationContext); }
private boolean hasRole(Identity identity, RoleModel role, RealmModel realm) { String roleName = role.getName(); if (role.isClientRole()) { ClientModel clientModel = realm.getClientById(role.getContainerId()); return identity.hasClientRole(clientModel.getClientId(), roleName); } return identity.hasRealmRole(roleName); }
@Override public void evaluate(Evaluation evaluation) { ClientPolicyRepresentation representation = representationFunction.apply(evaluation.getPolicy(), evaluation.getAuthorizationProvider()); AuthorizationProvider authorizationProvider = evaluation.getAuthorizationProvider(); RealmModel realm = authorizationProvider.getKeycloakSession().getContext().getRealm(); EvaluationContext context = evaluation.getContext(); for (String client : representation.getClients()) { ClientModel clientModel = realm.getClientById(client); if (context.getAttributes().containsValue("kc.client.id", clientModel.getClientId())) { evaluation.grant(); return; } } }
private PersistentAuthenticatedClientSessionAdapter toAdapter(RealmModel realm, PersistentUserSessionAdapter userSession, PersistentClientSessionEntity entity) { String clientId = entity.getClientId(); if (!entity.getExternalClientId().equals("local")) { clientId = new StorageId(entity.getClientId(), entity.getExternalClientId()).getId(); } ClientModel client = realm.getClientById(clientId); PersistentClientSessionModel model = new PersistentClientSessionModel(); model.setClientId(clientId); model.setUserSessionId(userSession.getId()); model.setUserId(userSession.getUserId()); model.setTimestamp(entity.getTimestamp()); model.setData(entity.getData()); return new PersistentAuthenticatedClientSessionAdapter(model, realm, client, userSession); }
private PersistentClientSessionAdapter toAdapter(RealmModel realm, PersistentUserSessionAdapter userSession, PersistentClientSessionEntity entity) { ClientModel client = realm.getClientById(entity.getClientId()); PersistentClientSessionModel model = new PersistentClientSessionModel(); model.setClientSessionId(entity.getClientSessionId()); model.setClientId(entity.getClientId()); model.setUserSessionId(userSession.getId()); model.setUserId(userSession.getUser().getId()); model.setTimestamp(entity.getTimestamp()); model.setData(entity.getData()); return new PersistentClientSessionAdapter(model, realm, client, userSession); }
private UserConsentModel toConsentModel(RealmModel realm, UserConsentEntity entity) { ClientModel client = realm.getClientById(entity.getClientId()); if (client == null) { throw new ModelException("Client with id " + entity.getClientId() + " is not available"); } UserConsentModel model = new UserConsentModel(client); model.setCreatedDate(entity.getCreatedDate()); model.setLastUpdatedDate(entity.getLastUpdatedDate()); for (String roleId : entity.getGrantedRoles()) { RoleModel roleModel = realm.getRoleById(roleId); if (roleModel != null) { model.addGrantedRole(roleModel); } } for (String protMapperId : entity.getGrantedProtocolMappers()) { ProtocolMapperModel protocolMapper = client.getProtocolMapperById(protMapperId); model.addGrantedProtocolMapper(protocolMapper); } return model; }