Search in sources :

Example 1 with ClientScopeClientMappingEntity

use of org.keycloak.models.jpa.entities.ClientScopeClientMappingEntity in project keycloak by keycloak.

the class JpaRealmProvider method addClientScopes.

@Override
public void addClientScopes(RealmModel realm, ClientModel client, Set<ClientScopeModel> clientScopes, boolean defaultScope) {
    // Defaults to openid-connect
    String clientProtocol = client.getProtocol() == null ? OIDCLoginProtocol.LOGIN_PROTOCOL : client.getProtocol();
    Map<String, ClientScopeModel> existingClientScopes = getClientScopes(realm, client, true);
    existingClientScopes.putAll(getClientScopes(realm, client, false));
    clientScopes.stream().filter(clientScope -> !existingClientScopes.containsKey(clientScope.getName())).filter(clientScope -> Objects.equals(clientScope.getProtocol(), clientProtocol)).forEach(clientScope -> {
        ClientScopeClientMappingEntity entity = new ClientScopeClientMappingEntity();
        entity.setClientScopeId(clientScope.getId());
        entity.setClientId(client.getId());
        entity.setDefaultScope(defaultScope);
        em.persist(entity);
        em.flush();
        em.detach(entity);
    });
}
Also used : GroupEntity(org.keycloak.models.jpa.entities.GroupEntity) Join(javax.persistence.criteria.Join) ClientProvider(org.keycloak.models.ClientProvider) RoleContainerModel(org.keycloak.models.RoleContainerModel) StackUtil.getShortStackTrace(org.keycloak.common.util.StackUtil.getShortStackTrace) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DeploymentStateProvider(org.keycloak.models.DeploymentStateProvider) ClientEntity(org.keycloak.models.jpa.entities.ClientEntity) Time(org.keycloak.common.util.Time) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ClientScopeModel(org.keycloak.models.ClientScopeModel) RealmModel(org.keycloak.models.RealmModel) RoleProvider(org.keycloak.models.RoleProvider) StreamsUtil.closing(org.keycloak.utils.StreamsUtil.closing) Set(java.util.Set) RoleModel(org.keycloak.models.RoleModel) Collectors(java.util.stream.Collectors) PaginationUtils.paginateQuery(org.keycloak.models.jpa.PaginationUtils.paginateQuery) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) OIDCLoginProtocol(org.keycloak.protocol.oidc.OIDCLoginProtocol) RoleEntity(org.keycloak.models.jpa.entities.RoleEntity) ClientModel(org.keycloak.models.ClientModel) ClientScopeEntity(org.keycloak.models.jpa.entities.ClientScopeEntity) RealmLocalizationTextsEntity(org.keycloak.models.jpa.entities.RealmLocalizationTextsEntity) KeycloakModelUtils(org.keycloak.models.utils.KeycloakModelUtils) Logger(org.jboss.logging.Logger) HashMap(java.util.HashMap) MigrationModel(org.keycloak.migration.MigrationModel) Function(java.util.function.Function) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) RealmProvider(org.keycloak.models.RealmProvider) CriteriaDelete(javax.persistence.criteria.CriteriaDelete) GroupModel(org.keycloak.models.GroupModel) GroupProvider(org.keycloak.models.GroupProvider) ClientModelLazyDelegate(org.keycloak.models.delegate.ClientModelLazyDelegate) Root(javax.persistence.criteria.Root) RoleRemovedEvent(org.keycloak.models.RoleContainerModel.RoleRemovedEvent) KeycloakSession(org.keycloak.models.KeycloakSession) ClientScopeClientMappingEntity(org.keycloak.models.jpa.entities.ClientScopeClientMappingEntity) EntityManager(javax.persistence.EntityManager) JpaUtils(org.keycloak.connections.jpa.util.JpaUtils) ModelException(org.keycloak.models.ModelException) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) LockModeType(javax.persistence.LockModeType) RealmEntity(org.keycloak.models.jpa.entities.RealmEntity) ClientScopeProvider(org.keycloak.models.ClientScopeProvider) ClientAttributeEntity(org.keycloak.models.jpa.entities.ClientAttributeEntity) ClientScopeClientMappingEntity(org.keycloak.models.jpa.entities.ClientScopeClientMappingEntity) ClientScopeModel(org.keycloak.models.ClientScopeModel)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 EntityManager (javax.persistence.EntityManager)1 LockModeType (javax.persistence.LockModeType)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaDelete (javax.persistence.criteria.CriteriaDelete)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Join (javax.persistence.criteria.Join)1 Predicate (javax.persistence.criteria.Predicate)1 Root (javax.persistence.criteria.Root)1 Logger (org.jboss.logging.Logger)1 StackUtil.getShortStackTrace (org.keycloak.common.util.StackUtil.getShortStackTrace)1