use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method saveOtherContracts.
protected List<IdmIdentityContractDto> saveOtherContracts(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
IdmIdentityProjectionDto dto = event.getContent();
IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
List<IdmIdentityContractDto> savedContracts = new ArrayList<>(dto.getOtherContracts().size());
//
// check all contracts has to be saved
IdmIdentityDto identity = dto.getIdentity();
if (identity.getFormProjection() != null) {
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
if (!formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS)) {
LOG.debug("Projection [{}] doesn't save other contracts.", formProjection.getCode());
return savedContracts;
}
}
//
for (IdmIdentityContractDto contract : dto.getOtherContracts()) {
IdentityContractEventType contractEventType = IdentityContractEventType.CREATE;
if (!contractService.isNew(contract)) {
contractEventType = IdentityContractEventType.UPDATE;
// TODO: validation - identity cannot be changed
} else {
contract.setIdentity(dto.getIdentity().getId());
}
IdentityContractEvent otherContractEvent = new IdentityContractEvent(contractEventType, contract);
//
savedContracts.add(contractService.publish(otherContractEvent, event, permission).getContent());
if (previousProjection != null) {
previousProjection.getOtherContracts().removeIf(c -> {
return Objects.equals(c.getId(), contract.getId());
});
}
}
// remove not sent contracts, if previous exists
if (previousProjection != null) {
boolean primeContractChanged = false;
//
for (IdmIdentityContractDto contract : previousProjection.getOtherContracts()) {
if (Objects.equals(dto.getContract(), contract)) {
// new prime contract is saved all time
primeContractChanged = true;
continue;
}
//
deleteContract(event, contract, permission);
}
// delete previous prime contract, if order of contracts changed
if (primeContractChanged && !savedContracts.contains(previousProjection.getContract())) {
deleteContract(event, previousProjection.getContract(), permission);
}
}
//
return savedContracts;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class FormProjectionSaveProcessor method process.
@Override
public EventResult<IdmFormProjectionDto> process(EntityEvent<IdmFormProjectionDto> event) {
IdmFormProjectionDto entity = event.getContent();
entity = service.saveInternal(entity);
event.setContent(entity);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityServiceIntegrationTest method testChangeProjectionWithoutChangePermission.
@Transactional
@Test(expected = ForbiddenEntityException.class)
public void testChangeProjectionWithoutChangePermission() {
//
IdmIdentityDto identity = getHelper().createIdentity();
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setCode(getHelper().createName());
projection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
projection = projectionService.save(projection);
//
IdmRoleDto role = getHelper().createRole();
getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.UPDATE);
getHelper().createIdentityRole(identity, role);
//
try {
getHelper().login(identity);
identity.setFormProjection(projection.getId());
identityService.save(identity, IdmBasePermission.UPDATE);
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class IdentityByFormProjectionEvaluatorIntegrationTest method testPolicy.
@Test
public void testPolicy() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityDto identityOther = getHelper().createIdentity();
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setCode(getHelper().createName());
projection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
projection = projectionService.save(projection);
identity.setFormProjection(projection.getId());
IdmIdentityDto identityOne = identityService.save(identity);
IdmRoleDto role = getHelper().createRole();
getHelper().createIdentityRole(identity, role);
//
List<IdmIdentityDto> identities = null;
// check created identity doesn't have compositions
try {
getHelper().login(identity.getUsername(), identity.getPassword());
identities = identityService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(identities.isEmpty());
} finally {
logout();
}
//
// create authorization policy - assign to role
ConfigurationMap properties = new ConfigurationMap();
properties.put(IdentityByFormProjectionEvaluator.PARAMETER_FORM_PROJECTION, projection.getId());
IdmAuthorizationPolicyDto authorizationPolicy = getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdentityByFormProjectionEvaluator.class, properties, IdmBasePermission.READ);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
// evaluate access
identities = identityService.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, identities.size());
Assert.assertEquals(identityOne.getId(), identities.get(0).getId());
//
Set<String> permissions = identityService.getPermissions(identityOne);
Assert.assertEquals(1, permissions.size());
Assert.assertEquals(IdmBasePermission.READ.name(), permissions.iterator().next());
} finally {
logout();
}
//
// default user type
authorizationPolicyService.delete(authorizationPolicy);
getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdentityByFormProjectionEvaluator.class, IdmBasePermission.READ);
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
// evaluate access
identities = identityService.find(null, IdmBasePermission.READ).getContent();
Assert.assertFalse(identities.isEmpty());
Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityOther.getId())));
Assert.assertTrue(identities.stream().allMatch(i -> !i.getId().equals(identityOne.getId())));
//
Set<String> permissions = identityService.getPermissions(identityOther);
Assert.assertEquals(1, permissions.size());
Assert.assertEquals(IdmBasePermission.READ.name(), permissions.iterator().next());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateBasicFields.
@Test
@Transactional
public void testValidateBasicFields() throws Exception {
// prepare projection
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
IdmFormAttributeDto attributeExternalCode = new IdmFormAttributeDto();
attributeExternalCode.setId(UUID.randomUUID());
attributeExternalCode.setCode(IdmIdentity_.externalCode.getName());
attributeExternalCode.setName(String.format("%s.%s", IdmIdentity.class.getSimpleName(), IdmIdentity_.externalCode.getName()));
attributeExternalCode.setRequired(true);
IdmFormAttributeDto attributeLastName = new IdmFormAttributeDto();
attributeLastName.setId(UUID.randomUUID());
attributeLastName.setCode(IdmIdentity_.lastName.getName());
attributeLastName.setMax(BigDecimal.valueOf(3));
IdmFormAttributeDto attributeValidTill = new IdmFormAttributeDto();
attributeValidTill.setId(UUID.randomUUID());
attributeValidTill.setCode(IdmIdentityContract_.validTill.getName());
attributeValidTill.setName(String.format("%s.%s", IdmIdentityContract.class.getSimpleName(), IdmIdentityContract_.validTill.getName()));
attributeValidTill.setRequired(true);
attributeValidTill.setMax(BigDecimal.valueOf(3));
IdmFormAttributeDto attributeWorkPosition = new IdmFormAttributeDto();
attributeWorkPosition.setId(UUID.randomUUID());
attributeWorkPosition.setCode(IdmIdentityContract_.workPosition.getName());
attributeWorkPosition.setName(String.format("%s.%s", IdmIdentityContract.class.getSimpleName(), IdmIdentityContract_.workPosition.getName()));
attributeWorkPosition.setRequired(true);
formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attributeExternalCode, attributeLastName, attributeValidTill, attributeWorkPosition)));
formProjection = projectionService.save(formProjection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setExternalCode(getHelper().createName());
identity.setLastName("xxx");
identity.setFormProjection(formProjection.getId());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// set contract
IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
primeContract.setMain(true);
primeContract.setWorkPosition(getHelper().createTreeNode().getId());
primeContract.setPosition(getHelper().createName());
primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
primeContract.setValidTill(LocalDate.now().plus(3l, ChronoUnit.DAYS));
projection.setContract(primeContract);
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
projection = manager.publish(identityProjectionEvent).getContent();
IdmIdentityProjectionDto createdProjection = manager.get(projection);
//
Assert.assertNotNull(createdProjection);
Assert.assertNotNull(createdProjection.getId());
Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
//
// prime contract
IdmIdentityContractDto createdPrimeContract = createdProjection.getContract();
Assert.assertEquals(primeContract.getWorkPosition(), createdPrimeContract.getWorkPosition());
Assert.assertEquals(primeContract.getPosition(), createdPrimeContract.getPosition());
Assert.assertEquals(primeContract.getValidFrom(), createdPrimeContract.getValidFrom());
Assert.assertEquals(primeContract.getValidTill(), createdPrimeContract.getValidTill());
Assert.assertEquals(createdProjection.getIdentity().getId(), createdPrimeContract.getIdentity());
}
Aggregations