Search in sources :

Example 6 with SysAttributeControlledValueDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto in project CzechIdMng by bcvsolutions.

the class AttributeControlledValueDeleteProcessor method process.

@Override
public EventResult<SysAttributeControlledValueDto> process(EntityEvent<SysAttributeControlledValueDto> event) {
    SysAttributeControlledValueDto entity = event.getContent();
    service.deleteInternal(entity);
    return new DefaultEventResult<>(event, this);
}
Also used : SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 7 with SysAttributeControlledValueDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto in project CzechIdMng by bcvsolutions.

the class VsProvisioningMergeTest method testSwitchControlledValue.

@Test
public void testSwitchControlledValue() {
    VsSystemDto config = new VsSystemDto();
    config.setName(helper.createName());
    config.setCreateDefaultRole(false);
    SysSystemDto system = helper.createVirtualSystem(config);
    IdmRoleDto roleOne = helper.createRole();
    IdmRoleDto roleTwo = helper.createRole();
    SysRoleSystemDto roleSystemOne = helper.createRoleSystem(roleOne, system);
    SysRoleSystemDto roleSystemTwo = helper.createRoleSystem(roleTwo, system);
    SysSystemMappingDto mapping = mappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
    SysSystemAttributeMappingFilter attributeFilter = new SysSystemAttributeMappingFilter();
    attributeFilter.setSystemMappingId(mapping.getId());
    attributeFilter.setSchemaAttributeName(RIGHTS_ATTRIBUTE);
    List<SysSystemAttributeMappingDto> attributes = attributeMappingService.find(attributeFilter, null).getContent();
    assertEquals(1, attributes.size());
    SysSystemAttributeMappingDto rightsAttribute = attributes.get(0);
    SysRoleSystemAttributeDto roleAttributeOne = new SysRoleSystemAttributeDto();
    roleAttributeOne.setName(RIGHTS_ATTRIBUTE);
    roleAttributeOne.setRoleSystem(roleSystemOne.getId());
    roleAttributeOne.setEntityAttribute(false);
    roleAttributeOne.setExtendedAttribute(false);
    roleAttributeOne.setUid(false);
    roleAttributeOne.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeOne.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    SysRoleSystemAttributeDto roleAttributeTwo = new SysRoleSystemAttributeDto();
    roleAttributeTwo.setName(RIGHTS_ATTRIBUTE);
    roleAttributeTwo.setRoleSystem(roleSystemTwo.getId());
    roleAttributeTwo.setEntityAttribute(false);
    roleAttributeTwo.setExtendedAttribute(false);
    roleAttributeTwo.setUid(false);
    roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeTwo.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "';");
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    IdmIdentityDto identity = helper.createIdentity();
    helper.createIdentityRole(identity, roleOne);
    helper.createIdentityRole(identity, roleTwo);
    AccAccountFilter accountFilter = new AccAccountFilter();
    accountFilter.setSystemId(system.getId());
    List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
    assertEquals(1, accounts.size());
    AccAccountDto account = accounts.get(0);
    IcConnectorObject connectorObject = accountService.getConnectorObject(account);
    IcAttribute rightsAttributeFromSystem = connectorObject.getAttributeByName(RIGHTS_ATTRIBUTE);
    List<Object> rightsValues = rightsAttributeFromSystem.getValues();
    assertEquals(2, rightsValues.size());
    assertTrue(rightsValues.contains(ONE_VALUE));
    assertTrue(rightsValues.contains(TWO_VALUE));
    // Change controlled value
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "_changed';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    SysAttributeControlledValueFilter controlledValueFilter = new SysAttributeControlledValueFilter();
    controlledValueFilter.setHistoricValue(Boolean.TRUE);
    controlledValueFilter.setAttributeMappingId(rightsAttribute.getId());
    List<SysAttributeControlledValueDto> attributeControlledValues = controlledValueService.find(controlledValueFilter, null).getContent();
    // One historic value should be exists
    assertEquals(1, attributeControlledValues.size());
    assertEquals(ONE_VALUE, attributeControlledValues.get(0).getValue());
    // Deleting of old value ... we don't want controlled it from now
    controlledValueService.delete(attributeControlledValues.get(0));
    // Do provisioning
    identityService.save(identity);
    // Check values on target system
    accounts = accountService.find(accountFilter, null).getContent();
    assertEquals(1, accounts.size());
    account = accounts.get(0);
    connectorObject = accountService.getConnectorObject(account);
    rightsAttributeFromSystem = connectorObject.getAttributeByName(RIGHTS_ATTRIBUTE);
    rightsValues = rightsAttributeFromSystem.getValues();
    assertEquals(3, rightsValues.size());
    assertTrue(rightsValues.contains(ONE_VALUE));
    assertTrue(rightsValues.contains(TWO_VALUE));
    assertTrue(rightsValues.contains(ONE_VALUE + "_changed"));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) VsSystemDto(eu.bcvsolutions.idm.vs.dto.VsSystemDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 8 with SysAttributeControlledValueDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto in project CzechIdMng by bcvsolutions.

the class ProvisioningMergeTest method testControlledAndHistoricValuesRemoveMapping.

@Test
public void testControlledAndHistoricValuesRemoveMapping() {
    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.setRoleSystem(roleSystemOne.getId());
    roleAttributeOne.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeOne.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    SysRoleSystemAttributeDto roleAttributeTwo = new SysRoleSystemAttributeDto();
    roleAttributeTwo.setName(RIGHTS_ATTRIBUTE);
    roleAttributeTwo.setRoleSystem(roleSystemTwo.getId());
    roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeTwo.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "';");
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    List<Serializable> 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));
    attributeMappingService.recalculateAttributeControlledValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE, rightsAttribute);
    SysAttributeControlledValueFilter attributeHistoricalValueFilter = new SysAttributeControlledValueFilter();
    attributeHistoricalValueFilter.setHistoricValue(Boolean.TRUE);
    attributeHistoricalValueFilter.setAttributeMappingId(rightsAttribute.getId());
    List<SysAttributeControlledValueDto> historicAttributeValues = attributeControlledValueService.find(attributeHistoricalValueFilter, null).getContent();
    List<Serializable> onlyValues = // 
    historicAttributeValues.stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(onlyValues);
    assertEquals(0, onlyValues.size());
    // Remove whole mapping (this is different between another tests)
    roleSystemService.delete(roleSystemOne);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(1, controlledAttributeValues.size());
    assertTrue(controlledAttributeValues.contains(TWO_VALUE));
    historicAttributeValues = attributeControlledValueService.find(attributeHistoricalValueFilter, null).getContent();
    onlyValues = // 
    historicAttributeValues.stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(onlyValues);
    assertEquals(1, onlyValues.size());
    assertTrue(onlyValues.contains(ONE_VALUE));
    // Remove second whole mapping (this is different between another tests)
    roleSystemService.delete(roleSystemTwo);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(0, controlledAttributeValues.size());
    historicAttributeValues = attributeControlledValueService.find(attributeHistoricalValueFilter, null).getContent();
    onlyValues = // 
    historicAttributeValues.stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(onlyValues);
    assertEquals(2, onlyValues.size());
    assertTrue(onlyValues.contains(ONE_VALUE));
    assertTrue(onlyValues.contains(TWO_VALUE));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with SysAttributeControlledValueDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto in project CzechIdMng by bcvsolutions.

