Search in sources :

Example 1 with FederatedUserGroupMembershipEntity

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

the class JpaUserFederatedStorageProvider method joinGroup.

@Override
public void joinGroup(RealmModel realm, String userId, GroupModel group) {
    createIndex(realm, userId);
    FederatedUserGroupMembershipEntity entity = new FederatedUserGroupMembershipEntity();
    entity.setUserId(userId);
    entity.setStorageProviderId(new StorageId(userId).getProviderId());
    entity.setGroupId(group.getId());
    entity.setRealmId(realm.getId());
    em.persist(entity);
}
Also used : FederatedUserGroupMembershipEntity(org.keycloak.storage.jpa.entity.FederatedUserGroupMembershipEntity) StorageId(org.keycloak.storage.StorageId)

Example 2 with FederatedUserGroupMembershipEntity

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

the class JpaUserFederatedStorageProvider method leaveGroup.

@Override
public void leaveGroup(RealmModel realm, String userId, GroupModel group) {
    if (userId == null || group == null)
        return;
    TypedQuery<FederatedUserGroupMembershipEntity> query1 = em.createNamedQuery("feduserMemberOf", FederatedUserGroupMembershipEntity.class);
    query1.setParameter("userId", userId);
    query1.setParameter("groupId", group.getId());
    TypedQuery<FederatedUserGroupMembershipEntity> query = query1;
    query.setLockMode(LockModeType.PESSIMISTIC_WRITE);
    List<FederatedUserGroupMembershipEntity> results = query.getResultList();
    if (results.size() == 0)
        return;
    for (FederatedUserGroupMembershipEntity entity : results) {
        em.remove(entity);
    }
    em.flush();
}
Also used : FederatedUserGroupMembershipEntity(org.keycloak.storage.jpa.entity.FederatedUserGroupMembershipEntity)

Aggregations

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