Search in sources :

Example 1 with FederatedUserRoleMappingEntity

use of org.keycloak.storage.jpa.entity.FederatedUserRoleMappingEntity 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 2 with FederatedUserRoleMappingEntity

use of org.keycloak.storage.jpa.entity.FederatedUserRoleMappingEntity in project keycloak by keycloak.

the class JpaUserFederatedStorageProvider method deleteRoleMapping.

@Override
public void deleteRoleMapping(RealmModel realm, String userId, RoleModel role) {
    TypedQuery<FederatedUserRoleMappingEntity> query = em.createNamedQuery("feduserRoleMappings", FederatedUserRoleMappingEntity.class);
    query.setParameter("userId", userId);
    List<FederatedUserRoleMappingEntity> results = query.getResultList();
    query.setLockMode(LockModeType.PESSIMISTIC_WRITE);
    for (FederatedUserRoleMappingEntity entity : results) {
        if (entity.getRoleId().equals(role.getId()))
            em.remove(entity);
    }
    em.flush();
}
Also used : FederatedUserRoleMappingEntity(org.keycloak.storage.jpa.entity.FederatedUserRoleMappingEntity)

Aggregations

FederatedUserRoleMappingEntity (org.keycloak.storage.jpa.entity.FederatedUserRoleMappingEntity)2 StorageId (org.keycloak.storage.StorageId)1