Search in sources :

Example 1 with IcAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcAttributeImpl in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningOperationServiceUnitTest method testReplaceGuardedStringsInConnectorObject.

@Test
public void testReplaceGuardedStringsInConnectorObject() {
    ProvisioningContext context = new ProvisioningContext();
    IcConnectorObjectImpl connectorObject = new IcConnectorObjectImpl();
    context.setConnectorObject(connectorObject);
    // 
    // fill properties
    String normalValue = "one";
    IcAttributeImpl normal = new IcAttributeImpl("normal", normalValue);
    connectorObject.getAttributes().add(normal);
    GuardedString guardedValue = new GuardedString("one");
    IcAttributeImpl guarded = new IcAttributeImpl("guarded", guardedValue);
    connectorObject.getAttributes().add(guarded);
    // 
    // run
    Map<String, Serializable> confidentiaValues = service.replaceGuardedStrings(context);
    // 
    // check
    assertEquals(1, confidentiaValues.size());
    assertEquals(guardedValue.asString(), confidentiaValues.get(service.createConnectorObjectPropertyKey(guarded, 0)));
    assertEquals(normalValue, connectorObject.getAttributes().get(0).getValue());
    assertNotEquals(guardedValue, connectorObject.getAttributes().get(1).getValue());
}
Also used : ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) Serializable(java.io.Serializable) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 2 with IcAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcAttributeImpl in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method resolveSynchronizationFilter.

/**
 * Compile filter for search from filter attribute and filter script
 *
 * @param config
 * @return
 */
protected IcFilter resolveSynchronizationFilter(AbstractSysSyncConfigDto config) {
    // If is reconciliation, then is filter null
    if (config.isReconciliation()) {
        return null;
    }
    IcFilter filter = null;
    AttributeMapping filterAttributeMapping = null;
    if (config.getFilterAttribute() != null) {
        filterAttributeMapping = systemAttributeMappingService.get(config.getFilterAttribute());
    }
    String configToken = config.getToken();
    String filterScript = config.getCustomFilterScript();
    if (filterAttributeMapping == null && configToken == null && StringUtils.isEmpty(filterScript)) {
        return null;
    }
    if (filterAttributeMapping != null) {
        Object transformedValue = systemAttributeMappingService.transformValueToResource(null, configToken, filterAttributeMapping, config);
        if (transformedValue != null) {
            SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.get(filterAttributeMapping.getSchemaAttribute());
            IcAttributeImpl filterAttribute = new IcAttributeImpl(schemaAttributeDto.getName(), transformedValue);
            switch(config.getFilterOperation()) {
                case GREATER_THAN:
                    filter = IcFilterBuilder.greaterThan(filterAttribute);
                    break;
                case LESS_THAN:
                    filter = IcFilterBuilder.lessThan(filterAttribute);
                    break;
                case EQUAL_TO:
                    filter = IcFilterBuilder.equalTo(filterAttribute);
                    break;
                case CONTAINS:
                    filter = IcFilterBuilder.contains(filterAttribute);
                    break;
                case ENDS_WITH:
                    filter = IcFilterBuilder.endsWith(filterAttribute);
                    break;
                case STARTS_WITH:
                    filter = IcFilterBuilder.startsWith(filterAttribute);
                    break;
            }
        }
    }
    if (StringUtils.hasLength(filterScript)) {
        Map<String, Object> variables = new HashMap<>();
        variables.put("filter", filter);
        variables.put("token", configToken);
        List<Class<?>> allowTypes = new ArrayList<>();
        // Allow all IC filter operator
        for (IcFilterOperationType operation : IcFilterOperationType.values()) {
            allowTypes.add(operation.getImplementation());
        }
        allowTypes.add(IcAndFilter.class);
        allowTypes.add(IcOrFilter.class);
        allowTypes.add(IcFilterBuilder.class);
        allowTypes.add(IcAttributeImpl.class);
        allowTypes.add(IcAttribute.class);
        Object filterObj = groovyScriptService.evaluate(filterScript, variables, allowTypes);
        if (filterObj != null && !(filterObj instanceof IcFilter)) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_FILTER_VALUE_WRONG_TYPE, ImmutableMap.of("type", filterObj.getClass().getName()));
        }
        filter = (IcFilter) filterObj;
    }
    return filter;
}
Also used : HashMap(java.util.HashMap) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcFilterOperationType(eu.bcvsolutions.idm.ic.domain.IcFilterOperationType) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter)

Example 3 with IcAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcAttributeImpl in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningOperationService method getFullConnectorObject.

/**
 * Returns fully loaded ConnectorObject with guarded strings.
 *
 * TODO: don't update connectorObject in provisioningOperation (needs attribute defensive clone)
 *
 * @param provisioningOperation
 * @return
 */
