use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindByRoleText.
@Test
public void testFindByRoleText() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmIdentityRoleDto createIdentityRole = getHelper().createIdentityRole(identity, roleOne);
getHelper().createIdentityRole(identity, roleTwo);
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleText(roleOne.getCode());
List<IdmIdentityRoleDto> results = find(filter);
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(createIdentityRole.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindValidRoles.
@Test
public void testFindValidRoles() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
// valid
IdmIdentityRoleDto validRole = getHelper().createIdentityRole(identity, getHelper().createRole());
// inValidByDate
getHelper().createIdentityRole(identity, getHelper().createRole(), null, LocalDate.now().minusDays(2));
IdmIdentityContractDto invalidContract = getHelper().createContract(identity, null, null, LocalDate.now().minusDays(2));
// inValidByContract
getHelper().createIdentityRole(invalidContract, getHelper().createRole());
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
filter.setValid(Boolean.TRUE);
List<IdmIdentityRoleDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(validRole.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindByRoleEnvironment.
@Test
public void testFindByRoleEnvironment() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmRoleDto roleOne = getHelper().createRole(null, getHelper().createName(), getHelper().createName());
IdmRoleDto roleTwo = getHelper().createRole(null, getHelper().createName(), getHelper().createName());
IdmIdentityRoleDto createIdentityRole = getHelper().createIdentityRole(identity, roleOne);
getHelper().createIdentityRole(identity, roleTwo);
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleEnvironment(roleOne.getEnvironment());
List<IdmIdentityRoleDto> results = find(filter);
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(createIdentityRole.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindAutomaticRoles.
@Test
public void testFindAutomaticRoles() {
IdmIdentityContractDto contract = getHelper().getPrimeContract(getHelper().createIdentity().getId());
// normal
IdmIdentityRoleDto normal = getHelper().createIdentityRole(contract, getHelper().createRole());
// automatic
IdmIdentityRoleDto automaticIdentityRole = new IdmIdentityRoleDto();
automaticIdentityRole.setIdentityContract(contract.getId());
IdmRoleDto role = getHelper().createRole();
automaticIdentityRole.setRole(role.getId());
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
automaticIdentityRole.setAutomaticRole(automaticRole.getId());
IdmIdentityRoleDto automatic = createDto(automaticIdentityRole);
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityContractId(contract.getId());
filter.setAutomaticRole(Boolean.TRUE);
List<IdmIdentityRoleDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(automatic.getId())));
//
filter.setAutomaticRole(Boolean.FALSE);
results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(normal.getId())));
//
// find by automatic role
filter.setAutomaticRole(null);
filter.setAutomaticRoleId(automaticRole.getId());
results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(automatic.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindCanBeRequestedRoles.
@Test
public void testFindCanBeRequestedRoles() throws Exception {
String defaultRoleCode = roleConfiguration.getDefaultRoleCode();
//
try {
// empty property => disable default role
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, "");
IdmRoleDto roleOne = createRole(true);
// other
IdmRoleDto roleTwo = createRole(false);
//
IdmIdentityDto identity = getHelper().createIdentity();
IdmRoleDto assignedRole = getHelper().createRole();
//
getHelper().createIdentityRole(identity, assignedRole);
//
// other identity - their identity roles we will read
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
getHelper().createIdentityRole(identityTwo, roleOne);
getHelper().createIdentityRole(identityTwo, roleTwo);
//
// create authorization policy - assign to role
getHelper().createAuthorizationPolicy(assignedRole.getId(), CoreGroupPermission.ROLE, IdmRole.class, RoleCanBeRequestedEvaluator.class, RoleBasePermission.CANBEREQUESTED, IdmBasePermission.UPDATE, IdmBasePermission.READ);
// with update transitively
ConfigurationMap evaluatorProperties = new ConfigurationMap();
evaluatorProperties.put(IdentityRoleByRoleEvaluator.PARAMETER_CAN_BE_REQUESTED_ONLY, false);
IdmAuthorizationPolicyDto transientIdentityRolePolicy = getHelper().createAuthorizationPolicy(assignedRole.getId(), CoreGroupPermission.IDENTITYROLE, IdmIdentityRole.class, IdentityRoleByRoleEvaluator.class, evaluatorProperties);
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identityTwo.getId());
List<IdmIdentityRoleDto> identityRoles = find("can-be-requested", filter, getAuthentication(identity.getUsername()));
//
Assert.assertFalse(identityRoles.isEmpty());
Assert.assertEquals(1, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(r -> r.getRole().equals(roleOne.getId())));
//
List<String> permissions = getPermissions(identityRoles.get(0), getAuthentication(identity.getUsername()));
//
Assert.assertEquals(3, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(RoleBasePermission.CANBEREQUESTED.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
//
// can be requested only
evaluatorProperties = new ConfigurationMap();
evaluatorProperties.put(IdentityRoleByRoleEvaluator.PARAMETER_CAN_BE_REQUESTED_ONLY, true);
transientIdentityRolePolicy.setEvaluatorProperties(evaluatorProperties);
authorizationPolicyService.save(transientIdentityRolePolicy);
//
identityRoles = find("can-be-requested", filter, getAuthentication(identity.getUsername()));
//
Assert.assertFalse(identityRoles.isEmpty());
Assert.assertEquals(1, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(r -> r.getRole().equals(roleOne.getId())));
// read authority is not available now
try {
getHelper().login(identity);
//
Set<String> canBeRequestedPermissions = identityRoleService.getPermissions(identityRoles.get(0).getId());
//
Assert.assertEquals(1, canBeRequestedPermissions.size());
Assert.assertTrue(canBeRequestedPermissions.stream().anyMatch(p -> p.equals(RoleBasePermission.CANBEREQUESTED.name())));
} finally {
logout();
}
} finally {
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRoleCode);
}
}
Aggregations