Search in sources :

Example 36 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cantCreateUserYouCantRead.

@Test
@ExpectValidationException("readPermission")
public void cantCreateUserYouCantRead() {
    Role createRole = createUsersRole();
    User createUser = insertUser(editRole, createRole);
    // noinspection Convert2MethodRef
    runAs.runAs(createUser, () -> insertUser());
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 37 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method testDeleteRoleUpdateVO.

@Test
@Override
public void testDeleteRoleUpdateVO() {
    User vo = newVO(readUser);
    vo.setRoles(Collections.singleton(readRole));
    service.insert(vo);
    User fromDb = service.get(vo.getId());
    assertVoEqual(vo, fromDb);
    roleService.delete(readRole.getId());
    // Remove the read role from the local copy
    Set<Role> roles = new HashSet<>(fromDb.getRoles());
    roles.remove(readRole);
    fromDb.setRoles(roles);
    // Check database
    User updated = service.get(fromDb.getId());
    assertVoEqual(fromDb, updated);
    // Check cache
    updated = service.get(fromDb.getUsername());
    assertVoEqual(fromDb, updated);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method canChangePermissionsOfSelfWithExplicitPermission.

@Test
public void canChangePermissionsOfSelfWithExplicitPermission() {
    Role otherRole = createRole(randomXid(), "Some other role").getRole();
    User vo = insertUser(editRole, readRole, otherRole);
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setReadPermission(MangoPermission.requireAnyRole(otherRole));
        self.setEditPermission(MangoPermission.requireAnyRole(otherRole));
        service.update(self.getId(), self);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test)

Example 39 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cantAddAdditionalRolesWhenCreating.

@Test
@ExpectValidationException("roles")
public void cantAddAdditionalRolesWhenCreating() {
    Role roleToAdd = createRole(randomXid(), "Some other role").getRole();
    Role createRole = createUsersRole();
    User createUser = insertUser(createRole, editRole, readRole);
    runAs.runAs(createUser, () -> {
        insertUser(roleToAdd);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 40 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cannotAllowAccessToRoleWeDontHold.

@Test
@ExpectValidationException({ "readPermission", "editPermission" })
public void cannotAllowAccessToRoleWeDontHold() {
    Role otherRole = createRole(randomXid(), "Some other role").getRole();
    User otherUser = insertUser();
    User user = insertUser(editRole, readRole);
    runAs.runAs(user, () -> {
        otherUser.setReadPermission(MangoPermission.requireAnyRole(readRole, otherRole));
        otherUser.setEditPermission(MangoPermission.requireAnyRole(editRole, otherRole));
        service.update(otherUser.getId(), otherUser);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Aggregations

Role (com.serotonin.m2m2.vo.role.Role)102 Test (org.junit.Test)59 HashSet (java.util.HashSet)40 Set (java.util.Set)38 User (com.serotonin.m2m2.vo.User)33 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)23 RoleVO (com.serotonin.m2m2.vo.role.RoleVO)22 Collectors (java.util.stream.Collectors)18 Common (com.serotonin.m2m2.Common)17 MangoTestBase (com.serotonin.m2m2.MangoTestBase)15 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)15 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)15 List (java.util.List)15 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)14 Assert.assertEquals (org.junit.Assert.assertEquals)14 Assert.assertTrue (org.junit.Assert.assertTrue)14 DataPointService (com.infiniteautomation.mango.spring.service.DataPointService)12 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)12 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)11 DSLContext (org.jooq.DSLContext)11