use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class RoleServiceTest method testCount.
@Override
@Test
public void testCount() {
List<RoleVO> all = service.dao.getAll();
for (RoleVO vo : all) {
if (!StringUtils.equals(PermissionHolder.SUPERADMIN_ROLE_XID, vo.getXid()) && !StringUtils.equals(PermissionHolder.USER_ROLE_XID, vo.getXid()) && !StringUtils.equals(PermissionHolder.ANONYMOUS_ROLE_XID, vo.getXid())) {
service.delete(vo.getId());
}
}
for (int i = 0; i < 5; i++) {
insertNewVO(readUser);
}
assertEquals(8, service.dao.count());
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
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);
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class PermissionService method loadRoleInheritance.
private RoleInheritance loadRoleInheritance(String xid) {
RoleInheritance i = new RoleInheritance();
RoleVO roleVo = roleDao.getByXid(xid);
if (roleVo == null) {
return null;
}
i.role = roleVo.getRole();
i.inherited = roleDao.getFlatInheritance(roleVo.getRole());
i.inheritedBy = roleDao.getRolesThatInherit(roleVo.getRole());
return i;
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class RoleService method commonValidation.
public ProcessResult commonValidation(RoleVO vo) {
ProcessResult result = super.validate(vo);
// Don't allow the use of role 'user' or 'superadmin'
if (StringUtils.equalsIgnoreCase(vo.getXid(), getSuperadminRole().getXid())) {
result.addContextualMessage("xid", "roles.cannotAlterSuperadminRole");
}
if (StringUtils.equalsIgnoreCase(vo.getXid(), getUserRole().getXid())) {
result.addContextualMessage("xid", "roles.cannotAlterUserRole");
}
if (StringUtils.equalsIgnoreCase(vo.getXid(), getAnonymousRole().getXid())) {
result.addContextualMessage("xid", "roles.cannotAlterAnonymousRole");
}
// Don't allow spaces in the XID
Matcher matcher = Functions.WHITESPACE_PATTERN.matcher(vo.getXid());
if (matcher.find()) {
result.addContextualMessage("xid", "validate.role.noSpaceAllowed");
}
// Ensure inherited roles exist and they are not us and there are no loops
if (vo.getInherited() != null) {
Set<Role> used = new HashSet<>();
used.add(vo.getRole());
for (Role role : vo.getInherited()) {
if (dao.getXidById(role.getId()) == null) {
result.addContextualMessage("inherited", "validate.role.notFound", role.getXid());
}
if (recursivelyCheckForUsedRoles(role, used)) {
result.addContextualMessage("inherited", "validate.role.inheritanceLoop", role.getXid());
break;
}
}
}
return result;
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
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);
}
Aggregations