Search in sources :

Example 21 with ProvisioningAttributeDto

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

the class DefaultSysProvisioningOperationServiceUnitTest method testReplaceCollectionGuardedStringsInAccountObject.

@Test
public void testReplaceCollectionGuardedStringsInAccountObject() {
    ProvisioningContext context = new ProvisioningContext();
    Map<ProvisioningAttributeDto, Object> accoutObject = new HashMap<>();
    context.setAccountObject(accoutObject);
    // 
    // fill properties
    ProvisioningAttributeDto guarded = new ProvisioningAttributeDto("guarded", AttributeMappingStrategyType.SET);
    GuardedString guardedOne = new GuardedString("one");
    GuardedString guardedTwo = new GuardedString("two");
    accoutObject.put(guarded, Lists.newArrayList(guardedOne, guardedTwo));
    // 
    // run
    Map<String, Serializable> confidentiaValues = service.replaceGuardedStrings(context);
    // 
    // check
    assertEquals(2, confidentiaValues.size());
    assertEquals(guardedOne.asString(), confidentiaValues.get(service.createAccountObjectPropertyKey(guarded.getKey(), 0)));
    assertEquals(guardedTwo.asString(), confidentiaValues.get(service.createAccountObjectPropertyKey(guarded.getKey(), 1)));
    assertEquals(2, ((List<?>) accoutObject.get(guarded)).size());
    assertEquals(service.createAccountObjectPropertyKey(guarded.getKey(), 0), ((ConfidentialString) ((List<?>) accoutObject.get(guarded)).get(0)).getKey());
    assertEquals(service.createAccountObjectPropertyKey(guarded.getKey(), 1), ((ConfidentialString) ((List<?>) accoutObject.get(guarded)).get(1)).getKey());
}
Also used : ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) Serializable(java.io.Serializable) HashMap(java.util.HashMap) List(java.util.List) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 22 with ProvisioningAttributeDto

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

the class DefaultSysProvisioningOperationService method deleteConfidentialStrings.

/**
 * Deletes persisted confidential storage values
 *
 * @param provisioningOperation
 */
protected void deleteConfidentialStrings(SysProvisioningOperationDto provisioningOperation) {
    Assert.notNull(provisioningOperation);
    // 
    ProvisioningContext context = provisioningOperation.getProvisioningContext();
    if (context == null) {
        return;
    }
    Map<ProvisioningAttributeDto, Object> accountObject = context.getAccountObject();
    if (accountObject != null) {
        for (Entry<ProvisioningAttributeDto, Object> entry : accountObject.entrySet()) {
            Object idmValue = entry.getValue();
            if (idmValue == null) {
                continue;
            }
            // single value
            if (idmValue instanceof ConfidentialString) {
                confidentialStorage.delete(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) entry.getValue()).getKey());
            } else // array
            if (idmValue.getClass().isArray()) {
                if (!idmValue.getClass().getComponentType().isPrimitive()) {
                    Object[] idmValues = (Object[]) idmValue;
                    for (int j = 0; j < idmValues.length; j++) {
                        Object singleValue = idmValues[j];
                        if (singleValue instanceof ConfidentialString) {
                            confidentialStorage.delete(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) singleValue).getKey());
                        }
                    }
                }
            } else // collection
            if (idmValue instanceof Collection) {
                Collection<?> idmValues = (Collection<?>) idmValue;
                idmValues.forEach(singleValue -> {
                    if (singleValue instanceof ConfidentialString) {
                        confidentialStorage.delete(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) singleValue).getKey());
                    }
                });
            }
        }
    }
    // 
    IcConnectorObject connectorObject = context.getConnectorObject();
    if (connectorObject != null) {
        connectorObject.getAttributes().forEach(attribute -> {
            if (attribute.getValues() != null) {
                attribute.getValues().forEach(attributeValue -> {
                    if (attributeValue instanceof ConfidentialString) {
                        confidentialStorage.delete(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) attributeValue).getKey());
                    }
                });
            }
        });
    }
}
Also used : ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Collection(java.util.Collection) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysProvisioningOperation(eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString)

