Search in sources :

Example 1 with AbstractEntity_

use of eu.bcvsolutions.idm.core.api.entity.AbstractEntity_ in project CzechIdMng by bcvsolutions.

the class ProvisioningMergeTest method testSkipMergeValueIfContractExcluded.

@Test
public void testSkipMergeValueIfContractExcluded() {
    SysSystemDto system = helper.createSystem("test_resource");
    SysSystemMappingDto mapping = helper.createMapping(system);
    IdmRoleDto roleOne = helper.createRole();
    IdmRoleDto roleTwo = helper.createRole();
    SysRoleSystemDto roleSystemOne = helper.createRoleSystem(roleOne, system);
    SysRoleSystemDto roleSystemTwo = helper.createRoleSystem(roleTwo, system);
    SysSchemaAttributeDto rightsSchemaAttribute = new SysSchemaAttributeDto();
    rightsSchemaAttribute.setObjectClass(mapping.getObjectClass());
    rightsSchemaAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsSchemaAttribute.setMultivalued(true);
    rightsSchemaAttribute.setClassType(String.class.getName());
    rightsSchemaAttribute.setReadable(true);
    rightsSchemaAttribute.setUpdateable(true);
    rightsSchemaAttribute = schemaAttributeService.save(rightsSchemaAttribute);
    SysSystemAttributeMappingDto rightsAttribute = new SysSystemAttributeMappingDto();
    rightsAttribute.setSchemaAttribute(rightsSchemaAttribute.getId());
    rightsAttribute.setSystemMapping(mapping.getId());
    rightsAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsAttribute.setStrategyType(AttributeMappingStrategyType.MERGE);
    rightsAttribute = attributeMappingService.save(rightsAttribute);
    SysRoleSystemAttributeDto roleAttributeOne = new SysRoleSystemAttributeDto();
    roleAttributeOne.setName(RIGHTS_ATTRIBUTE);
    roleAttributeOne.setEntityAttribute(false);
    roleAttributeOne.setExtendedAttribute(false);
    roleAttributeOne.setRoleSystem(roleSystemOne.getId());
    roleAttributeOne.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeOne.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    List<Serializable> controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    SysRoleSystemAttributeDto roleAttributeTwo = new SysRoleSystemAttributeDto();
    roleAttributeTwo.setName(RIGHTS_ATTRIBUTE);
    roleAttributeTwo.setEntityAttribute(false);
    roleAttributeTwo.setExtendedAttribute(false);
    roleAttributeTwo.setRoleSystem(roleSystemTwo.getId());
    roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeTwo.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "';");
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(2, controlledAttributeValues.size());
    assertTrue(controlledAttributeValues.contains(ONE_VALUE));
    assertTrue(controlledAttributeValues.contains(TWO_VALUE));
    SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
    attributeControlledValueFilter.setAttributeMappingId(rightsAttribute.getId());
    attributeControlledValueFilter.setHistoricValue(Boolean.TRUE);
    List<Serializable> historicControlledValues = // 
    attributeControlledValueService.find(attributeControlledValueFilter, // 
    null).getContent().stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(historicControlledValues);
    assertEquals(0, historicControlledValues.size());
    IdmIdentityDto identity = this.getHelper().createIdentity();
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    // Set contract as excluded
    contract.setState(ContractState.EXCLUDED);
    contract = identityContractService.save(contract);
    assertTrue(contract.isExcluded());
    this.getHelper().createIdentityRole(identity, roleOne);
    this.getHelper().createIdentityRole(identity, roleTwo);
    SysProvisioningOperationFilter operationFilter = new SysProvisioningOperationFilter();
    operationFilter.setEntityIdentifier(identity.getId());
    List<SysProvisioningArchiveDto> archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    SysProvisioningArchiveDto archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    ProvisioningContext provisioningContext = archive.getProvisioningContext();
    Map<ProvisioningAttributeDto, Object> accountObject = provisioningContext.getAccountObject();
    Entry<ProvisioningAttributeDto, Object> attributeEntry = accountObject.entrySet().stream().filter(entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    List<?> values = (List<?>) attributeEntry.getValue();
    assertEquals(2, values.size());
    // Set attribute TWO to skip value if contract is excluded
    roleAttributeTwo.setSkipValueIfExcluded(true);
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    // Save identity -> execute provisioning
    identityService.save(identity);
    archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    provisioningContext = archive.getProvisioningContext();
    accountObject = provisioningContext.getAccountObject();
    attributeEntry = // 
    accountObject.entrySet().stream().filter(// 
    entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    values = (List<?>) attributeEntry.getValue();
    assertEquals(1, values.size());
    assertEquals(ONE_VALUE, values.get(0));
    // Set contract as not excluded
    contract.setState(null);
    contract = identityContractService.save(contract);
    assertFalse(contract.isExcluded());
    // Save identity -> execute provisioning
    identityService.save(identity);
    archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    provisioningContext = archive.getProvisioningContext();
    accountObject = provisioningContext.getAccountObject();
    attributeEntry = // 
    accountObject.entrySet().stream().filter(// 
    entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    values = (List<?>) attributeEntry.getValue();
    assertEquals(2, values.size());
}
Also used : AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) Autowired(org.springframework.beans.factory.annotation.Autowired) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) Map(java.util.Map) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) AbstractEntity_(eu.bcvsolutions.idm.core.api.entity.AbstractEntity_) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) SysAttributeControlledValueService(eu.bcvsolutions.idm.acc.service.api.SysAttributeControlledValueService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) PageRequest(org.springframework.data.domain.PageRequest) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) Test(org.junit.Test) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Assert.assertFalse(org.junit.Assert.assertFalse) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) Entry(java.util.Map.Entry) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) Sort(org.springframework.data.domain.Sort) List(java.util.List) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with AbstractEntity_