the class ProvisioningMergeTest method testCachedControlledAndHistoricValues.

@Test
public void testCachedControlledAndHistoricValues() {
    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.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.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());
    // Manual recalculation
    attributeMappingService.recalculateAttributeControlledValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE, rightsAttribute);
    // Check cached controlled and historic values (results are controlled and
    // historic values in one lists)
    List<Serializable> cachedControlledAndHistoricAttributeValues = attributeMappingService.getCachedControlledAndHistoricAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(cachedControlledAndHistoricAttributeValues);
    assertEquals(2, cachedControlledAndHistoricAttributeValues.size());
    assertTrue(cachedControlledAndHistoricAttributeValues.contains(ONE_VALUE));
    assertTrue(cachedControlledAndHistoricAttributeValues.contains(TWO_VALUE));
    // Change value definition on attribute TWO (should be changed in controlled
    // values
    // and old value appears in the history)
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "Changed';");
    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 + "Changed"));
    // Search historic controlled values for that attribute
    List<SysAttributeControlledValueDto> historicControlledValueDtos = // 
    attributeControlledValueService.find(attributeControlledValueFilter, // 
    null).getContent();
    assertNotNull(historicControlledValueDtos);
    assertEquals(1, historicControlledValueDtos.size());
    assertTrue(historicControlledValueDtos.get(0).getValue().equals(TWO_VALUE));
    // Manual recalculation (needed for deleting redundant historic value)
    attributeMappingService.recalculateAttributeControlledValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE, rightsAttribute);
    // Check cached controlled and historic values (results are controlled and
    // historic values in one lists)
    cachedControlledAndHistoricAttributeValues = attributeMappingService.getCachedControlledAndHistoricAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(cachedControlledAndHistoricAttributeValues);
    assertEquals(3, cachedControlledAndHistoricAttributeValues.size());
    assertTrue(cachedControlledAndHistoricAttributeValues.contains(ONE_VALUE));
    assertTrue(cachedControlledAndHistoricAttributeValues.contains(TWO_VALUE));
    assertTrue(cachedControlledAndHistoricAttributeValues.contains(TWO_VALUE + "Changed"));
    // Delete historic value TWO. Should be disappear from the cached values
    attributeControlledValueService.delete(historicControlledValueDtos.get(0));
    cachedControlledAndHistoricAttributeValues = attributeMappingService.getCachedControlledAndHistoricAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(cachedControlledAndHistoricAttributeValues);
    assertEquals(2, cachedControlledAndHistoricAttributeValues.size());
    assertTrue(cachedControlledAndHistoricAttributeValues.contains(ONE_VALUE));
    assertTrue(cachedControlledAndHistoricAttributeValues.contains(TWO_VALUE + "Changed"));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 10 with SysAttributeControlledValueDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto 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

SysAttributeControlledValueDto (eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto)15 SysAttributeControlledValueFilter (eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter)13 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)11 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)11 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)11 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)10 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)10 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)10 Test (org.junit.Test)10 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)9 Serializable (java.io.Serializable)9 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)4 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)4 SysAttributeControlledValueService (eu.bcvsolutions.idm.acc.service.api.SysAttributeControlledValueService)4 SysSystemAttributeMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 List (java.util.List)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 TestHelper (eu.bcvsolutions.idm.acc.TestHelper)3