use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method testChangeUsernameWithPermission.
@Test
public void testChangeUsernameWithPermission() {
// Add read role to change username permission
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(ChangeOwnUsernamePermissionDefinition.PERMISSION);
Set<Set<Role>> roleSet = def.getPermission().getRoles();
Set<Set<Role>> newRoles = new HashSet<>();
newRoles.add(Collections.singleton(readRole));
for (Set<Role> roles : roleSet) {
newRoles.add(new HashSet<>(roles));
}
systemPermissionService.update(new MangoPermission(newRoles), def);
// Ensure they can edit self
setEditSelfPermission(MangoPermission.requireAnyRole(readRole));
User vo = newVO(readUser);
vo.setRoles(Collections.singleton(readRole));
service.insert(vo);
User saved = service.get(vo.getId());
runAs.runAs(saved, () -> {
saved.setUsername(randomXid());
service.update(saved.getId(), saved);
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method createDataSource.
MockDataSourceVO createDataSource(Set<Role> editRoles) {
MockDataSourceVO dsVo = new MockDataSourceVO();
dsVo.setName("permissions_test_datasource");
dsVo.setEditPermission(MangoPermission.requireAnyRole(editRoles));
return (MockDataSourceVO) dataSourceService.insert(dsVo);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method ensureHasAllPermissionsFailHasNeither.
@Test(expected = PermissionException.class)
public void ensureHasAllPermissionsFailHasNeither() {
Role perm1 = this.randomRole();
Role perm2 = this.randomRole();
User testUser = this.createTestUser(Sets.newHashSet(randomRole(), randomRole()));
permissionService.ensurePermission(testUser, MangoPermission.requireAllRoles(perm1, perm2));
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method ensureHasSingleRoleFailEmptyRoles.
@Test(expected = PermissionException.class)
public void ensureHasSingleRoleFailEmptyRoles() {
User testUser = this.createTestUser();
Role unsavedRole = new Role(Common.NEW_ID, UUID.randomUUID().toString());
permissionService.ensurePermission(testUser, MangoPermission.requireAnyRole(unsavedRole));
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class RoleServiceTest method adminCanSeeAllRoles.
@Test
public void adminCanSeeAllRoles() {
RoleVO vo = insertNewVO(readUser);
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 superadmin role", roleXids.contains(PermissionHolder.SUPERADMIN_ROLE_XID));
Assert.assertTrue("Superadmin should see all roles", roleXids.contains(vo.getXid()));
}
Aggregations