use of eu.bcvsolutions.idm.core.api.entity.AbstractEntity_ in project CzechIdMng by bcvsolutions.

the class DefaultLongPollingManager method baseCheckDeferredResult.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void baseCheckDeferredResult(DeferredResult<OperationResultDto> deferredResult, LongPollingSubscriber subscriber, ModifiedFromFilter filter, ReadDtoService service, boolean checkCount) {
    Assert.notNull(deferredResult, "Deferred result is required to check.");
    Assert.notNull(subscriber.getEntityId(), "Subscriber is required to check deferred result.");
    LOG.debug("Start baseCheckDeferredResult for deferred-result [{}] and subscriber [{}]", deferredResult, subscriber);
    if (checkCount) {
        long countOfentities = service.count(filter);
        Long lastNumberOfEntities = subscriber.getLastNumberOfEntities();
        subscriber.setLastNumberOfEntities(countOfentities);
        if (lastNumberOfEntities != null && countOfentities != lastNumberOfEntities) {
            // Notify FE -> Some of an entities were changed (refresh must be executed)
            deferredResult.setResult(new OperationResultDto(OperationState.RUNNING));
            return;
        }
    }
    ZonedDateTime timeStamp = subscriber.getLastTimeStamp();
    if (timeStamp == null) {
        List<AbstractDto> entities = service.find(filter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName(), AbstractEntity_.modified.getName()))).getContent();
        if (entities.isEmpty()) {
            subscriber.setLastTimeStamp(ZonedDateTime.now());
            return;
        }
        ZonedDateTime lastModified = this.getLastTimeStamp(entities.get(0));
        subscriber.setLastTimeStamp(lastModified);
        return;
    }
    // Try to find, if some from not finished entities were changed
    // TODO: For search SysSyncLogs the filter by modifiedFrom didn't work properly.
    // I didn't found reason why, but I hope using sort by created and modified fields will be works better.
    // filter.setModifiedFrom(timeStamp);
    List<AbstractDto> changedRequestsFromLastChecks = service.find(filter, PageRequest.of(0, 1, Sort.by(Direction.DESC, AbstractEntity_.created.getName(), AbstractEntity_.modified.getName()))).getContent();
    if (!changedRequestsFromLastChecks.isEmpty()) {
        AbstractDto changedRequestsFromLastCheck = changedRequestsFromLastChecks.get(0);
        ZonedDateTime lastModified = this.getLastTimeStamp(changedRequestsFromLastCheck);
        if (lastModified.isAfter(timeStamp)) {
            // Notify FE -> Some of the entity was changed (refresh must be executed).
            // Notified will be all suspended request for same entity ID!
            this.suspendedRequests.stream().filter(request -> request.getEntityId().equals(subscriber.getEntityId())).forEach(request -> {
                request.getResult().setResult(new OperationResultDto(OperationState.RUNNING));
            });
            subscriber.setLastTimeStamp(lastModified);
            return;
        }
    }
