Search in sources :

Example 1 with RoleEntity

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

the class RoleDTOAssemblerTest method testAssembleSingleRole.

@Test
public void testAssembleSingleRole() {
    Role role = new RoleEntity("role name");
    RoleDTO roleData = RoleDTOAssembler.assemble(role);
    assertNotNull(roleData);
    assertEquals(0, roleData.getId());
    assertEquals(role.getName(), roleData.getName());
    assertEquals(0, role.getId());
    assertEquals(0, role.getVersion());
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) RoleDTO(org.simbasecurity.core.service.manager.dto.RoleDTO) Test(org.junit.Test)

Example 2 with RoleEntity

use of org.simbasecurity.core.domain.RoleEntity 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)

Example 3 with RoleEntity

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

the class RoleServiceImpl method createRole.

public TRole createRole(String roleName) throws TException {
    return simbaExceptionHandlingCaller.call(() -> {
        try {
            DTOValidator.assertValidString("createRole", roleName);
            if (roleRepository.findByName(roleName) != null) {
                throw new IllegalArgumentException("Role with name " + roleName + " already exists");
            }
            Role newRole = new RoleEntity(roleName);
            roleRepository.persist(newRole);
            managementAudit.log("Role ''{0}'' created", roleName);
            return assembler.assemble(newRole);
        } catch (ValidationException e) {
            throw new IllegalArgumentException(e);
        }
    });
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) ValidationException(org.owasp.esapi.errors.ValidationException)

Example 4 with RoleEntity

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

the class RoleDTOAssemblerTest method testAssembleMultipleRoles.

@Test
public void testAssembleMultipleRoles() {
    Role role = new RoleEntity("role name");
    Collection<RoleDTO> roleDataList = RoleDTOAssembler.assemble(Arrays.asList(role));
    assertNotNull(roleDataList);
    assertEquals(1, roleDataList.size());
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) RoleDTO(org.simbasecurity.core.service.manager.dto.RoleDTO) Test(org.junit.Test)

Example 5 with RoleEntity

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

the class RuleDatabaseRepositoryTest method setUp.

@Before
public void setUp() {
    UserEntity user = new UserEntity(USER_NAME);
    RoleEntity role = new RoleEntity(ROLE_NAME);
    policy = new PolicyEntity(POLICY_NAME);
    resourceRuleEntity = new ResourceRuleEntity(RESOURCE_RULE_NAME);
    resourceRuleEntity.setResourceName(RESOURCE_NAME);
    urlRuleEntity = new URLRuleEntity("urlrule");
    persistAndRefresh(user, role, policy, resourceRuleEntity, urlRuleEntity);
    policy.addRule(resourceRuleEntity);
    policy.addRule(urlRuleEntity);
    role.addPolicy(policy);
    user.addRole(role);
}
Also used : RoleEntity(org.simbasecurity.core.domain.RoleEntity) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) ResourceRuleEntity(org.simbasecurity.core.domain.ResourceRuleEntity) UserEntity(org.simbasecurity.core.domain.UserEntity) URLRuleEntity(org.simbasecurity.core.domain.URLRuleEntity) Before(org.junit.Before)

Aggregations

RoleEntity (org.simbasecurity.core.domain.RoleEntity)5 Role (org.simbasecurity.core.domain.Role)4 Test (org.junit.Test)2 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)2 ResourceRuleEntity (org.simbasecurity.core.domain.ResourceRuleEntity)2 URLRuleEntity (org.simbasecurity.core.domain.URLRuleEntity)2 UserEntity (org.simbasecurity.core.domain.UserEntity)2 RoleDTO (org.simbasecurity.core.service.manager.dto.RoleDTO)2 Before (org.junit.Before)1 ValidationException (org.owasp.esapi.errors.ValidationException)1 Group (org.simbasecurity.core.domain.Group)1 GroupEntity (org.simbasecurity.core.domain.GroupEntity)1 Policy (org.simbasecurity.core.domain.Policy)1 ResourceRule (org.simbasecurity.core.domain.ResourceRule)1 User (org.simbasecurity.core.domain.User)1