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);
}
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();
}
Aggregations