use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionService method removeSubRoles.
@Override
@Transactional
public void removeSubRoles(EntityEvent<IdmIdentityRoleDto> event, BasePermission... permission) {
Assert.notNull(event, "Event is required.");
IdmIdentityRoleDto directRole = event.getContent();
Assert.notNull(directRole, "Direct role is required.");
Assert.notNull(directRole.getId(), "Direct role identifier is required.");
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setDirectRoleId(directRole.getId());
//
identityRoleService.find(filter, null).forEach(subIdentityRole -> {
IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.DELETE, subIdentityRole);
//
identityRoleService.publish(subEvent, event, permission);
// Notes identity-accounts to ACM
notingIdentityAccountForDelayedAcm(event, subEvent);
});
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionService method assignSubRoles.
/**
* @Transactional is not needed - (asynchronous) events is thrown for every sub role anyway ...
* Can be called repetitively for given identity role => checks or creates missing sub roles by composition.
*/
@Override
@SuppressWarnings("unchecked")
public void assignSubRoles(EntityEvent<IdmIdentityRoleDto> event, UUID roleCompositionId, BasePermission... permission) {
Assert.notNull(event, "Event is required.");
IdmIdentityRoleDto identityRole = event.getContent();
Assert.notNull(identityRole, "Identity role identifier is required.");
// find direct sub roles
IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
compositionFilter.setSuperiorId(identityRole.getRole());
compositionFilter.setId(roleCompositionId);
//
List<IdmRoleCompositionDto> directSubRoles = find(compositionFilter, null, permission).getContent();
LOG.debug("Assign sub roles [{}] for identity role [{}], role [{}]", directSubRoles.size(), identityRole.getId(), identityRole.getRole());
//
Map<String, Serializable> props = resolveProperties(event);
Set<UUID> processedRoles = (Set<UUID>) props.get(IdentityRoleEvent.PROPERTY_PROCESSED_ROLES);
processedRoles.add(identityRole.getRole());
//
directSubRoles.forEach(subRoleComposition -> {
IdmRoleDto subRole = DtoUtils.getEmbedded(subRoleComposition, IdmRoleComposition_.sub);
if (processedRoles.contains(subRole.getId())) {
LOG.debug("Role [{}] was already processed by other business role composition - cycle, skipping", subRole.getCode());
} else {
// try to find currently assigned subrole by this configuration (return operation)
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleCompositionId(subRoleComposition.getId());
filter.setDirectRoleId(identityRole.getDirectRole() == null ? identityRole.getId() : identityRole.getDirectRole());
if (identityRoleService.find(filter, null).getTotalElements() > 0) {
LOG.debug("Role [{}] was already processed by other business role composition - cycle, skipping", subRole.getCode());
} else {
//
IdmIdentityRoleDto subIdentityRole = new IdmIdentityRoleDto();
subIdentityRole.setRole(subRole.getId());
subIdentityRole.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_ROLE, subRole);
subIdentityRole.setIdentityContract(identityRole.getIdentityContract());
subIdentityRole.setContractPosition(identityRole.getContractPosition());
subIdentityRole.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT, identityRole.getEmbedded().get(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT));
subIdentityRole.setValidFrom(identityRole.getValidFrom());
subIdentityRole.setValidTill(identityRole.getValidTill());
subIdentityRole.setDirectRole(identityRole.getDirectRole() == null ? identityRole.getId() : identityRole.getDirectRole());
subIdentityRole.setRoleComposition(subRoleComposition.getId());
//
processedRoles.add(subRole.getId());
IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.CREATE, subIdentityRole, props);
//
identityRoleService.publish(subEvent, event, permission);
// Notes new created assigned role to parent event
IdmIdentityRoleDto subContent = subEvent.getContent();
notingAssignedRole(event, subEvent, subContent, IdentityRoleEvent.PROPERTY_ASSIGNED_NEW_ROLES);
}
}
});
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionService method updateSubRoles.
@Override
@Transactional
public void updateSubRoles(EntityEvent<IdmIdentityRoleDto> event, BasePermission... permission) {
Assert.notNull(event, "Event is required.");
IdmIdentityRoleDto identityRole = event.getContent();
Assert.notNull(identityRole, "Identity role identifier is required.");
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setDirectRoleId(identityRole.getId());
//
identityRoleService.find(filter, null).forEach(subIdentityRole -> {
subIdentityRole.setIdentityContract(identityRole.getIdentityContract());
subIdentityRole.setContractPosition(identityRole.getContractPosition());
subIdentityRole.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT, identityRole.getEmbedded().get(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT));
subIdentityRole.setValidFrom(identityRole.getValidFrom());
subIdentityRole.setValidTill(identityRole.getValidTill());
//
IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.UPDATE, subIdentityRole);
//
identityRoleService.publish(subEvent, event, permission);
// Notes updated assigned role to parent event
IdmIdentityRoleDto subContent = subEvent.getContent();
notingAssignedRole(event, subEvent, subContent, IdentityRoleEvent.PROPERTY_ASSIGNED_UPDATED_ROLES);
});
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityRoleByRoleCatalogueCodeFilterIntegrationTest method testOneResult.
@Test
public void testOneResult() {
IdmRoleDto role = getHelper().createRole();
IdmRoleCatalogueDto roleCatalogue = getHelper().createRoleCatalogue();
getHelper().createRoleCatalogueRole(role, roleCatalogue);
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityRoleDto createIdentityRole = getHelper().createIdentityRole(identity, role);
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.set(IdentityRoleByRoleCatalogueCodeFilter.PARAMETER_ROLE_CATALOGUE_CODE, roleCatalogue.getCode());
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter(params);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
Assert.assertFalse(identityRoles.isEmpty());
Assert.assertEquals(1, identityRoles.size());
IdmIdentityRoleDto foundedIdentityRole = identityRoles.get(0);
Assert.assertEquals(createIdentityRole.getId(), foundedIdentityRole.getId());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityRoleExpirationTaskExecutorIntegrationTest method testExpiredBusinessRole.
@Test
public void testExpiredBusinessRole() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
//
// normal and business role
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleRoot = getHelper().createRole();
IdmRoleDto roleSub = getHelper().createRole();
getHelper().createRoleComposition(roleRoot, roleSub);
//
// assign roles
IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, roleRoot);
IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contract, roleOne);
//
// expire contract
assignedRoleOne.setValidTill(LocalDate.now().minusDays(2));
assignedRoleOne = identityRoleService.save(assignedRoleOne);
assignedRoleTwo.setValidTill(LocalDate.now().minusDays(2));
assignedRoleTwo = identityRoleService.save(assignedRoleTwo);
//
// test after create before lrt is executed
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityContractId(contract.getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(filter, null).getContent();
//
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleRoot.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleSub.getId())));
Assert.assertTrue(assignedRoles.stream().allMatch(ir -> !ir.isValid()));
//
IdentityRoleExpirationTaskExecutor lrt = new IdentityRoleExpirationTaskExecutor();
lrt.init(null);
lrtManager.executeSync(lrt);
//
assignedRoles = identityRoleService.find(filter, null).getContent();
//
Assert.assertTrue(assignedRoles.isEmpty());
}
Aggregations