Search in sources :

Example 96 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class AbstractVOServiceWithPermissionsTest method testAddReadRoleUserDoesNotHave.

/**
 * There will be 2 validation messages about this, must retain permission AND cannot add/remove a role you do not have
 */
@Test
public void testAddReadRoleUserDoesNotHave() {
    validation.expectValidationException(getReadPermissionContextKey());
    VO vo = newVO(readUser);
    setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    service.insert(vo);
    runAs.runAs(readUser, () -> {
        VO fromDb = service.get(vo.getId());
        assertVoEqual(vo, fromDb);
        setReadPermission(MangoPermission.superadminOnly(), fromDb);
        service.update(fromDb.getId(), fromDb);
    });
}
Also used : AbstractVO(com.serotonin.m2m2.vo.AbstractVO) Test(org.junit.Test)

Example 97 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class AbstractBasicVOServiceWithPermissionsTestBase method addRoleToCreatePermission.

void addRoleToCreatePermission(Role vo) {
    String permissionType = getCreatePermissionType();
    if (permissionType != null) {
        PermissionDefinition def = ModuleRegistry.getPermissionDefinition(getCreatePermissionType());
        Set<Set<Role>> roleSet = def.getPermission().getRoles();
        Set<Set<Role>> newRoles = new HashSet<>();
        newRoles.add(Collections.singleton(vo));
        for (Set<Role> roles : roleSet) {
            newRoles.add(new HashSet<>(roles));
        }
        Common.getBean(SystemPermissionService.class).update(new MangoPermission(newRoles), def);
    }
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) Set(java.util.Set) HashSet(java.util.HashSet) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Example 98 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class PermissionServiceTest method randomRole.

Role randomRole() {
    RoleVO vo = new RoleVO(Common.NEW_ID, UUID.randomUUID().toString(), "Random permission");
    roleService.insert(vo);
    return new Role(vo);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) RoleVO(com.serotonin.m2m2.vo.role.RoleVO)

Example 99 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class PermissionServiceTest method ensureHasSingleRoleOKHasPerm.

@Test
public void ensureHasSingleRoleOKHasPerm() {
    Set<Role> roles = this.randomRoles(2);
    User testUser = this.createTestUser(roles);
    for (Role role : testUser.getRoles()) {
        permissionService.ensurePermission(testUser, MangoPermission.requireAnyRole(role));
    }
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test)

Example 100 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class PermissionServiceTest method ensureHasAnyRoleOKHasOne.

@Test
public void ensureHasAnyRoleOKHasOne() {
    Role perm1 = this.randomRole();
    Role perm2 = this.randomRole();
    Role perm3 = this.randomRole();
    User testUser = this.createTestUser(Sets.newHashSet(perm1, perm2));
    permissionService.ensurePermission(testUser, MangoPermission.requireAnyRole(perm1, perm3));
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test)

Aggregations

Role (com.serotonin.m2m2.vo.role.Role)102 Test (org.junit.Test)59 HashSet (java.util.HashSet)40 Set (java.util.Set)38 User (com.serotonin.m2m2.vo.User)33 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)23 RoleVO (com.serotonin.m2m2.vo.role.RoleVO)22 Collectors (java.util.stream.Collectors)18 Common (com.serotonin.m2m2.Common)17 MangoTestBase (com.serotonin.m2m2.MangoTestBase)15 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)15 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)15 List (java.util.List)15 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)14 Assert.assertEquals (org.junit.Assert.assertEquals)14 Assert.assertTrue (org.junit.Assert.assertTrue)14 DataPointService (com.infiniteautomation.mango.spring.service.DataPointService)12 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)12 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)11 DSLContext (org.jooq.DSLContext)11