// Nothing was changed
}
Also used : ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) DeferredResult(org.springframework.web.context.request.async.DeferredResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Scheduled(org.springframework.scheduling.annotation.Scheduled) ModifiedFromFilter(eu.bcvsolutions.idm.core.api.dto.filter.ModifiedFromFilter) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) CheckLongPollingResult(eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult) Map(java.util.Map) LongPollingManager(eu.bcvsolutions.idm.core.model.service.api.LongPollingManager) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) DeferredResultWrapper(eu.bcvsolutions.idm.core.rest.DeferredResultWrapper) Logger(org.slf4j.Logger) AbstractEntity_(eu.bcvsolutions.idm.core.api.entity.AbstractEntity_) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PageRequest(org.springframework.data.domain.PageRequest) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) LongPollingSubscriber(eu.bcvsolutions.idm.core.rest.LongPollingSubscriber) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Lazy(org.springframework.context.annotation.Lazy) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Assert(org.springframework.util.Assert) ZonedDateTime(java.time.ZonedDateTime) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) Sort(org.springframework.data.domain.Sort)

Example 3 with AbstractEntity_

use of eu.bcvsolutions.idm.core.api.entity.AbstractEntity_ in project CzechIdMng by bcvsolutions.

the class ProvisioningMergeTest method testSkipAuthoritativeMergeValueIfContractExcluded.

@Test
public void testSkipAuthoritativeMergeValueIfContractExcluded() {
    SysSystemDto system = helper.createSystem("test_resource");
    SysSystemMappingDto mapping = helper.createMapping(system);
    IdmRoleDto roleOne = helper.createRole();
    IdmRoleDto roleTwo = helper.createRole();
    SysRoleSystemDto roleSystemOne = helper.createRoleSystem(roleOne, system);
    SysRoleSystemDto roleSystemTwo = helper.createRoleSystem(roleTwo, system);
    SysSchemaAttributeDto rightsSchemaAttribute = new SysSchemaAttributeDto();
    rightsSchemaAttribute.setObjectClass(mapping.getObjectClass());
    rightsSchemaAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsSchemaAttribute.setMultivalued(true);
    rightsSchemaAttribute.setClassType(String.class.getName());
    rightsSchemaAttribute.setReadable(true);
    rightsSchemaAttribute.setUpdateable(true);
    rightsSchemaAttribute = schemaAttributeService.save(rightsSchemaAttribute);
    SysSystemAttributeMappingDto rightsAttribute = new SysSystemAttributeMappingDto();
    rightsAttribute.setSchemaAttribute(rightsSchemaAttribute.getId());
    rightsAttribute.setSystemMapping(mapping.getId());
    rightsAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsAttribute.setStrategyType(AttributeMappingStrategyType.AUTHORITATIVE_MERGE);
    rightsAttribute = attributeMappingService.save(rightsAttribute);
    SysRoleSystemAttributeDto roleAttributeOne = new SysRoleSystemAttributeDto();
    roleAttributeOne.setName(RIGHTS_ATTRIBUTE);
    roleAttributeOne.setEntityAttribute(false);
    roleAttributeOne.setExtendedAttribute(false);
    roleAttributeOne.setRoleSystem(roleSystemOne.getId());
    roleAttributeOne.setStrategyType(AttributeMappingStrategyType.AUTHORITATIVE_MERGE);
    roleAttributeOne.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    SysRoleSystemAttributeDto roleAttributeTwo = new SysRoleSystemAttributeDto();
    roleAttributeTwo.setName(RIGHTS_ATTRIBUTE);
    roleAttributeTwo.setEntityAttribute(false);
    roleAttributeTwo.setExtendedAttribute(false);
    roleAttributeTwo.setRoleSystem(roleSystemTwo.getId());
    roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.AUTHORITATIVE_MERGE);
    roleAttributeTwo.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "';");
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    IdmIdentityDto identity = this.getHelper().createIdentity();
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    // Set contract as excluded
    contract.setState(ContractState.EXCLUDED);
    contract = identityContractService.save(contract);
    assertTrue(contract.isExcluded());
    this.getHelper().createIdentityRole(identity, roleOne);
    this.getHelper().createIdentityRole(identity, roleTwo);
    SysProvisioningOperationFilter operationFilter = new SysProvisioningOperationFilter();
    operationFilter.setEntityIdentifier(identity.getId());
    List<SysProvisioningArchiveDto> archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    SysProvisioningArchiveDto archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    ProvisioningContext provisioningContext = archive.getProvisioningContext();
    Map<ProvisioningAttributeDto, Object> accountObject = provisioningContext.getAccountObject();
    Entry<ProvisioningAttributeDto, Object> attributeEntry = accountObject.entrySet().stream().filter(entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    List<?> values = (List<?>) attributeEntry.getValue();
    assertEquals(2, values.size());
    // Set attribute TWO to skip value if contract is excluded
    roleAttributeTwo.setSkipValueIfExcluded(true);
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    // Save identity -> execute provisioning
    identityService.save(identity);
    archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    provisioningContext = archive.getProvisioningContext();
    accountObject = provisioningContext.getAccountObject();
    attributeEntry = // 
    accountObject.entrySet().stream().filter(// 
    entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    values = (List<?>) attributeEntry.getValue();
    assertEquals(1, values.size());
    assertEquals(ONE_VALUE, values.get(0));
    // Set contract as not excluded
    contract.setState(null);
    contract = identityContractService.save(contract);
    assertFalse(contract.isExcluded());
    // Save identity -> execute provisioning
    identityService.save(identity);
    archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    provisioningContext = archive.getProvisioningContext();
    accountObject = provisioningContext.getAccountObject();
    attributeEntry = // 
    accountObject.entrySet().stream().filter(// 
    entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    values = (List<?>) attributeEntry.getValue();
    assertEquals(2, values.size());
}
Also used : AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) Autowired(org.springframework.beans.factory.annotation.Autowired) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) Map(java.util.Map) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) AbstractEntity_(eu.bcvsolutions.idm.core.api.entity.AbstractEntity_) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) SysAttributeControlledValueService(eu.bcvsolutions.idm.acc.service.api.SysAttributeControlledValueService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) PageRequest(org.springframework.data.domain.PageRequest) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) Test(org.junit.Test) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Assert.assertFalse(org.junit.Assert.assertFalse) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) Entry(java.util.Map.Entry) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) Sort(org.springframework.data.domain.Sort) List(java.util.List) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with AbstractEntity_

