Search in sources :

Example 76 with SysSystemAttributeMappingDto

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

the class DefaultSysSystemService method duplicateMapping.

/**
 * Duplication of mapping attributes. Is not in attribute mapping service, because we need use IDs cache (Old vs New IDs)
 * @param id
 * @param schema
 * @param schemaAttributesIds
 * @param mappedAttributesIds
 * @return
 */
private SysSystemMappingDto duplicateMapping(UUID id, SysSchemaObjectClassDto schema, Map<UUID, UUID> schemaAttributesIds, Map<UUID, UUID> mappedAttributesIds) {
    Assert.notNull(id, "Id of duplication mapping, must be filled!");
    Assert.notNull(schema, "Parent schema must be filled!");
    SysSystemMappingDto clonedMapping = systemMappingService.clone(id);
    clonedMapping.setObjectClass(schema.getId());
    SysSystemMappingDto mapping = this.systemMappingService.save(clonedMapping);
    // Clone mapped attributes
    SysSystemAttributeMappingFilter attributesFilter = new SysSystemAttributeMappingFilter();
    attributesFilter.setSystemMappingId(id);
    systemAttributeMappingService.find(attributesFilter, null).forEach(attribute -> {
        UUID originalAttributeId = attribute.getId();
        SysSystemAttributeMappingDto clonedAttribute = systemAttributeMappingService.clone(originalAttributeId);
        // Find cloned schema attribute in cache (by original Id)
        SysSchemaAttributeDto clonedSchemaAttribute = attributeService.get(schemaAttributesIds.get(clonedAttribute.getSchemaAttribute()));
        clonedAttribute.setSystemMapping(mapping.getId());
        clonedAttribute.setSchemaAttribute(clonedSchemaAttribute.getId());
        clonedAttribute = systemAttributeMappingService.save(clonedAttribute);
        // Put original and new id to cache
        mappedAttributesIds.put(originalAttributeId, clonedAttribute.getId());
    });
    return mapping;
}
Also used : SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) UUID(java.util.UUID)

Example 77 with SysSystemAttributeMappingDto

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

the class IdentitySynchronizationExecutor method doUpdateEntity.

/**
 * Fill data from IC attributes to entity (EAV and confidential storage too)
 *
 * @param account
 * @param entityType
 * @param uid
 * @param icAttributes
 * @param mappedAttributes
 * @param log
 * @param logItem
 * @param actionLogs
 */
protected void doUpdateEntity(SynchronizationContext context) {
    String uid = context.getUid();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    AccAccountDto account = context.getAccount();
    List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
    SystemEntityType entityType = context.getEntityType();
    UUID entityId = getEntityByAccount(account.getId());
    IdmIdentityDto identity = null;
    if (entityId != null) {
        identity = identityService.get(entityId);
    }
    if (identity != null) {
        // Update identity
        identity = fillEntity(mappedAttributes, uid, icAttributes, identity, false, context);
        identity = this.save(identity, true);
        // Update extended attribute (entity must be persisted first)
        updateExtendedAttributes(mappedAttributes, uid, icAttributes, identity, false, context);
        // Update confidential attribute (entity must be persisted
        // first)
        updateConfidentialAttributes(mappedAttributes, uid, icAttributes, identity, false, context);
        // Identity Updated
        addToItemLog(logItem, MessageFormat.format("Identity with id {0} was updated", identity.getId()));
        if (logItem != null) {
            logItem.setDisplayName(identity.getUsername());
        }
        // Call provisioning for entity
        this.callProvisioningForEntity(identity, entityType, logItem);
        return;
    } else {
        addToItemLog(logItem, "Identity account relation (with ownership = true) was not found!");
        initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
        return;
    }
}
Also used : SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 78 with SysSystemAttributeMappingDto

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

the class VsReqeustServiceTest method checkMultivalueInWishObjectTest.

