use of eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeService method removeAutomaticRoles.
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void removeAutomaticRoles(UUID contractId, Set<AbstractIdmAutomaticRoleDto> automaticRoles) {
for (AbstractIdmAutomaticRoleDto autoRole : automaticRoles) {
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(contractId);
identityRoleFilter.setAutomaticRoleId(autoRole.getId());
// TODO: possible performance update with pageable
for (IdmIdentityRoleDto identityRole : identityRoleService.find(identityRoleFilter, null).getContent()) {
// skip check granted authorities
IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.DELETE, identityRole);
event.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
identityRoleService.publish(event);
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleTreeNodeService method addAutomaticRoles.
@Override
@Transactional
public void addAutomaticRoles(IdmIdentityContractDto contract, Set<IdmRoleTreeNodeDto> automaticRoles) {
// original method assignAutomaticRoles has also only @Transactional without reguired new
for (AbstractIdmAutomaticRoleDto autoRole : automaticRoles) {
// create identity role directly
IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
identityRole.setRoleTreeNode(autoRole.getId());
identityRole.setIdentityContract(contract.getId());
identityRole.setRole(autoRole.getRole());
identityRole.setValidFrom(contract.getValidFrom());
identityRole.setValidTill(contract.getValidTill());
//
// start event with skip check authorities
IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.CREATE, identityRole);
event.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
identityRoleService.publish(event);
}
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testDisabledContract.
@Test
public void testDisabledContract() {
IdmIdentityDto identity = testHelper.createIdentity();
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
IdmIdentityContractDto contract2 = testHelper.createIdentityContact(identity, null, new LocalDate().minusMonths(5), new LocalDate().plusMonths(5));
contract2.setState(ContractState.DISABLED);
contract2 = identityContractService.save(contract2);
//
IdmIdentityContractDto contract3 = testHelper.createIdentityContact(identity, null, null, new LocalDate().plusMonths(5));
contract3.setState(ContractState.DISABLED);
contract3 = identityContractService.save(contract3);
//
IdmIdentityContractDto contract4 = testHelper.createIdentityContact(identity, null, null, null);
contract4.setState(ContractState.DISABLED);
contract4 = identityContractService.save(contract4);
//
IdmIdentityContractDto contract5 = testHelper.createIdentityContact(identity, null, new LocalDate().minusMonths(5), null);
contract5.setState(ContractState.DISABLED);
contract5 = identityContractService.save(contract5);
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, identity.getUsername());
//
this.recalculateSync(automaticRole.getId());
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
identityRoles = identityRoleService.findAllByContract(contract2.getId());
assertEquals(0, identityRoles.size());
//
identityRoles = identityRoleService.findAllByContract(contract3.getId());
assertEquals(0, identityRoles.size());
//
identityRoles = identityRoleService.findAllByContract(contract4.getId());
assertEquals(0, identityRoles.size());
//
identityRoles = identityRoleService.findAllByContract(contract5.getId());
assertEquals(0, identityRoles.size());
//
contract5.setState(null);
contract5 = identityContractService.save(contract5);
// we must save identity, automatic role will be recalculate after identity save
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByContract(contract5.getId());
assertEquals(1, identityRoles.size());
//
contract4.setState(null);
contract4 = identityContractService.save(contract4);
// we must save identity, automatic role will be recalculate after identity save
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByContract(contract4.getId());
assertEquals(1, identityRoles.size());
//
contract3.setState(null);
contract3 = identityContractService.save(contract3);
// we must save identity, automatic role will be recalculate after identity save
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByContract(contract3.getId());
assertEquals(1, identityRoles.size());
//
contract2.setState(null);
contract2 = identityContractService.save(contract2);
// we must save identity, automatic role will be recalculate after identity save
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByContract(contract2.getId());
assertEquals(1, identityRoles.size());
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
for (IdmIdentityRoleDto identityRole : identityRoles) {
assertEquals(automaticRole.getId(), identityRole.getRoleTreeNode());
AbstractIdmAutomaticRoleDto embedded = DtoUtils.getEmbedded(identityRole, IdmAutomaticRoleAttributeService.ROLE_TREE_NODE_ATTRIBUTE_NAME, AbstractIdmAutomaticRoleDto.class, null);
assertEquals(automaticRole, embedded);
assertEquals(role.getId(), embedded.getRole());
assertEquals(role.getId(), identityRole.getRole());
}
//
contract3.setState(ContractState.DISABLED);
contract3 = identityContractService.save(contract3);
// we must save identity, automatic role will be recalculate after identity save
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByContract(contract3.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto in project CzechIdMng by bcvsolutions.
the class IdentityContractAutomaticRoleProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto identityContract = event.getContent();
UUID contractId = identityContract.getId();
//
// both by default - contract can be saved together with identity => we need to recalculate all rules
AutomaticRoleAttributeRuleType type = null;
// just contract eav save
if (CoreEventType.EAV_SAVE.name().equals(event.getParentType())) {
type = AutomaticRoleAttributeRuleType.CONTRACT_EAV;
}
//
// resolve automatic role by attribute
Set<AbstractIdmAutomaticRoleDto> allNewPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(true, type, contractId);
Set<AbstractIdmAutomaticRoleDto> allNotPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(false, type, contractId);
// we don't know precious size - guava is used instead simple ArrayList constructor
List<IdmConceptRoleRequestDto> concepts = Lists.newArrayListWithExpectedSize(allNewPassedAutomaticRoleForContract.size() + allNotPassedAutomaticRoleForContract.size());
// Iterate over newly passed
for (AbstractIdmAutomaticRoleDto autoRole : allNewPassedAutomaticRoleForContract) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contractId);
concept.setValidFrom(identityContract.getValidFrom());
concept.setValidTill(identityContract.getValidTill());
concept.setRole(autoRole.getRole());
concept.setAutomaticRole(autoRole.getId());
concept.setOperation(ConceptRoleRequestOperation.ADD);
concepts.add(concept);
}
// Iterate over newly not passed
for (AbstractIdmAutomaticRoleDto autoRole : allNotPassedAutomaticRoleForContract) {
// Find all identity roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setAutomaticRoleId(autoRole.getId());
filter.setIdentityContractId(contractId);
;
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
//
for (IdmIdentityRoleDto identityRole : identityRoles) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contractId);
concept.setRole(autoRole.getRole());
concept.setAutomaticRole(autoRole.getId());
concept.setIdentityRole(identityRole.getId());
concept.setOperation(ConceptRoleRequestOperation.REMOVE);
concepts.add(concept);
}
}
//
// Execute concepts
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(identityContract.getIdentity());
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), event);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleTreeNodeService method createIdentityRole.
/**
* Method create identity role and start event with create
* the identity role and skip check authorities.
*
* @param contract
* @param automaticRoles
*/
private void createIdentityRole(IdmIdentityContractDto contract, IdmContractPositionDto contractPosition, Set<IdmRoleTreeNodeDto> automaticRoles) {
for (AbstractIdmAutomaticRoleDto autoRole : automaticRoles) {
// create identity role directly
IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
identityRole.setAutomaticRole(autoRole.getId());
identityRole.setIdentityContract(contract.getId());
identityRole.setContractPosition(contractPosition == null ? null : contractPosition.getId());
identityRole.setRole(autoRole.getRole());
identityRole.setValidFrom(contract.getValidFrom());
identityRole.setValidTill(contract.getValidTill());
//
// start event with skip check authorities
IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.CREATE, identityRole);
event.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
identityRoleService.publish(event);
}
}
Aggregations