Search in sources :

Example 6 with IdmFormProjectionDto

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;
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) ArrayList(java.util.ArrayList) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)

Example 7 with IdmFormProjectionDto

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);
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 8 with IdmFormProjectionDto

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();
    }
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with IdmFormProjectionDto

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();
    }
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmFormProjectionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormProjectionService) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 10 with IdmFormProjectionDto

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());
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)36 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)30 Test (org.junit.Test)21 IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)17 Transactional (org.springframework.transaction.annotation.Transactional)16 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)13 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)12 IdentityProjectionEvent (eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent)12 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)12 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)10 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)8 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)6 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)6 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 UUID (java.util.UUID)4 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)3