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());
});
}
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);
}
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()));
});
}
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);
}
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);
}
Aggregations