Search in sources :

Example 61 with RoleVO

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());
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) Test(org.junit.Test)

Example 62 with RoleVO

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);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) RoleVO(com.serotonin.m2m2.vo.role.RoleVO)

Example 63 with RoleVO

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;
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO)

Example 64 with RoleVO

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;
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) Matcher(java.util.regex.Matcher) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) HashSet(java.util.HashSet)

Example 65 with RoleVO

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);
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) RoleService(com.infiniteautomation.mango.spring.service.RoleService)

Aggregations

RoleVO (com.serotonin.m2m2.vo.role.RoleVO)58 Test (org.junit.Test)34 Role (com.serotonin.m2m2.vo.role.Role)33 HashSet (java.util.HashSet)17 RoleService (com.infiniteautomation.mango.spring.service.RoleService)14 User (com.serotonin.m2m2.vo.User)11 ArrayList (java.util.ArrayList)11 ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)8 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)8 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)7 JsonValue (com.serotonin.json.type.JsonValue)7 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)7 Set (java.util.Set)7 Roles (com.infiniteautomation.mango.db.tables.Roles)6 JsonException (com.serotonin.json.JsonException)6 DSLContext (org.jooq.DSLContext)6 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)5 JsonObject (com.serotonin.json.type.JsonObject)5 ImportContext (com.infiniteautomation.mango.emport.ImportContext)4 JsonReader (com.serotonin.json.JsonReader)4