use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method ensureHasAnyPermissionFailNullEntry.
@Test(expected = IllegalArgumentException.class)
public void ensureHasAnyPermissionFailNullEntry() {
User testUser = this.createTestUser(roleService.getSuperadminRole());
permissionService.ensurePermission(testUser, MangoPermission.requireAnyRole((Role) null));
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method implodeRoles.
@Test
public void implodeRoles() {
Role perm1 = this.randomRole();
Role perm2 = this.randomRole();
Set<Role> permSet = new HashSet<>();
permSet.add(perm1);
permSet.add(perm2);
String joinedPerms = PermissionService.implodeRoles(permSet);
assertTrue(joinedPerms.contains(perm1.getXid()));
assertTrue(joinedPerms.contains(perm2.getXid()));
assertTrue(joinedPerms.contains(","));
assertFalse(joinedPerms.contains(" "));
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class MangoTestBase method createRole.
/**
* Create a role with inherited roles (
*/
protected RoleVO createRole(String xid, String name, Role... inherited) {
RoleService service = Common.getBean(RoleService.class);
RoleVO role = new RoleVO(Common.NEW_ID, xid, name, new HashSet<>(Arrays.asList(inherited)));
return service.insert(role);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method canEditPermissions.
@Test
public void canEditPermissions() {
Role otherRole = createRole(randomXid(), "Some other role").getRole();
User otherUser = insertUser();
User user = insertUser(editRole, readRole, otherRole);
runAs.runAs(user, () -> {
otherUser.setReadPermission(MangoPermission.requireAnyRole(otherRole));
otherUser.setEditPermission(MangoPermission.requireAnyRole(otherRole));
service.update(otherUser.getId(), otherUser);
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method testChangeUsernameWithoutPermission.
@Test
@ExpectValidationException("username")
public void testChangeUsernameWithoutPermission() {
setEditSelfPermission(MangoPermission.requireAnyRole(readRole));
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(ChangeOwnUsernamePermissionDefinition.PERMISSION);
Set<Set<Role>> roleSet = def.getPermission().getRoles();
Set<Set<Role>> newRoles = new HashSet<>();
newRoles.add(Collections.singleton(editRole));
for (Set<Role> roles : roleSet) {
if (roles.contains(PermissionHolder.USER_ROLE)) {
// skip the user role
continue;
}
newRoles.add(roles);
}
systemPermissionService.update(new MangoPermission(newRoles), def);
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);
});
}
Aggregations