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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations