use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionPersistenceTest method testAndPermission.
@Test
public void testAndPermission() {
PermissionService service = Common.getBean(PermissionService.class);
// Create some roles
Set<Role> roles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
// insert the permission
MangoPermission permission = service.findOrCreate(MangoPermission.requireAllRoles(roles));
MangoPermission read = service.get(permission.getId());
assertEquals(1, read.getRoles().size());
Iterator<Set<Role>> it = read.getRoles().iterator();
assertEquals(2, it.next().size());
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class ViewDataPointsPermissionTest method init.
@Before
public void init() {
this.runAs = Common.getBean(RunAs.class);
this.service = Common.getBean(DataPointService.class);
// create Role for this test
this.viewDataPointsRole = this.createRole("viewDataPointsRole", DataPointPermissionDefinition.PERMISSION);
this.userAllowed = this.createUser("Jane Doe", "Jane001", "14mJ4n3D03!", "jane.doe@unknown.com", viewDataPointsRole.getRole());
this.userWithoutPermission = this.createUser("John Doe", "John001", "14mJ0hnD03!", "john.doe@unknown.com");
// get the permission def
DataPointPermissionDefinition dpPermDef = Common.getBean(DataPointPermissionDefinition.class);
SystemPermissionService sysPermServ = Common.getBean(SystemPermissionService.class);
this.runAs.runAs(this.runAs.systemSuperadmin(), () -> {
sysPermServ.update(MangoPermission.requireAnyRole(viewDataPointsRole.getRole()), dpPermDef);
});
// create a data point that only superadmin can view
point = (DataPointVO) this.createMockDataPoints(1).get(0);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class DataPointServiceTest method testAddEditRoleUserDoesNotHave.
/**
* There will be 2 validation messages about this, must retain permission AND cannot add/remove a role you do not have
*/
@Override
@Test
public void testAddEditRoleUserDoesNotHave() {
validation.expectValidationException(getEditPermissionContextKey());
DataPointVO vo = newVO(editUser);
setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
vo.setSetPermission(MangoPermission.requireAnyRole(roleService.getUserRole()));
setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
service.insert(vo);
runAs.runAs(readUser, () -> {
DataPointVO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
setEditPermission(MangoPermission.superadminOnly(), fromDb);
service.update(fromDb.getId(), fromDb);
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class DataPointQueryPermissionTest method testDeleteSingleRoleFromAndSet.
/**
* Delete a single role from an and set (this results in the user still having permission)
*/
@Test
public void testDeleteSingleRoleFromAndSet() {
// Insert some data points
Set<Role> readRoles = this.createRoles(3).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());
Role role = readRoles.iterator().next();
Common.getBean(RoleDao.class).delete(role.getId());
readRoles.remove(role);
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 DataPointQueryPermissionTest method testOrPermission.
@Test
public void testOrPermission() {
// 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.requireAnyRole(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));
}
});
}
Aggregations