Search in sources :

Example 6 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class JpaUserProvider method preRemove.

@Override
public void preRemove(RealmModel realm, ClientModel client) {
    StorageId clientStorageId = new StorageId(client.getId());
    if (clientStorageId.isLocal()) {
        em.createNamedQuery("deleteUserConsentClientScopesByClient").setParameter("clientId", client.getId()).executeUpdate();
        em.createNamedQuery("deleteUserConsentsByClient").setParameter("clientId", client.getId()).executeUpdate();
    } else {
        em.createNamedQuery("deleteUserConsentClientScopesByExternalClient").setParameter("clientStorageProvider", clientStorageId.getProviderId()).setParameter("externalClientId", clientStorageId.getExternalId()).executeUpdate();
        em.createNamedQuery("deleteUserConsentsByExternalClient").setParameter("clientStorageProvider", clientStorageId.getProviderId()).setParameter("externalClientId", clientStorageId.getExternalId()).executeUpdate();
    }
}
Also used : StorageId(org.keycloak.storage.StorageId)

Example 7 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class JpaUserFederatedStorageProvider method grantRole.

@Override
public void grantRole(RealmModel realm, String userId, RoleModel role) {
    createIndex(realm, userId);
    FederatedUserRoleMappingEntity entity = new FederatedUserRoleMappingEntity();
    entity.setUserId(userId);
    entity.setStorageProviderId(new StorageId(userId).getProviderId());
    entity.setRealmId(realm.getId());
    entity.setRoleId(role.getId());
    em.persist(entity);
}
Also used : FederatedUserRoleMappingEntity(org.keycloak.storage.jpa.entity.FederatedUserRoleMappingEntity) StorageId(org.keycloak.storage.StorageId)

Example 8 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class JpaUserFederatedStorageProvider method createCredential.

@Override
public CredentialModel createCredential(RealmModel realm, String userId, CredentialModel cred) {
    createIndex(realm, userId);
    FederatedUserCredentialEntity entity = new FederatedUserCredentialEntity();
    String id = cred.getId() == null ? KeycloakModelUtils.generateId() : cred.getId();
    entity.setId(id);
    entity.setCreatedDate(cred.getCreatedDate());
    entity.setType(cred.getType());
    entity.setCredentialData(cred.getCredentialData());
    entity.setSecretData(cred.getSecretData());
    entity.setUserLabel(cred.getUserLabel());
    entity.setUserId(userId);
    entity.setRealmId(realm.getId());
    entity.setStorageProviderId(new StorageId(userId).getProviderId());
    // add in linkedlist to last position
    List<FederatedUserCredentialEntity> credentials = getStoredCredentialEntitiesStream(userId).collect(Collectors.toList());
    int priority = credentials.isEmpty() ? JpaUserCredentialStore.PRIORITY_DIFFERENCE : credentials.get(credentials.size() - 1).getPriority() + JpaUserCredentialStore.PRIORITY_DIFFERENCE;
    entity.setPriority(priority);
    em.persist(entity);
    return toModel(entity);
}
Also used : FederatedUserCredentialEntity(org.keycloak.storage.jpa.entity.FederatedUserCredentialEntity) StorageId(org.keycloak.storage.StorageId)

Example 9 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class JpaUserFederatedStorageProvider method addFederatedIdentity.

@Override
public void addFederatedIdentity(RealmModel realm, String userId, FederatedIdentityModel link) {
    createIndex(realm, userId);
    BrokerLinkEntity entity = new BrokerLinkEntity();
    entity.setRealmId(realm.getId());
    entity.setUserId(userId);
    entity.setBrokerUserId(link.getUserId());
    entity.setIdentityProvider(link.getIdentityProvider());
    entity.setToken(link.getToken());
    entity.setBrokerUserName(link.getUserName());
    entity.setStorageProviderId(new StorageId(userId).getProviderId());
    em.persist(entity);
}
Also used : BrokerLinkEntity(org.keycloak.storage.jpa.entity.BrokerLinkEntity) StorageId(org.keycloak.storage.StorageId)

Example 10 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class JpaUserFederatedStorageProvider method addRequiredAction.

@Override
public void addRequiredAction(RealmModel realm, String userId, String action) {
    Key key = new FederatedUserRequiredActionEntity.Key(userId, action);
    if (em.find(FederatedUserRequiredActionEntity.class, key) == null) {
        createIndex(realm, userId);
        FederatedUserRequiredActionEntity entity = new FederatedUserRequiredActionEntity();
        entity.setUserId(userId);
        entity.setRealmId(realm.getId());
        entity.setStorageProviderId(new StorageId(userId).getProviderId());
        entity.setAction(action);
        em.persist(entity);
    }
}
Also used : FederatedUserRequiredActionEntity(org.keycloak.storage.jpa.entity.FederatedUserRequiredActionEntity) StorageId(org.keycloak.storage.StorageId) Key(org.keycloak.storage.jpa.entity.FederatedUserRequiredActionEntity.Key)

Aggregations

StorageId (org.keycloak.storage.StorageId)44 UserModel (org.keycloak.models.UserModel)7 RealmModel (org.keycloak.models.RealmModel)6 ComponentModel (org.keycloak.component.ComponentModel)5 ClientModel (org.keycloak.models.ClientModel)5 ClientScopeModel (org.keycloak.models.ClientScopeModel)5 List (java.util.List)3 Objects (java.util.Objects)3 Stream (java.util.stream.Stream)3 Test (org.junit.Test)3 KeycloakSession (org.keycloak.models.KeycloakSession)3 ModelException (org.keycloak.models.ModelException)3 UserConsentModel (org.keycloak.models.UserConsentModel)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2