Search in sources :

Example 31 with SysRoleSystemAttributeDto

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

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

the class VsProvisioningMergeTest method testChangeControlledValue.

@Test
public void testChangeControlledValue() {
    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);
    // Change controlled value
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "_changed';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    // Do provisioning
    identityService.save(identity);
    // Check values on target system
    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(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) 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) 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 33 with SysRoleSystemAttributeDto

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

the class RoleSynchronizationExecutor method resolveAssignRole.

private boolean resolveAssignRole(boolean isNew, SynchronizationContext context, IdmRoleDto roleDto, SysSyncRoleConfigDto config, SysSyncItemLogDto logItem, IcConnectorObject connectorObject, SysSystemAttributeMappingDto memberOfAttributeDto, SysSchemaObjectClassDto schemaObjectClassDto) {
    // Find attribute for get members (DNs)
    SysSystemAttributeMappingDto roleMembersAttributeDto = context.getMappedAttributes().stream().filter(attribute -> !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && ROLE_MEMBERS_FIELD.equals(attribute.getIdmPropertyName())).findFirst().orElse(null);
    Assert.notNull(roleMembersAttributeDto, "Mapped attribute with role's members was not found. Please create it!");
    if (!isNew && AttributeMappingStrategyType.CREATE == roleMembersAttributeDto.getStrategyType()) {
        addToItemLog(logItem, "The attribute with role's members has strategy set to 'Set only for new entity'. Role isn't new, so resolving controlling an assignment of roles to users by the external system will be skipped for this role.");
    } else {
        addToItemLog(logItem, "Controlling an assignment of roles to users by the external system is activated.");
        Object membersObj = this.getValueByMappedAttribute(roleMembersAttributeDto, connectorObject.getAttributes(), context);
        if (membersObj == null) {
            membersObj = Lists.newArrayList();
        }
        if (membersObj instanceof String) {
            membersObj = Lists.newArrayList(membersObj);
        }
        Assert.isInstanceOf(List.class, membersObj, "The value from attribute with role's members must be List of Strings!");
        @SuppressWarnings("unchecked") List<String> members = (List<String>) membersObj;
        SysRoleSystemDto roleSystemDto = findRoleSystemDto(roleDto, memberOfAttributeDto, schemaObjectClassDto);
        if (roleSystemDto == null) {
            addToItemLog(logItem, "Relation between this role and system was not found. Assigning of role to users will be skip for this role.");
            return false;
        }
        SysRoleSystemAttributeDto memberAttribute = findMemberAttribute(memberOfAttributeDto, schemaObjectClassDto, roleSystemDto);
        if (memberAttribute == null) {
            addToItemLog(logItem, "The member attribute between this role and system was not found. Assigning of role to users will be skip for this role.");
            return false;
        }
        // Find identities with this role.
        IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
        identityRoleFilter.setRoleId(roleDto.getId());
        List<IdmIdentityRoleDto> existsIdentityRoleDtos = identityRoleService.find(identityRoleFilter, null).getContent();
        // Get cache with users (DN vs UID).
        Map<String, String> usersUidCache = getUserUidCache();
        SysSchemaAttributeDto memberIdentifierAttribute = lookupService.lookupEmbeddedDto(config, SysSyncRoleConfig_.memberIdentifierAttribute);
        Assert.notNull(memberIdentifierAttribute, "User identifier attribute cannot be null!");
        Set<String> membersUid = Sets.newHashSet();
        Set<UUID> membersContractIds = Sets.newHashSet();
        // Call user system for every member (if isn't already in the cache).
        SysSystemDto userSystemDto = systemService.get(roleSystemDto.getSystem());
        IcConnectorConfiguration icConfig = systemService.getConnectorConfiguration(userSystemDto);
        IcConnectorInstance connectorInstance = systemService.getConnectorInstance(userSystemDto);
        IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
        if (icConfig instanceof IcConnectorConfigurationImpl) {
            // Enable pooling - a performance reason.
            IcConnectorConfigurationImpl icConfigImpl = (IcConnectorConfigurationImpl) icConfig;
            icConfigImpl.setConnectorPoolingSupported(true);
        }
        final int[] count = { 0 };
        for (String member : members) {
            if (!transformDnToUid(config, usersUidCache, memberIdentifierAttribute, membersUid, icConfig, connectorInstance, objectClass, count, member)) {
                return false;
            }
        }
        count[0] = 0;
        membersUid.forEach(uid -> assignMissingIdentityRoles(roleDto, config, logItem, existsIdentityRoleDtos, membersContractIds, userSystemDto, count, uid, context));
        if (!checkForCancelAndFlush(config)) {
            return false;
        }
        // Remove redundant identity roles.
        List<IdmIdentityRoleDto> redundantIdentityRoles = existsIdentityRoleDtos.stream().filter(existsIdentityRole -> !membersContractIds.contains(existsIdentityRole.getIdentityContract())).collect(Collectors.toList());
        count[0] = 0;
        redundantIdentityRoles.forEach(redundantIdentityRole -> removeRedundantIdentityRoles(roleDto, config, logItem, count, redundantIdentityRole));
    }
    return true;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) SysSystemAttributeMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) EntityAccountService(eu.bcvsolutions.idm.acc.service.api.EntityAccountService) Map(java.util.Map) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AccRoleAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter) Set(java.util.Set) Serializable(java.io.Serializable) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IdmRoleCatalogueService(eu.bcvsolutions.idm.core.api.service.IdmRoleCatalogueService) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IdmRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_) IdmRoleCatalogueRole_(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole_) RoleEvent(eu.bcvsolutions.idm.core.model.event.RoleEvent) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) RoleEventType(eu.bcvsolutions.idm.core.model.event.RoleEvent.RoleEventType) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) IcFilterBuilder(eu.bcvsolutions.idm.ic.filter.impl.IcFilterBuilder) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) AccRoleAccountService(eu.bcvsolutions.idm.acc.service.api.AccRoleAccountService) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) SysSyncRoleConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncRoleConfigDto) IcConnectorConfigurationImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorConfigurationImpl) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) RoleType(eu.bcvsolutions.idm.core.api.domain.RoleType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) AccRoleAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleAccountFilter) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) SysSchemaAttribute_(eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute_) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRoleCatalogueRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCatalogueRoleFilter) ImmutableMap(com.google.common.collect.ImmutableMap) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleCatalogue_(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue_) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) IdmRoleCatalogueFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCatalogueFilter) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AtomicReference(java.util.concurrent.atomic.AtomicReference) MessageFormat(java.text.MessageFormat) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IdmRoleCatalogueRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncRoleConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncRoleConfig_) IdmRoleCatalogueRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleCatalogueRoleService) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) Component(org.springframework.stereotype.Component) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) Assert(org.springframework.util.Assert) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcConnectorConfigurationImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorConfigurationImpl) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) List(java.util.List) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID)

Example 34 with SysRoleSystemAttributeDto

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

the class RoleSynchronizationExecutor method resolveMembership.

/**
 * Resolve role membership.
 */
private boolean resolveMembership(boolean isNew, SynchronizationContext context, IdmRoleDto roleDto, SysSyncRoleConfigDto config, SysSyncItemLogDto logItem, IcConnectorObject connectorObject, SysSystemAttributeMappingDto memberOfAttributeDto, SysSchemaObjectClassDto schemaObjectClassDto) {
    UUID memberOfAttribute = config.getMemberOfAttribute();
    Assert.notNull(memberOfAttribute, "Member attribute cannot be null!");
    // Find attribute for get role identifier (DN)
    SysSystemAttributeMappingDto roleIdentifierAttributeDto = context.getMappedAttributes().stream().filter(attribute -> !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && ROLE_MEMBERSHIP_ID_FIELD.equals(attribute.getIdmPropertyName())).findFirst().orElse(null);
    Assert.notNull(roleIdentifierAttributeDto, "Role identifier attribute cannot be null!");
    if (!isNew && AttributeMappingStrategyType.CREATE == roleIdentifierAttributeDto.getStrategyType()) {
        addToItemLog(logItem, "The attribute with role identifier has strategy set to 'Set only for new entity'. Role isn't new, so resolving of membership will be skipped for this role.");
    } else {
        addToItemLog(logItem, MessageFormat.format("Resolving of membership is activated for this role {0}.", roleDto.getCode()));
        Object roleIdentifierObj = this.getValueByMappedAttribute(roleIdentifierAttributeDto, connectorObject.getAttributes(), context);
        String roleIdentifier;
        if (roleIdentifierObj != null) {
            Assert.isInstanceOf(String.class, roleIdentifierObj, "Role identifier must be String!");
            roleIdentifier = (String) roleIdentifierObj;
        } else {
            // Identifier form transformation is null -> We will delete role-system relations.
            addToItemLog(logItem, "The role identifier form a transformation is null -> We will try to delete role-system relation and member attribute.");
            SysRoleSystemDto roleSystemDto = findRoleSystemDto(roleDto, memberOfAttributeDto, schemaObjectClassDto);
            if (roleSystemDto != null) {
                // Find member attribute. If exist, then will be deleted.
                SysRoleSystemAttributeDto memberAttribute = findMemberAttribute(memberOfAttributeDto, schemaObjectClassDto, roleSystemDto);
                if (memberAttribute != null) {
                    roleSystemAttributeService.delete(memberAttribute);
                    addToItemLog(logItem, MessageFormat.format("Member attribute {0} was deleted.", memberAttribute.getName()));
                }
                // Check if role-system relationship contains others attribute. If not, the relationship will be deleted.
                SysRoleSystemAttributeDto someOtherAttribute = findMemberAttribute(null, schemaObjectClassDto, roleSystemDto);
                if (someOtherAttribute == null) {
                    roleSystemService.delete(roleSystemDto);
                    addToItemLog(logItem, MessageFormat.format("Role-system relation {0} was deleted.", roleSystemDto.getId()));
                }
            }
            // End of processing.
            return false;
        }
        // Resolve (create or update) relation on a system.
        SysRoleSystemDto roleSystemDto = resolveRoleSystem(roleDto, memberOfAttributeDto, schemaObjectClassDto);
        // Resolve (create or update) relation on member attribute (ldapGroups).
        resolveMemberAttribute(logItem, memberOfAttributeDto, roleIdentifier, schemaObjectClassDto, roleSystemDto);
    }
    return true;
}
Also used : SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) UUID(java.util.UUID) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)

