use of com.serotonin.m2m2.vo.role.Role 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.Role in project ma-core-public by infiniteautomation.
the class AbstractVOServiceWithPermissionsTest 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);
}
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class AbstractVOServiceWithPermissionsTest method testAddEditRoleUserDoesNotHave.
/**
* There will be 2 validation messages about this, must retain permission AND cannot add/remove a role you do not have
*/
@Test
public void testAddEditRoleUserDoesNotHave() {
validation.expectValidationException(getEditPermissionContextKey());
VO vo = newVO(editUser);
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);
setEditPermission(MangoPermission.superadminOnly(), fromDb);
service.update(fromDb.getId(), fromDb);
});
}
use of com.serotonin.m2m2.vo.role.Role 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.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method mustRetainAccess.
@Test
@ExpectValidationException({ "readPermission", "editPermission" })
public void mustRetainAccess() {
Role otherRole = createRole(randomXid(), "Some other role").getRole();
User otherUser = insertUser();
User user = insertUser(editRole, readRole);
runAs.runAs(user, () -> {
otherUser.setReadPermission(MangoPermission.requireAnyRole(otherRole));
otherUser.setEditPermission(MangoPermission.requireAnyRole(otherRole));
service.update(otherUser.getId(), otherUser);
});
}
Aggregations