Search in sources :

Example 31 with RoleVO

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

the class RoleServiceTest method cantGetRoleUserDoesNotHave.

@Test(expected = PermissionException.class)
public void cantGetRoleUserDoesNotHave() {
    RoleVO roleUserHas = insertNewVO(readUser);
    RoleVO roleUserDoesNotHave = insertNewVO(readUser);
    User testUser = createUser("test-user@example.com", "test-user@example.com", "test-user@example.com", "test-user@example.com", roleUserHas.getRole());
    runAs.runAs(testUser, () -> {
        service.get(roleUserDoesNotHave.getXid());
    });
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test)

Example 32 with RoleVO

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

the class RoleServiceTest method cannotModifyUserRole.

@Test
@ExpectValidationException("xid")
public void cannotModifyUserRole() {
    RoleVO vo = service.get(PermissionHolder.USER_ROLE_XID);
    RoleVO updated = new RoleVO(Common.NEW_ID, vo.getXid(), vo.getName());
    service.update(vo.getXid(), updated);
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 33 with RoleVO

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

the class RoleServiceTest method userCanOnlySeeOwnRoles.

@Test
public void userCanOnlySeeOwnRoles() {
    RoleVO inheritedRole = insertNewVO(readUser);
    RoleVO directlyAssignedRole = newVO(readUser);
    directlyAssignedRole.setInherited(Collections.singleton(inheritedRole.getRole()));
    service.insert(directlyAssignedRole);
    RoleVO roleUserDoesNotHave = insertNewVO(readUser);
    User testUser = createUser("test-user@example.com", "test-user@example.com", "test-user@example.com", "test-user@example.com", directlyAssignedRole.getRole());
    runAs.runAs(testUser, () -> {
        Set<String> roleXids = service.list().stream().map(AbstractVO::getXid).collect(Collectors.toSet());
        Assert.assertTrue("Should see anonymous role", roleXids.contains(PermissionHolder.ANONYMOUS_ROLE_XID));
        Assert.assertTrue("Should see user role", roleXids.contains(PermissionHolder.USER_ROLE_XID));
        Assert.assertTrue("Should see directly assigned role", roleXids.contains(directlyAssignedRole.getXid()));
        Assert.assertTrue("Should see inherited role", roleXids.contains(inheritedRole.getXid()));
        Assert.assertFalse("Should not see role that user does not have", roleXids.contains(roleUserDoesNotHave.getXid()));
    });
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test)

Example 34 with RoleVO

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

the class AbstractRoleBasedTest method setupRoles.

protected void setupRoles() {
    roleService = Common.getBean(RoleService.class);
    // Add some roles
    RoleVO temp = new RoleVO(Common.NEW_ID, "read-role", "Role to allow reading.");
    roleService.insert(temp);
    readRole = new Role(temp);
    temp = new RoleVO(Common.NEW_ID, "edit-role", "Role to allow editing.");
    roleService.insert(temp);
    editRole = new Role(temp);
    temp = new RoleVO(Common.NEW_ID, "set-role", "Role to allow setting.");
    roleService.insert(temp);
    setRole = new Role(temp);
    temp = new RoleVO(Common.NEW_ID, "delete-role", "Role to allow deleting.");
    roleService.insert(temp);
    deleteRole = new Role(temp);
    readUser = createUser("readUser", "readUser", "password", "readUser@example.com", readRole);
    editUser = createUser("editUser", "editUser", "password", "editUser@example.com", editRole);
    setUser = createUser("setUser", "setUser", "password", "setUser@example.com", setRole);
    deleteUser = createUser("deleteUser", "deleteUser", "password", "deleteUser@example.com", deleteRole);
    allUser = createUser("allUser", "allUser", "password", "allUser@example.com", readRole, editRole, setRole, deleteRole);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) RoleVO(com.serotonin.m2m2.vo.role.RoleVO) RoleService(com.infiniteautomation.mango.spring.service.RoleService)

Example 35 with RoleVO

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

the class EventInstanceWithTagsQueryTest method setupRoles.

void setupRoles() {
    roleService = Common.getBean(RoleService.class);
    // Add some roles
    RoleVO temp = new RoleVO(Common.NEW_ID, "point-1-read-role", "Role to allow reading.");
    roleService.insert(temp);
    point1ReadRole = new Role(temp);
    temp = new RoleVO(Common.NEW_ID, "point-2-read-role", "Role to allow reading.");
    roleService.insert(temp);
    point2ReadRole = new Role(temp);
    point1User = createUser("point1User", "point1User", "password", "point1User@example.com", point1ReadRole);
    point2User = createUser("poin2User", "poin2User", "password", "poin2User@example.com", point2ReadRole);
    allUser = createUser("allUser", "allUser", "password", "allUser@example.com", point1ReadRole, point2ReadRole);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) RoleVO(com.serotonin.m2m2.vo.role.RoleVO)

Aggregations

RoleVO (com.serotonin.m2m2.vo.role.RoleVO)58 Test (org.junit.Test)34 Role (com.serotonin.m2m2.vo.role.Role)33 HashSet (java.util.HashSet)17 RoleService (com.infiniteautomation.mango.spring.service.RoleService)14 User (com.serotonin.m2m2.vo.User)11 ArrayList (java.util.ArrayList)11 ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)8 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)8 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)7 JsonValue (com.serotonin.json.type.JsonValue)7 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)7 Set (java.util.Set)7 Roles (com.infiniteautomation.mango.db.tables.Roles)6 JsonException (com.serotonin.json.JsonException)6 DSLContext (org.jooq.DSLContext)6 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)5 JsonObject (com.serotonin.json.type.JsonObject)5 ImportContext (com.infiniteautomation.mango.emport.ImportContext)4 JsonReader (com.serotonin.json.JsonReader)4