Example 35 with SysRoleSystemAttributeDto

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

the class IdentityProvisioningExecutor method findOverloadingAttributes.

/**
 * Return list of all overloading attributes for given identity, system and uid
 *
 * @param entity
 * @param system
 * @param entityType
 * @param account
 * @return
 */
@Override
protected List<SysRoleSystemAttributeDto> findOverloadingAttributes(IdmIdentityDto entity, SysSystemDto system, AccAccountDto account, SystemEntityType entityType) {
    SysSystemMappingDto mapping = getMapping(system, entityType);
    List<SysRoleSystemAttributeDto> roleSystemAttributesAll = new ArrayList<>();
    if (mapping == null) {
        return roleSystemAttributesAll;
    }
    // Search overridden attributes for this account.
    SysRoleSystemAttributeFilter roleSystemAttributeFilter = new SysRoleSystemAttributeFilter();
    roleSystemAttributeFilter.setSystemMappingId(mapping.getId());
    // Filtering by identity-account relation.
    roleSystemAttributeFilter.setAccountId(account.getId());
    roleSystemAttributeFilter.setIdentityId(entity.getId());
    List<SysRoleSystemAttributeDto> roleAttributes = roleSystemAttributeService.find(roleSystemAttributeFilter, null).getContent();
    if (!CollectionUtils.isEmpty(roleAttributes)) {
        roleSystemAttributesAll.addAll(roleAttributes);
    }
    // Cross-domains attributes and no-login attributes will be added only for default UID.
    // It means, if some attributes override an UID attribute, then no additional attribute will be used!
    boolean uidIsOverridden = roleSystemAttributesAll.stream().anyMatch(SysRoleSystemAttributeDto::isUid);
    if (!uidIsOverridden) {
        // Add overridden attributes which are in a cross-domain group or is in no-login role.
        // Beware - these attributes are added for every account (overridden attributes are not supported)
        roleSystemAttributeFilter = new SysRoleSystemAttributeFilter();
        roleSystemAttributeFilter.setRoleSystemRelationForIdentityId(entity.getId());
        roleSystemAttributeFilter.setSystemMappingId(mapping.getId());
        roleSystemAttributeFilter.setInCrossDomainGroupOrIsNoLogin(Boolean.TRUE);
        List<SysRoleSystemAttributeDto> roleAttributesInCrossGroup = roleSystemAttributeService.find(roleSystemAttributeFilter, null).getContent();
        if (!CollectionUtils.isEmpty(roleAttributesInCrossGroup)) {
            roleSystemAttributesAll.addAll(roleAttributesInCrossGroup);
        }
    }
    return roleSystemAttributesAll;
}
Also used : SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) ArrayList(java.util.ArrayList) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)

Aggregations

SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)65 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)50 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)47 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)44 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)42 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)41 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)36 Test (org.junit.Test)34 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)30 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)25 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)20 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)19 UUID (java.util.UUID)19 ArrayList (java.util.ArrayList)17 SysRoleSystemAttributeService (eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)16 List (java.util.List)16 Autowired (org.springframework.beans.factory.annotation.Autowired)16 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)15