use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class DataPointQueryPermissionTest method testAndPermission.
@Test
public void testAndPermission() {
// Insert some data points
Set<Role> readRoles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
List<IDataPoint> points = this.createMockDataPoints(5, false, MangoPermission.requireAllRoles(readRoles), new MangoPermission());
List<IDataPoint> unreadable = this.createMockDataPoints(5, false, new MangoPermission(), new MangoPermission());
DataPointService service = Common.getBean(DataPointService.class);
runAs.runAs(new PermissionHolder() {
@Override
public String getPermissionHolderName() {
return "Test";
}
@Override
public boolean isPermissionHolderDisabled() {
return false;
}
@Override
public Set<Role> getRoles() {
return readRoles;
}
}, () -> {
List<Integer> ids = points.stream().map(dp -> dp.getId()).collect(Collectors.toList());
ids.addAll(unreadable.stream().map(dp -> dp.getId()).collect(Collectors.toList()));
QueryBuilder<DataPointVO> query = service.buildQuery().in("id", ids.toArray());
List<DataPointVO> vos = query.query();
assertEquals(points.size(), vos.size());
for (DataPointVO vo : vos) {
assertTrue(points.contains(vo));
}
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
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.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method ensureHasAnyRoleOKHasBoth.
@Test
public void ensureHasAnyRoleOKHasBoth() {
Role perm1 = this.randomRole();
Role perm2 = this.randomRole();
User testUser = this.createTestUser(Sets.newHashSet(perm1, perm2));
permissionService.ensurePermission(testUser, MangoPermission.requireAnyRole(perm1, perm2));
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method ensureHasAllPermissionsFailHasOne.
@Test(expected = PermissionException.class)
public void ensureHasAllPermissionsFailHasOne() {
Role perm1 = this.randomRole();
Role perm2 = this.randomRole();
User testUser = this.createTestUser(Sets.newHashSet(perm1, 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 ensureHasAnyPermissionFailHasNeither.
@Test(expected = PermissionException.class)
public void ensureHasAnyPermissionFailHasNeither() {
Role perm1 = this.randomRole();
Role perm2 = this.randomRole();
Role perm3 = this.randomRole();
Role perm4 = this.randomRole();
User testUser = this.createTestUser(Sets.newHashSet(perm1, perm2));
permissionService.ensurePermission(testUser, MangoPermission.requireAnyRole(perm3, perm4));
}
Aggregations