use of eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationService method getFullAccountObject.
/**
* Returns fully loaded AccountObject with guarded strings.
*
* @param provisioningOperation
* @return
*/
@Override
public Map<ProvisioningAttributeDto, Object> getFullAccountObject(SysProvisioningOperationDto provisioningOperation) {
if (provisioningOperation == null || provisioningOperation.getProvisioningContext() == null || provisioningOperation.getProvisioningContext().getAccountObject() == null) {
return null;
}
//
Map<ProvisioningAttributeDto, Object> fullAccountObject = new HashMap<>();
Map<ProvisioningAttributeDto, Object> accountObject = provisioningOperation.getProvisioningContext().getAccountObject();
for (Entry<ProvisioningAttributeDto, Object> entry : accountObject.entrySet()) {
if (entry.getValue() == null) {
fullAccountObject.put(entry.getKey(), entry.getValue());
continue;
}
Object idmValue = entry.getValue();
// single value
if (idmValue instanceof ConfidentialString) {
fullAccountObject.put(entry.getKey(), confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) idmValue).getKey()));
continue;
}
// 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<GuardedString> processedValues = new ArrayList<>();
for (int j = 0; j < idmValues.length; j++) {
Object singleValue = idmValues[j];
if (singleValue instanceof ConfidentialString) {
processedValues.add(confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) singleValue).getKey()));
}
}
if (!processedValues.isEmpty()) {
fullAccountObject.put(entry.getKey(), processedValues.toArray(new GuardedString[processedValues.size()]));
continue;
}
}
} else // collection
if (idmValue instanceof Collection) {
Collection<?> idmValues = (Collection<?>) idmValue;
List<GuardedString> processedValues = new ArrayList<>();
idmValues.forEach(singleValue -> {
if (singleValue instanceof ConfidentialString) {
processedValues.add(confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) singleValue).getKey()));
}
});
if (!processedValues.isEmpty()) {
fullAccountObject.put(entry.getKey(), processedValues);
continue;
}
}
// copy value
fullAccountObject.put(entry.getKey(), entry.getValue());
}
return fullAccountObject;
}
use of eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString 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;
}
use of eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationServiceUnitTest method testReplaceArrayGuardedStringsInAccountObject.
@Test
public void testReplaceArrayGuardedStringsInAccountObject() {
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, new GuardedString[] { 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, ((Object[]) accoutObject.get(guarded)).length);
assertEquals(service.createAccountObjectPropertyKey(guarded.getKey(), 0), ((ConfidentialString) ((Object[]) accoutObject.get(guarded))[0]).getKey());
assertEquals(service.createAccountObjectPropertyKey(guarded.getKey(), 1), ((ConfidentialString) ((Object[]) accoutObject.get(guarded))[1]).getKey());
}
use of eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString 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());
}
use of eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString 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());
}
});
}
});
}
}
Aggregations