Example 23 with ProvisioningAttributeDto

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

the class DefaultSysProvisioningOperationService method replaceGuardedStrings.

/**
 * Replaces GuardedStrings as ConfidentialStrings in given {@link ProvisioningContext}.
 *
 * TODO: don't update accountObject in provisioningOperation (needs attribute defensive clone)
 *
 * @param context
 * @return Returns values (key / value) to store in confidential storage.
 */
protected Map<String, Serializable> replaceGuardedStrings(ProvisioningContext context) {
    try {
        Map<String, Serializable> confidentialValues = new HashMap<>();
        if (context == null) {
            return confidentialValues;
        }
        // 
        Map<ProvisioningAttributeDto, Object> accountObject = context.getAccountObject();
        if (accountObject != null) {
            for (Entry<ProvisioningAttributeDto, Object> entry : accountObject.entrySet()) {
                if (entry.getValue() == null) {
                    continue;
                }
                Object idmValue = entry.getValue();
                // single value
                if (idmValue instanceof GuardedString) {
                    GuardedString guardedString = (GuardedString) entry.getValue();
                    // save value into confidential storage
                    String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), 0);
                    confidentialValues.put(confidentialStorageKey, guardedString.asString());
                    accountObject.put(entry.getKey(), new ConfidentialString(confidentialStorageKey));
                } else // array
                if (idmValue.getClass().isArray()) {
                    if (!idmValue.getClass().getComponentType().isPrimitive()) {
                        // objects only, we dont want pto proces byte, boolean etc.
                        Object[] idmValues = (Object[]) idmValue;
                        List<ConfidentialString> processedValues = new ArrayList<>();
                        for (int j = 0; j < idmValues.length; j++) {
                            Object singleValue = idmValues[j];
                            if (singleValue instanceof GuardedString) {
                                GuardedString guardedString = (GuardedString) singleValue;
                                // save value into confidential storage
                                String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), j);
                                confidentialValues.put(confidentialStorageKey, guardedString.asString());
                                processedValues.add(new ConfidentialString(confidentialStorageKey));
                            }
                        }
                        if (!processedValues.isEmpty()) {
                            accountObject.put(entry.getKey(), processedValues.toArray(new ConfidentialString[processedValues.size()]));
                        }
                    }
                } else // collection
                if (idmValue instanceof Collection) {
                    Collection<?> idmValues = (Collection<?>) idmValue;
                    List<ConfidentialString> processedValues = new ArrayList<>();
                    idmValues.forEach(singleValue -> {
                        if (singleValue instanceof GuardedString) {
                            GuardedString guardedString = (GuardedString) singleValue;
                            // save value into confidential storage
                            String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), processedValues.size());
                            confidentialValues.put(confidentialStorageKey, guardedString.asString());
                            processedValues.add(new ConfidentialString(confidentialStorageKey));
                        }
                    });
                    if (!processedValues.isEmpty()) {
                        accountObject.put(entry.getKey(), processedValues);
                    }
                }
            }
        }
        // 
        IcConnectorObject connectorObject = context.getConnectorObject();
        if (connectorObject != null) {
            for (IcAttribute attribute : connectorObject.getAttributes()) {
                if (attribute.getValues() != null) {
                    for (int j = 0; j < attribute.getValues().size(); j++) {
                        Object attributeValue = attribute.getValues().get(j);
                        if (attributeValue instanceof GuardedString) {
                            GuardedString guardedString = (GuardedString) attributeValue;
                            String confidentialStorageKey = createConnectorObjectPropertyKey(attribute, j);
                            confidentialValues.put(confidentialStorageKey, guardedString.asString());
                            attribute.getValues().set(j, new ConfidentialString(confidentialStorageKey));
                        }
                    }
                }
            }
        }
        // 
        return confidentialValues;
    } catch (Exception ex) {
        throw new CoreException("Replace guarded strings for provisioning operation failed.", ex);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Collection(java.util.Collection) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)23 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)18 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)16 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)15 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)14 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)11 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)10 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)9 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)9 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)8 List (java.util.List)8 Test (org.junit.Test)8 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)6 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)6 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)6 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)6