use of eu.bcvsolutions.idm.core.api.entity.AbstractEntity_ in project CzechIdMng by bcvsolutions.

the class ProvisioningMergeTest method testSkipMergeValueIfTwoContractsExcluded.

@Test
public void testSkipMergeValueIfTwoContractsExcluded() {
    SysSystemDto system = helper.createSystem("test_resource");
    SysSystemMappingDto mapping = helper.createMapping(system);
    IdmRoleDto roleOne = helper.createRole();
    IdmRoleDto roleTwo = helper.createRole();
    SysRoleSystemDto roleSystemOne = helper.createRoleSystem(roleOne, system);
    SysRoleSystemDto roleSystemTwo = helper.createRoleSystem(roleTwo, system);
    SysSchemaAttributeDto rightsSchemaAttribute = new SysSchemaAttributeDto();
    rightsSchemaAttribute.setObjectClass(mapping.getObjectClass());
    rightsSchemaAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsSchemaAttribute.setMultivalued(true);
    rightsSchemaAttribute.setClassType(String.class.getName());
    rightsSchemaAttribute.setReadable(true);
    rightsSchemaAttribute.setUpdateable(true);
    rightsSchemaAttribute = schemaAttributeService.save(rightsSchemaAttribute);
    SysSystemAttributeMappingDto rightsAttribute = new SysSystemAttributeMappingDto();
    rightsAttribute.setSchemaAttribute(rightsSchemaAttribute.getId());
    rightsAttribute.setSystemMapping(mapping.getId());
    rightsAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsAttribute.setStrategyType(AttributeMappingStrategyType.MERGE);
    rightsAttribute = attributeMappingService.save(rightsAttribute);
    SysRoleSystemAttributeDto roleAttributeOne = new SysRoleSystemAttributeDto();
    roleAttributeOne.setName(RIGHTS_ATTRIBUTE);
    roleAttributeOne.setEntityAttribute(false);
    roleAttributeOne.setExtendedAttribute(false);
    roleAttributeOne.setRoleSystem(roleSystemOne.getId());
    roleAttributeOne.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeOne.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    List<Serializable> controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    SysRoleSystemAttributeDto roleAttributeTwo = new SysRoleSystemAttributeDto();
    roleAttributeTwo.setName(RIGHTS_ATTRIBUTE);
    roleAttributeTwo.setEntityAttribute(false);
    roleAttributeTwo.setExtendedAttribute(false);
    roleAttributeTwo.setRoleSystem(roleSystemTwo.getId());
    roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeTwo.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "';");
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(2, controlledAttributeValues.size());
    assertTrue(controlledAttributeValues.contains(ONE_VALUE));
    assertTrue(controlledAttributeValues.contains(TWO_VALUE));
    SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
    attributeControlledValueFilter.setAttributeMappingId(rightsAttribute.getId());
    attributeControlledValueFilter.setHistoricValue(Boolean.TRUE);
    List<Serializable> historicControlledValues = // 
    attributeControlledValueService.find(attributeControlledValueFilter, // 
    null).getContent().stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(historicControlledValues);
    assertEquals(0, historicControlledValues.size());
    IdmIdentityDto identity = this.getHelper().createIdentity();
    IdmIdentityContractDto contractOne = this.getHelper().getPrimeContract(identity);
    IdmIdentityContractDto contractTwo = this.getHelper().createContract(identity);
    // Set contract one as excluded
    contractOne.setState(ContractState.EXCLUDED);
    contractOne = identityContractService.save(contractOne);
    assertTrue(contractOne.isExcluded());
    // Set contract two as not excluded
    contractTwo.setState(null);
    contractTwo = identityContractService.save(contractTwo);
    assertFalse(contractTwo.isExcluded());
    this.getHelper().createIdentityRole(identity, roleOne);
    // Role two is assigned by contract one and contract two!
    this.getHelper().createIdentityRole(contractOne, roleTwo);
    this.getHelper().createIdentityRole(contractTwo, roleTwo);
    SysProvisioningOperationFilter operationFilter = new SysProvisioningOperationFilter();
    operationFilter.setEntityIdentifier(identity.getId());
    List<SysProvisioningArchiveDto> archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    SysProvisioningArchiveDto archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    ProvisioningContext provisioningContext = archive.getProvisioningContext();
    Map<ProvisioningAttributeDto, Object> accountObject = provisioningContext.getAccountObject();
    Entry<ProvisioningAttributeDto, Object> attributeEntry = accountObject.entrySet().stream().filter(entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    List<?> values = (List<?>) attributeEntry.getValue();
    assertEquals(2, values.size());
    // Set attribute TWO to skip value if contract is excluded
    roleAttributeTwo.setSkipValueIfExcluded(true);
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    // Save identity -> execute provisioning
    identityService.save(identity);
    archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    provisioningContext = archive.getProvisioningContext();
    accountObject = provisioningContext.getAccountObject();
    attributeEntry = // 
    accountObject.entrySet().stream().filter(// 
    entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    values = (List<?>) attributeEntry.getValue();
    // Skip was not executed, because there is two contracts assigned same role and
    // second contract is not excluded
    assertEquals(2, values.size());
    // Set contract two as excluded
    contractTwo.setState(ContractState.EXCLUDED);
    contractTwo = identityContractService.save(contractTwo);
    assertTrue(contractTwo.isExcluded());
    // Save identity -> execute provisioning
    identityService.save(identity);
    archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    provisioningContext = archive.getProvisioningContext();
    accountObject = provisioningContext.getAccountObject();
    attributeEntry = // 
    accountObject.entrySet().stream().filter(// 
    entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    values = (List<?>) attributeEntry.getValue();
    assertEquals(1, values.size());
    assertEquals(ONE_VALUE, values.get(0));
    // Set contract as not excluded
    contractOne.setState(null);
    contractOne = identityContractService.save(contractOne);
    assertFalse(contractOne.isExcluded());
    // Save identity -> execute provisioning
    identityService.save(identity);
    archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
    assertEquals(1, archives.size());
    archive = archives.get(0);
    assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
    provisioningContext = archive.getProvisioningContext();
    accountObject = provisioningContext.getAccountObject();
    attributeEntry = // 
    accountObject.entrySet().stream().filter(// 
    entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
    values = (List<?>) attributeEntry.getValue();
    assertEquals(2, values.size());
}
Also used : AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) Autowired(org.springframework.beans.factory.annotation.Autowired) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) Map(java.util.Map) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) AbstractEntity_(eu.bcvsolutions.idm.core.api.entity.AbstractEntity_) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) SysAttributeControlledValueService(eu.bcvsolutions.idm.acc.service.api.SysAttributeControlledValueService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) PageRequest(org.springframework.data.domain.PageRequest) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) Test(org.junit.Test) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Assert.assertFalse(org.junit.Assert.assertFalse) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) Entry(java.util.Map.Entry) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) Sort(org.springframework.data.domain.Sort) List(java.util.List) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

AbstractEntity_ (eu.bcvsolutions.idm.core.api.entity.AbstractEntity_)4 List (java.util.List)4 Map (java.util.Map)4 TestHelper (eu.bcvsolutions.idm.acc.TestHelper)3 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)3 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)3 ProvisioningEventType (eu.bcvsolutions.idm.acc.domain.ProvisioningEventType)3 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)3 SysAttributeControlledValueDto (eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto)3 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)3 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)3 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)3 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)3 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)3 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)3 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)3 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)3 SysAttributeControlledValueFilter (eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter)3 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)3 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)3