Search in sources :

Example 6 with Group

use of org.simbasecurity.core.domain.Group in project simba-os by cegeka.

the class GroupDatabaseRepositoryTest method find.

@Test
public void find() {
    UserEntity user = new UserEntity("Jan");
    user.addGroup(group);
    persistAndRefresh(user);
    Collection<Group> result = groupDatabaseRepository.find(user);
    assertThat(result).containsOnly(group);
}
Also used : Group(org.simbasecurity.core.domain.Group) UserEntity(org.simbasecurity.core.domain.UserEntity) Test(org.junit.Test)

Example 7 with Group

use of org.simbasecurity.core.domain.Group in project simba-os by cegeka.

the class GroupServiceImpl method addRole.

public void addRole(TGroup group, TRole role) {
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role.getId(), role.getVersion());
    Group attachedGroup = groupRepository.refreshWithOptimisticLocking(group.getId(), group.getVersion());
    attachedGroup.addRole(attachedRole);
}
Also used : TRole(org.simbasecurity.api.service.thrift.TRole) Role(org.simbasecurity.core.domain.Role) TGroup(org.simbasecurity.api.service.thrift.TGroup) Group(org.simbasecurity.core.domain.Group)

Example 8 with Group

use of org.simbasecurity.core.domain.Group in project simba-os by cegeka.

the class GroupDatabaseRepository method findByCN.

@SuppressWarnings("unchecked")
@Override
public Group findByCN(String cn) {
    Query query = entityManager.createQuery("SELECT g FROM GroupEntity g WHERE g.cn = :cn").setParameter("cn", cn);
    List<Group> resultList = query.getResultList();
    if (resultList.size() == 0) {
        return null;
    } else if (resultList.size() == 1) {
        return resultList.get(0);
    }
    throw new IllegalStateException("Multiple users found for username: '" + cn + "'");
}
Also used : Group(org.simbasecurity.core.domain.Group) Query(javax.persistence.Query)

Aggregations

Group (org.simbasecurity.core.domain.Group)8 Role (org.simbasecurity.core.domain.Role)4 TGroup (org.simbasecurity.api.service.thrift.TGroup)3 TRole (org.simbasecurity.api.service.thrift.TRole)3 Test (org.junit.Test)2 UserEntity (org.simbasecurity.core.domain.UserEntity)2 GroupRepository (org.simbasecurity.core.domain.repository.GroupRepository)2 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 NamingEnumeration (javax.naming.NamingEnumeration)1 SearchControls (javax.naming.directory.SearchControls)1 SearchResult (javax.naming.directory.SearchResult)1 Query (javax.persistence.Query)1 GroupService (org.simbasecurity.api.service.thrift.GroupService)1 TUser (org.simbasecurity.api.service.thrift.TUser)1 GroupEntity (org.simbasecurity.core.domain.GroupEntity)1 Policy (org.simbasecurity.core.domain.Policy)1 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)1 ResourceRule (org.simbasecurity.core.domain.ResourceRule)1