@Test
public void checkMultivalueInWishObjectTest() {
    String ldapGroupsName = "ldapGroups";
    String changed = "changed";
    List<String> attributes = new ArrayList<>(Lists.newArrayList(BasicVirtualConfiguration.DEFAULT_ATTRIBUTES));
    attributes.add(ldapGroupsName);
    // Create virtual system with extra attribute (ldapGroups)
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, attributes);
    // Search attribute definition for ldapGroups and set him to multivalue
    String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId().toString());
    String type = VsAccount.class.getName();
    IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
    IdmFormAttributeDto ldapGroupsFormAttr = formAttributeService.findAttribute(VsAccount.class.getName(), definition.getCode(), ldapGroupsName);
    Assert.assertNotNull("Ldap attribute muste exist!", ldapGroupsFormAttr);
    ldapGroupsFormAttr.setMultiple(true);
    formService.saveAttribute(ldapGroupsFormAttr);
    // Generate schema for system (we need propagate multivalue setting)
    SysSchemaObjectClassDto schema = systemService.generateSchema(system).get(0);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(system.getId());
    List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
    SysSystemMappingFilter systemMappingFilter = new SysSystemMappingFilter();
    systemMappingFilter.setSystemId(system.getId());
    systemMappingFilter.setObjectClassId(schema.getId());
    SysSystemMappingDto mapping = systemMappingService.find(systemMappingFilter, null).getContent().get(0);
    for (SysSchemaAttributeDto schemaAttr : schemaAttributes) {
        if (ldapGroupsName.equals(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setUid(false);
            attributeMapping.setEntityAttribute(false);
            attributeMapping.setExtendedAttribute(true);
            attributeMapping.setIdmPropertyName(ldapGroupsName);
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setSystemMapping(mapping.getId());
            systemAttributeMappingService.save(attributeMapping);
        }
    }
    IdmIdentityDto userOne = helper.createIdentity(USER_ONE_NAME);
    List<Serializable> initList = ImmutableList.of("TEST1", "TEST2", "TEST3");
    formService.saveValues(userOne, ldapGroupsName, initList);
    this.assignRoleSystem(system, userOne, ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto createRequest = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, createRequest.getUid());
    Assert.assertEquals(VsOperationType.CREATE, createRequest.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, createRequest.getState());
    VsConnectorObjectDto wish = requestService.getWishConnectorObject(createRequest);
    boolean findAttributeWithouChange = wish.getAttributes().stream().filter(attribute -> !attribute.isChanged()).findFirst().isPresent();
    Assert.assertTrue(!findAttributeWithouChange);
    // Check on exist ldapGroups attribute with three values
    VsAttributeDto ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
    Assert.assertTrue(ldapGroupAttribute.isMultivalue());
    Assert.assertEquals(3, ldapGroupAttribute.getValues().size());
    // Change multivalue attribute
    List<Serializable> changeList = ImmutableList.of("TEST1", changed, "TEST3");
    formService.saveValues(userOne, ldapGroupsName, changeList);
    // Invoke provisioning
    identityService.save(userOne);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(2, requests.size());
    VsRequestDto changeRequest = requests.stream().filter(req -> VsOperationType.UPDATE == req.getOperationType()).findFirst().get();
    wish = requestService.getWishConnectorObject(changeRequest);
    ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
    Assert.assertTrue(ldapGroupAttribute.isMultivalue());
    // Wish must contains three values (all add) ... because previous create
    // request is not realize yet. Wish show changes versus reals state in
    // VsAccount.
    Assert.assertEquals(3, ldapGroupAttribute.getValues().size());
    // We realize the create request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    requestService.realize(createRequest);
    // Refresh wish
    wish = requestService.getWishConnectorObject(changeRequest);
    ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
    Assert.assertTrue(ldapGroupAttribute.isMultivalue());
    // Wish must contains four values ... two without change, one delete and
    // one add value
    Assert.assertEquals(4, ldapGroupAttribute.getValues().size());
    // Find unchanged value
    boolean findCorrectTest1Value = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(initList.get(0)) && value.getOldValue().equals(initList.get(0)) && value.getChange() == null).findFirst().isPresent();
    Assert.assertTrue(findCorrectTest1Value);
    // Find deleted value
    boolean findCorrectDeletedTest2Value = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(initList.get(1)) && value.getOldValue().equals(initList.get(1)) && VsValueChangeType.REMOVED == value.getChange()).findFirst().isPresent();
    Assert.assertTrue(findCorrectDeletedTest2Value);
    // Find added value
    boolean findCorrectCreatedChangedValue = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(changed) && value.getOldValue() == null && VsValueChangeType.ADDED == value.getChange()).findFirst().isPresent();
    Assert.assertTrue(findCorrectCreatedChangedValue);
}
Also used : SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) Date(java.util.Date) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) VsRequestByImplementerEvaluator(eu.bcvsolutions.idm.vs.evaluator.VsRequestByImplementerEvaluator) After(org.junit.After) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) VsOperationType(eu.bcvsolutions.idm.vs.domain.VsOperationType) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) TestHelper(eu.bcvsolutions.idm.vs.TestHelper) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) Collectors(java.util.stream.Collectors) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState) Serializable(java.io.Serializable) List(java.util.List) VsRequest(eu.bcvsolutions.idm.vs.entity.VsRequest) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Before(org.junit.Before) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) InitTestData(eu.bcvsolutions.idm.InitTestData) VsAttributeDto(eu.bcvsolutions.idm.vs.dto.VsAttributeDto) VsValueChangeType(eu.bcvsolutions.idm.vs.domain.VsValueChangeType) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) VsAccountService(eu.bcvsolutions.idm.vs.service.api.VsAccountService) Test(org.junit.Test) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Component(org.springframework.stereotype.Component) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) VsRequestState(eu.bcvsolutions.idm.vs.domain.VsRequestState) Assert(org.junit.Assert) VirtualSystemGroupPermission(eu.bcvsolutions.idm.vs.domain.VirtualSystemGroupPermission) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) VsRequestService(eu.bcvsolutions.idm.vs.service.api.VsRequestService) VsSystemDto(eu.bcvsolutions.idm.vs.dto.VsSystemDto) Serializable(java.io.Serializable) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsAttributeDto(eu.bcvsolutions.idm.vs.dto.VsAttributeDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)78 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)48 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)42 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)37 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)34 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 Test (org.junit.Test)29 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)26 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)26 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)21 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)20 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)20 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)19 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)18 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)14 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)14 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)14 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)13 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)13 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)13