Search in sources :

Example 1 with Group

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

the class GroupServiceImpl method addRoles.

public void addRoles(TGroup group, List<TRole> roles) {
    Group attachedGroup = groupRepository.refreshWithOptimisticLocking(group.getId(), group.getVersion());
    Collection<Role> attachedRoles = roles.stream().map(r -> roleRepository.refreshWithOptimisticLocking(r.getId(), r.getVersion())).collect(Collectors.toList());
    attachedGroup.addRoles(attachedRoles);
}
Also used : TRole(org.simbasecurity.api.service.thrift.TRole) RoleRepository(org.simbasecurity.core.domain.repository.RoleRepository) Role(org.simbasecurity.core.domain.Role) TGroup(org.simbasecurity.api.service.thrift.TGroup) Group(org.simbasecurity.core.domain.Group) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) TUser(org.simbasecurity.api.service.thrift.TUser) GroupRepository(org.simbasecurity.core.domain.repository.GroupRepository) List(java.util.List) Service(org.springframework.stereotype.Service) GroupService(org.simbasecurity.api.service.thrift.GroupService) ThriftAssembler(org.simbasecurity.core.service.thrift.ThriftAssembler) Transactional(org.springframework.transaction.annotation.Transactional) 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 2 with Group

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

the class GroupServiceImpl method removeRole.

public void removeRole(TGroup group, TRole role) {
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role.getId(), role.getVersion());
    Group attachedGroup = groupRepository.refreshWithOptimisticLocking(group.getId(), group.getVersion());
    attachedGroup.removeRole(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 3 with Group

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

the class ActiveDirectoryLoginModule method addADGroupsToUser.

protected void addADGroupsToUser(LdapContext ldapContext, User user, String userCN) throws NamingException {
    SearchControls searchControls = new SearchControls();
    searchControls.setReturningAttributes(new String[] { "dn" });
    searchControls.setSearchScope(searchScope);
    GroupRepository groupRepository = GlobalContext.locate(GroupRepository.class);
    String filterGroups = "(&(member=" + userCN + "," + searchBase + ")(objectcategory=group))";
    NamingEnumeration results = ldapContext.search(searchBase, filterGroups, searchControls);
    while (hasMoreResults(results)) {
        String groupCN = ((SearchResult) results.next()).getName();
        Group group = groupRepository.findByCN(groupCN);
        if (group != null) {
            user.addGroup(group);
        }
    }
}
Also used : Group(org.simbasecurity.core.domain.Group) SearchControls(javax.naming.directory.SearchControls) NamingEnumeration(javax.naming.NamingEnumeration) SearchResult(javax.naming.directory.SearchResult) GroupRepository(org.simbasecurity.core.domain.repository.GroupRepository)

Example 4 with Group

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

the class GroupDatabaseRepositoryTest method findByName_success.

@Test
public void findByName_success() {
    Group result = groupDatabaseRepository.findByCN(DUMMY_GROUP_CN);
    assertNotNull(result);
    assertEquals(DUMMY_GROUP_NAME, result.getName());
}
Also used : Group(org.simbasecurity.core.domain.Group) Test(org.junit.Test)

Example 5 with Group

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

the class RuleDatabaseRepositoryTest method setupWithGroups.

private ResourceRule setupWithGroups() {
    User user = new UserEntity(USER_VIA_GROUP);
    Role role = new RoleEntity("role2");
    Group group = new GroupEntity("groupName", "cn");
    Policy policy = new PolicyEntity("policy2");
    ResourceRule resourceRuleEntity = new ResourceRuleEntity("resrule2");
    resourceRuleEntity.setResourceName("resname2");
    urlRuleEntityViaGroup = new URLRuleEntity("urlrule2");
    persistAndRefresh(user, role, policy, resourceRuleEntity, urlRuleEntityViaGroup);
    persistAndRefresh(user, group, role, policy, resourceRuleEntity, urlRuleEntityViaGroup);
    policy.addRule(resourceRuleEntity);
    policy.addRule(urlRuleEntityViaGroup);
    role.addPolicy(policy);
    group.addRole(role);
    user.addGroup(group);
    return resourceRuleEntity;
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) Policy(org.simbasecurity.core.domain.Policy) Group(org.simbasecurity.core.domain.Group) User(org.simbasecurity.core.domain.User) GroupEntity(org.simbasecurity.core.domain.GroupEntity) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) ResourceRule(org.simbasecurity.core.domain.ResourceRule) ResourceRuleEntity(org.simbasecurity.core.domain.ResourceRuleEntity) UserEntity(org.simbasecurity.core.domain.UserEntity) URLRuleEntity(org.simbasecurity.core.domain.URLRuleEntity)

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