use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method testReadOnlySystem.
@Test
public void testReadOnlySystem() {
String suffixForPassword = "-" + System.currentTimeMillis();
SysSystemDto system = initSystem();
system.setReadonly(true);
system = systemService.save(system);
SysSystemAttributeMappingDto descriptionAttribute = initDescriptionAttribute(system);
descriptionAttribute = changeAttributeToPasswordMapping(descriptionAttribute, "" + "import eu.bcvsolutions.idm.core.security.api.domain.GuardedString;" + System.lineSeparator() + "" + System.lineSeparator() + "String newPassword = attributeValue.asString();" + System.lineSeparator() + "return new GuardedString(newPassword + '" + suffixForPassword + "');" + System.lineSeparator());
IdmRoleDto role = initRole(system);
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
long deleteOperations = provisioningOperationService.deleteOperations(system.getId());
assertEquals(1l, deleteOperations);
// Execute provisioning
identityService.save(identity);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityIdentifier(identity.getId());
List<SysProvisioningOperationDto> operations = provisioningOperationService.find(filter, null).getContent();
assertEquals(1, operations.size());
SysProvisioningOperationDto operationDto = operations.get(0);
assertEquals(ProvisioningEventType.CREATE, operationDto.getOperationType());
Map<ProvisioningAttributeDto, Object> accountObject = operationDto.getProvisioningContext().getAccountObject();
String confidentialAccountKeyPassword = null;
String confidentialAccountKeyDescrip = null;
String confidentialConnectorKeyPassword = null;
String confidentialConnectorKeyDescrip = null;
boolean descripAttributeExists = false;
boolean passwordAttributeExists = false;
for (Entry<ProvisioningAttributeDto, Object> entry : accountObject.entrySet()) {
ProvisioningAttributeDto key = entry.getKey();
if (key.getSchemaAttributeName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION)) {
descripAttributeExists = true;
Object value = entry.getValue();
assertTrue(value instanceof ConfidentialString);
ConfidentialString confidentialStorageValue = (ConfidentialString) value;
confidentialAccountKeyDescrip = confidentialStorageValue.getKey();
GuardedString guardedString = confidentialStorage.getGuardedString(operationDto, confidentialAccountKeyDescrip);
assertNotNull(guardedString);
String asString = guardedString.asString();
assertEquals(DEFAULT_PASSWORD + suffixForPassword, asString);
}
if (key.getSchemaAttributeName().equalsIgnoreCase(ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME)) {
passwordAttributeExists = true;
Object value = entry.getValue();
assertTrue(value instanceof ConfidentialString);
ConfidentialString confidentialStorageValue = (ConfidentialString) value;
confidentialAccountKeyPassword = confidentialStorageValue.getKey();
GuardedString guardedString = confidentialStorage.getGuardedString(operationDto, confidentialAccountKeyPassword);
assertNotNull(guardedString);
String asString = guardedString.asString();
assertEquals(DEFAULT_PASSWORD, asString);
}
}
assertTrue(passwordAttributeExists);
assertTrue(descripAttributeExists);
descripAttributeExists = false;
passwordAttributeExists = false;
IcConnectorObject connectorObject = operationDto.getProvisioningContext().getConnectorObject();
for (IcAttribute attribute : connectorObject.getAttributes()) {
if (attribute.getName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION)) {
descripAttributeExists = true;
Object value = attribute.getValue();
assertTrue(value instanceof ConfidentialString);
ConfidentialString confidentialStorageValue = (ConfidentialString) value;
confidentialConnectorKeyDescrip = confidentialStorageValue.getKey();
GuardedString guardedString = confidentialStorage.getGuardedString(operationDto, confidentialConnectorKeyDescrip);
assertNotNull(guardedString);
String asString = guardedString.asString();
assertEquals(DEFAULT_PASSWORD + suffixForPassword, asString);
}
if (attribute.getName().equalsIgnoreCase(ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME)) {
passwordAttributeExists = true;
Object value = attribute.getValue();
assertTrue(value instanceof ConfidentialString);
ConfidentialString confidentialStorageValue = (ConfidentialString) value;
confidentialConnectorKeyPassword = confidentialStorageValue.getKey();
GuardedString guardedString = confidentialStorage.getGuardedString(operationDto, confidentialConnectorKeyPassword);
assertNotNull(guardedString);
String asString = guardedString.asString();
assertEquals(DEFAULT_PASSWORD, asString);
}
}
assertTrue(passwordAttributeExists);
assertTrue(descripAttributeExists);
assertNotNull(confidentialAccountKeyPassword);
assertNotNull(confidentialAccountKeyDescrip);
assertNotNull(confidentialConnectorKeyPassword);
assertNotNull(confidentialConnectorKeyDescrip);
system.setReadonly(false);
system = systemService.save(system);
operationDto = provisioningExecutor.executeSync(operationDto);
assertEquals(OperationState.EXECUTED, operationDto.getResultState());
Serializable serializable = confidentialStorage.get(operationDto, confidentialAccountKeyPassword);
assertNull(serializable);
serializable = confidentialStorage.get(operationDto, confidentialAccountKeyDescrip);
assertNull(serializable);
serializable = confidentialStorage.get(operationDto, confidentialConnectorKeyPassword);
assertNull(serializable);
serializable = confidentialStorage.get(operationDto, confidentialConnectorKeyDescrip);
assertNull(serializable);
SysProvisioningOperationFilter archiveFilter = new SysProvisioningOperationFilter();
archiveFilter.setSystemId(system.getId());
archiveFilter.setEntityIdentifier(identity.getId());
List<SysProvisioningArchiveDto> archive = provisioningArchiveService.find(archiveFilter, null).getContent();
assertEquals(1, archive.size());
SysProvisioningArchiveDto provisioningArchiveDto = archive.get(0);
descripAttributeExists = false;
passwordAttributeExists = false;
for (Entry<ProvisioningAttributeDto, Object> entry : provisioningArchiveDto.getProvisioningContext().getAccountObject().entrySet()) {
ProvisioningAttributeDto key = entry.getKey();
if (key.getSchemaAttributeName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION)) {
descripAttributeExists = true;
Object value = entry.getValue();
assertTrue(value instanceof ConfidentialString);
ConfidentialString confidentialStorageValue = (ConfidentialString) value;
confidentialAccountKeyDescrip = confidentialStorageValue.getKey();
GuardedString guardedString = confidentialStorage.getGuardedString(operationDto, confidentialAccountKeyDescrip);
assertNotNull(guardedString);
assertTrue(StringUtils.isEmpty(guardedString.asString()));
guardedString = confidentialStorage.getGuardedString(provisioningArchiveDto, confidentialAccountKeyDescrip);
assertNotNull(guardedString);
assertTrue(StringUtils.isEmpty(guardedString.asString()));
}
if (key.getSchemaAttributeName().equalsIgnoreCase(ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME)) {
passwordAttributeExists = true;
Object value = entry.getValue();
assertTrue(value instanceof ConfidentialString);
ConfidentialString confidentialStorageValue = (ConfidentialString) value;
confidentialAccountKeyPassword = confidentialStorageValue.getKey();
GuardedString guardedString = confidentialStorage.getGuardedString(operationDto, confidentialAccountKeyPassword);
assertNotNull(guardedString);
assertTrue(StringUtils.isEmpty(guardedString.asString()));
guardedString = confidentialStorage.getGuardedString(provisioningArchiveDto, confidentialAccountKeyPassword);
assertNotNull(guardedString);
assertTrue(StringUtils.isEmpty(guardedString.asString()));
}
}
assertTrue(passwordAttributeExists);
assertTrue(descripAttributeExists);
descripAttributeExists = false;
passwordAttributeExists = false;
connectorObject = provisioningArchiveDto.getProvisioningContext().getConnectorObject();
for (IcAttribute attribute : connectorObject.getAttributes()) {
if (attribute.getName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION)) {
descripAttributeExists = true;
Object value = attribute.getValue();
assertTrue(value instanceof ConfidentialString);
ConfidentialString confidentialStorageValue = (ConfidentialString) value;
confidentialConnectorKeyDescrip = confidentialStorageValue.getKey();
GuardedString guardedString = confidentialStorage.getGuardedString(operationDto, confidentialConnectorKeyDescrip);
assertNotNull(guardedString);
assertTrue(StringUtils.isEmpty(guardedString.asString()));
guardedString = confidentialStorage.getGuardedString(provisioningArchiveDto, confidentialConnectorKeyDescrip);
assertNotNull(guardedString);
assertTrue(StringUtils.isEmpty(guardedString.asString()));
}
if (attribute.getName().equalsIgnoreCase(ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME)) {
passwordAttributeExists = true;
Object value = attribute.getValue();
assertTrue(value instanceof ConfidentialString);
ConfidentialString confidentialStorageValue = (ConfidentialString) value;
confidentialConnectorKeyPassword = confidentialStorageValue.getKey();
GuardedString guardedString = confidentialStorage.getGuardedString(operationDto, confidentialConnectorKeyPassword);
assertNotNull(guardedString);
assertTrue(StringUtils.isEmpty(guardedString.asString()));
guardedString = confidentialStorage.getGuardedString(provisioningArchiveDto, confidentialConnectorKeyPassword);
assertNotNull(guardedString);
assertTrue(StringUtils.isEmpty(guardedString.asString()));
}
}
List<AccAccountDto> accounts = accountService.getAccounts(system.getId(), identity.getId());
assertEquals(1, accounts.size());
AccAccountDto accountDto = accounts.get(0);
TestResource resource = this.helper.findResource(accountDto.getUid());
assertNotNull(resource);
assertEquals(DEFAULT_PASSWORD, resource.getPassword());
assertEquals(DEFAULT_PASSWORD + suffixForPassword, resource.getDescrip());
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class MappingContextTest method testMappingContextConnectorObject.
@Test
public void testMappingContextConnectorObject() {
SysSystemDto system = helper.createTestResourceSystem(true);
Assert.assertNotNull(system);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
Assert.assertNotNull(mapping);
// Create the description attribute (print context as string).
createDescriptionAttribute(system, mapping);
// Set context transformation to the mapping
// Add connector object to the context.
mapping.setAddContextConnectorObject(true);
mapping = initContextForMapping(mapping);
IdmRoleDto roleWithSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, system);
IdmIdentityDto identity = helper.createIdentity();
helper.createContract(identity, null, LocalDate.now(), null);
List<IdmIdentityContractDto> contracts = identityContractService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, contracts.size());
helper.createIdentityRole(identity, roleWithSystem, null, null);
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
assertEquals(identity.getFirstName(), resource.getFirstname());
MappingContext context = new MappingContext();
context.put("test", "TestValueOne");
assertEquals(context.toString(), resource.getDescrip());
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
IcConnectorObject connectorObject = systemEntityService.getConnectorObject(systemEntity);
Assert.assertNotNull(connectorObject);
// Invoke provisioning
identityService.save(identity);
resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
assertEquals(identity.getFirstName(), resource.getFirstname());
context = new MappingContext();
context.put("test", "TestValueOne");
context.setConnectorObject(connectorObject);
assertEquals(context.toString(), resource.getDescrip());
// Delete role mapping
systemMappingService.delete(mapping);
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method prepareProvisioningForAttribute.
private SysProvisioningOperationDto prepareProvisioningForAttribute(SysSystemEntityDto systemEntity, AttributeMapping attributeMapping, Object value, ProvisioningOperationType operationType, DTO dto) {
Assert.notNull(systemEntity, "System entity is required.");
Assert.notNull(systemEntity.getSystem(), "Relation to system is required for system entity.");
Assert.notNull(systemEntity.getEntityType(), "System entity type is required.");
Assert.notNull(systemEntity.getUid(), "System entity uid is required.");
Assert.notNull(attributeMapping, "Attribute mapping is required.");
SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attributeMapping);
if (!schemaAttributeDto.isUpdateable()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_SCHEMA_ATTRIBUTE_IS_NOT_UPDATEABLE, ImmutableMap.of("attribute", StringUtils.defaultIfBlank(attributeMapping.getIdmPropertyName(), attributeMapping.getName()), "entity", systemEntity.getUid()));
}
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(schemaAttributeDto.getObjectClass());
String objectClassName = schemaObjectClassDto.getObjectClassName();
// We do transformation to system if is attribute only constant
Object valueTransformed = value;
if (!attributeMapping.isEntityAttribute() && !attributeMapping.isExtendedAttribute()) {
// If is attribute handling resolve as constant, then we don't want
// do transformation again (was did in getAttributeValue)
} else {
valueTransformed = attributeMappingService.transformValueToResource(systemEntity.getUid(), value, attributeMapping, dto);
}
IcAttribute icAttributeForCreate = attributeMappingService.createIcAttribute(schemaAttributeDto, valueTransformed);
//
// Call IC modul for update single attribute
IcConnectorObject connectorObject = new IcConnectorObjectImpl(systemEntity.getUid(), new IcObjectClassImpl(objectClassName), ImmutableList.of(icAttributeForCreate));
SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(ProvisioningEventType.UPDATE).setSystemEntity(systemEntity).setEntityIdentifier(dto == null ? null : dto.getId()).setProvisioningContext(new ProvisioningContext(connectorObject));
//
return operationBuilder.build();
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class SysSystemEntityController method getConnectorObject.
@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@RequestMapping(value = "/{backendId}/connector-object", method = RequestMethod.GET)
@ApiOperation(value = "Connector object for the system entity", nickname = "getConnectorObject", response = IcConnectorObject.class, tags = { SysSystemEntityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }) })
public ResponseEntity<IcConnectorObject> getConnectorObject(@ApiParam(value = "System entity's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
SysSystemEntityDto systemEntity = this.getDto(backendId);
if (systemEntity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IcConnectorObject connectorObject = ((SysSystemEntityService) getService()).getConnectorObject(systemEntity, IdmBasePermission.READ);
if (connectorObject == null) {
return new ResponseEntity<IcConnectorObject>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<IcConnectorObject>(connectorObject, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject 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, "Provisioning operation is required for delete related confidential values.");
//
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