@Override
public IcConnectorObject getFullConnectorObject(SysProvisioningOperationDto provisioningOperation) {
    if (provisioningOperation == null || provisioningOperation.getProvisioningContext() == null || provisioningOperation.getProvisioningContext().getConnectorObject() == null) {
        return null;
    }
    List<IcAttribute> attributes = new ArrayList<>();
    // 
    IcConnectorObject connectorObject = provisioningOperation.getProvisioningContext().getConnectorObject();
    connectorObject.getAttributes().forEach(attribute -> {
        IcAttribute attributeCopy = null;
        if (attribute.isMultiValue()) {
            List<Object> values = (List<Object>) attribute.getValues();
            attributeCopy = new IcAttributeImpl(attribute.getName(), values, true);
        } else if (attribute instanceof IcPasswordAttribute && attribute.getValue() != null) {
            attributeCopy = new IcPasswordAttributeImpl(attribute.getName(), confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) attribute.getValue()).getKey()));
        } else if (attribute instanceof IcPasswordAttribute && attribute.getValue() == null) {
            attributeCopy = new IcPasswordAttributeImpl(attribute.getName(), (GuardedString) null);
        } else {
            attributeCopy = new IcAttributeImpl(attribute.getName(), attribute.getValue());
        }
        attributes.add(attributeCopy);
    });
    IcConnectorObject newConnectorObject = new IcConnectorObjectImpl(connectorObject.getUidValue(), connectorObject.getObjectClass(), attributes);
    return newConnectorObject;
}
Also used : ArrayList(java.util.ArrayList) SysProvisioningOperation(eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) IcPasswordAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcPasswordAttributeImpl) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) List(java.util.List) ArrayList(java.util.ArrayList) IcPasswordAttribute(eu.bcvsolutions.idm.ic.api.IcPasswordAttribute) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)

Example 4 with IcAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcAttributeImpl in project CzechIdMng by bcvsolutions.

the class DefaultVsAccountService method getIcAttributes.

@Override
public List<IcAttribute> getIcAttributes(VsAccountDto account) {
    Assert.notNull(account);
    List<IcAttribute> attributes = new ArrayList<>();
    // Create uid attribute
    IcAttributeImpl uidAttribute = new IcAttributeImpl(IcAttributeInfo.NAME, account.getUid());
    attributes.add(uidAttribute);
    // Create enable attribute
    IcAttributeImpl enableAttribute = new IcAttributeImpl(IcAttributeInfo.ENABLE, account.isEnable());
    attributes.add(enableAttribute);
    String connectorKey = account.getConnectorKey();
    String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", connectorKey, account.getSystemId().toString());
    String type = VsAccount.class.getName();
    IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
    if (definition == null) {
        return attributes;
    }
    definition.getFormAttributes().forEach(formAttribute -> {
        attributes.add(this.getIcAttribute(account.getId(), formAttribute.getName(), definition));
    });
    return attributes;
}
Also used : IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Example 5 with IcAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcAttributeImpl in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method read.

@Override
public IcConnectorObject read(IcUidAttribute uid, IcObjectClass objectClass) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(uid, "UID cannot be null!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    String uidValue = uid.getUidValue();
    if (uidValue == null) {
        throw new IcException("UID value cannot be null!");
    }
    // Find account by UID and System ID
    VsAccountDto account = accountService.findByUidSystem(uidValue, systemId);
    // All attributes from VS account
    List<IcAttribute> vsAttributes = new ArrayList<>();
    // Create uid attribute
    IcAttributeImpl uidAttribute = new IcAttributeImpl(IcAttributeInfo.NAME, uidValue);
    vsAttributes.add(uidAttribute);
    if (account != null) {
        // Create enable attribute
        if (this.virtualConfiguration.isDisableSupported()) {
            IcAttributeImpl enableAttribute = new IcAttributeImpl(IcAttributeInfo.ENABLE, account.isEnable());
            vsAttributes.add(enableAttribute);
        }
        // Attributes from definition and configuration
        UUID accountId = account.getId();
        Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
            IcAttribute attribute = accountService.getIcAttribute(accountId, virtualAttirbute, formDefinition);
            if (attribute == null) {
                return;
            }
            vsAttributes.add(attribute);
        });
    }
    // Overwrite attributes form VS account with attributes from unresloved
    // requests
    List<IcAttribute> attributes = this.overwriteAttributesByUnresolvedRequests(account, uidValue, vsAttributes);
    if (attributes == null) {
        return null;
    }
    IcConnectorObjectImpl connectorObject = new IcConnectorObjectImpl();
    connectorObject.setUidValue(uidValue);
    connectorObject.setObjectClass(new IcObjectClassImpl(IcObjectClassInfo.ACCOUNT));
    connectorObject.setAttributes(attributes);
    return connectorObject;
}
Also used : IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) ArrayList(java.util.ArrayList) IcException(eu.bcvsolutions.idm.ic.exception.IcException) UUID(java.util.UUID) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)

Aggregations

IcAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcAttributeImpl)6 ArrayList (java.util.ArrayList)4 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)3 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)3 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)3 ConfidentialString (eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString)2 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)2 AttributeMapping (eu.bcvsolutions.idm.acc.domain.AttributeMapping)1 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)1 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)1 SysProvisioningOperation (eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation)1 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)1 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)1 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)1 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)1 IcPasswordAttribute (eu.bcvsolutions.idm.ic.api.IcPasswordAttribute)1 IcFilterOperationType (eu.bcvsolutions.idm.ic.domain.IcFilterOperationType)1 IcException (eu.bcvsolutions.idm.ic.exception.IcException)1 IcFilter (eu.bcvsolutions.idm.ic.filter.api.IcFilter)1