use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class SysSystemMappingServiceValidationTest method createSchemaAttribute.
/*
* Creates and returns attribute schema
*
* @param schemaObject
* @return schemaAttribute
*/
private SysSchemaAttributeDto createSchemaAttribute(UUID schemaObject) {
SysSchemaAttributeDto schemaAttribute = new SysSchemaAttributeDto();
schemaAttribute.setName("name_test" + System.currentTimeMillis());
schemaAttribute.setClassType("String");
schemaAttribute.setObjectClass(schemaObject);
return schemaAttributeService.save(schemaAttribute);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method createSchemaAttribute.
/**
* Create schema attribute.
*/
protected SysSchemaAttributeDto createSchemaAttribute(SysSchemaObjectClassDto schemaDto, String attributeName, String type, boolean returnByDefault, boolean updateable, boolean multivalued) {
SysSchemaAttributeDto attribute;
attribute = new SysSchemaAttributeDto();
attribute.setName(attributeName);
attribute.setClassType(type);
attribute.setObjectClass(schemaDto.getId());
attribute.setCreateable(true);
attribute.setReadable(true);
attribute.setMultivalued(multivalued);
attribute.setReturnedByDefault(returnByDefault);
attribute.setUpdateable(updateable);
return schemaAttributeService.save(attribute);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method processCreate.
/**
* Create object on target system
*
* @param provisioningOperation
*/
private void processCreate(SysProvisioningOperationDto provisioningOperation) {
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
ProvisioningContext provisioningContext = provisioningOperation.getProvisioningContext();
IcConnectorObject connectorObject = provisioningContext.getConnectorObject();
//
// prepare provisioning attributes from account attributes
Map<ProvisioningAttributeDto, Object> fullAccountObject = provisioningOperationService.getFullAccountObject(provisioningOperation);
if (fullAccountObject != null) {
connectorObject.getAttributes().clear();
SysSystemMappingDto mapping = getMapping(system, provisioningOperation.getEntityType());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
List<SysSchemaAttributeDto> schemaAttributes = findSchemaAttributes(system, schemaObjectClassDto);
List<SysSystemAttributeMappingDto> passwordAttributes = attributeMappingService.getAllPasswordAttributes(system.getId(), mapping.getId());
GuardedString generatedPassword = null;
// If exists at least one password attribute generate password and try set echos for current system
if (!passwordAttributes.isEmpty()) {
// Check if exists a uniform password for this entity. If yes, then use it.
if (provisioningOperation.getEntityIdentifier() != null && provisioningOperation.getEntityType() != null && provisioningOperation.getSystem() != null && provisioningOperation.getTransactionId() != null) {
if (uniformPasswordManager.isSystemInUniformPasswordAgenda(provisioningOperation.getSystem())) {
generatedPassword = uniformPasswordManager.generateUniformPassword(provisioningOperation.getEntityIdentifier(), provisioningOperation.getEntityType().getEntityType(), provisioningOperation.getTransactionId());
}
}
if (generatedPassword == null) {
generatedPassword = generatePassword(system);
}
} else {
generatedPassword = null;
}
// Found all given password from original provisioning context, these passwords will be skipped
List<ProvisioningAttributeDto> givenPasswords = provisioningContext.getAccountObject().keySet().stream().filter(provisioningAtt -> provisioningAtt.isPasswordAttribute()).collect(Collectors.toList());
// Iterate over all password attributes founded for system and mapping
for (SysSystemAttributeMappingDto passwordAttribute : passwordAttributes) {
// Password may be add by another process or execute existing provisioning operation, these password skip
SysSchemaAttributeDto schemaByPasswordAttribute = DtoUtils.getEmbedded(passwordAttribute, SysSystemAttributeMapping_.schemaAttribute, SysSchemaAttributeDto.class);
Optional<ProvisioningAttributeDto> findAnyPassword = //
givenPasswords.stream().filter(givenPassword -> givenPassword.getSchemaAttributeName().equals(//
schemaByPasswordAttribute.getName())).findAny();
if (findAnyPassword.isPresent()) {
continue;
}
// All non existing passwords in provisioning context will be added and
// transformed. Then will be set as new attribute into fullAccountObject
GuardedString transformPassword = transformPassword(provisioningOperation, system.getId(), passwordAttribute, generatedPassword);
SysSchemaAttributeDto schemaAttribute = //
schemaAttributes.stream().filter(//
schemaAtt -> schemaAtt.getId().equals(passwordAttribute.getSchemaAttribute())).findFirst().orElse(null);
ProvisioningAttributeDto passwordProvisiongAttributeDto = ProvisioningAttributeDto.createProvisioningAttributeKey(passwordAttribute, schemaAttribute.getName(), schemaAttribute.getClassType());
fullAccountObject.put(passwordProvisiongAttributeDto, transformPassword);
// Update previous account object (gui left side)
Map<ProvisioningAttributeDto, Object> accountObject = provisioningOperation.getProvisioningContext().getAccountObject();
// Is needed put password also into account object. Complete provisioning operation can be stored in
// queue and while retry the provisioning operation is value get from confidential storage.
// Confidential key is composed by account object.
String confidentialStrorageKey = provisioningOperationService.createAccountObjectPropertyKey(passwordProvisiongAttributeDto.getKey(), 0);
confidentialStorage.saveGuardedString(provisioningOperation, confidentialStrorageKey, transformPassword);
accountObject.put(passwordProvisiongAttributeDto, new ConfidentialString(confidentialStrorageKey));
}
for (Entry<ProvisioningAttributeDto, Object> entry : fullAccountObject.entrySet()) {
ProvisioningAttributeDto provisioningAttribute = entry.getKey();
Optional<SysSchemaAttributeDto> schemaAttributeOptional = schemaAttributes.stream().filter(schemaAttribute -> {
return provisioningAttribute.getSchemaAttributeName().equals(schemaAttribute.getName());
}).findFirst();
if (!schemaAttributeOptional.isPresent()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_SCHEMA_ATTRIBUTE_IS_FOUND, ImmutableMap.of("attribute", provisioningAttribute.getSchemaAttributeName()));
}
Object idmValue = fullAccountObject.get(provisioningAttribute);
SysSchemaAttributeDto schemaAttribute = schemaAttributeOptional.get();
if (provisioningAttribute.isSendOnlyIfNotNull()) {
if (this.isValueEmpty(idmValue)) {
// is null
continue;
}
}
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType() || AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
boolean existSetAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.SET == provisioningAttributeKey.getStrategyType();
});
boolean existIfResourceNulltAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttributeKey.getStrategyType();
});
boolean existMergeAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.MERGE == provisioningAttributeKey.getStrategyType();
});
boolean existAuthMergeAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.AUTHORITATIVE_MERGE == provisioningAttributeKey.getStrategyType();
});
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType()) {
if (existIfResourceNulltAttribute || existSetAttribute || existAuthMergeAttribute || existMergeAttribute) {
// (this strategies has higher priority)
continue;
}
}
if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
if (existSetAttribute || existAuthMergeAttribute || existMergeAttribute) {
// (this strategies has higher priority)
continue;
}
}
}
IcAttribute createdAttribute = createAttribute(schemaAttribute, fullAccountObject.get(provisioningAttribute));
if (createdAttribute != null) {
connectorObject.getAttributes().add(createdAttribute);
}
}
provisioningContext.setConnectorObject(connectorObject);
}
provisioningOperation.setOperationType(ProvisioningEventType.CREATE);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class SystemMappingIdentityAutoAttributesProcessor method process.
@Override
public EventResult<SysSystemMappingDto> process(EntityEvent<SysSystemMappingDto> event) {
SysSystemMappingDto dto = event.getContent();
UUID schemaId = dto.getObjectClass();
if (schemaId == null) {
return new DefaultEventResult<>(event, this);
}
List<SysSchemaAttributeDto> schemaAttributes = getSchemaAttributes(schemaId);
// UID attribute
SysSchemaAttributeDto primarySchemaAttribute = getSchemaAttributeByCatalogue(schemaAttributes, this.getPrimaryKeyCatalogue());
if (primarySchemaAttribute != null) {
createAttributeMappingBySchemaAttribute(dto, primarySchemaAttribute, IdmIdentity_.username.getName(), true);
}
// First name attribute
SysSchemaAttributeDto schemaAttribute = getSchemaAttributeByCatalogue(schemaAttributes, this.getFirstNameCatalogue());
if (schemaAttribute != null) {
createAttributeMappingBySchemaAttribute(dto, schemaAttribute, IdmIdentity_.firstName.getName(), false);
}
// Last name attribute
schemaAttribute = getSchemaAttributeByCatalogue(schemaAttributes, this.getLastNameCatalogue());
if (schemaAttribute != null) {
createAttributeMappingBySchemaAttribute(dto, schemaAttribute, IdmIdentity_.lastName.getName(), false);
}
// Email attribute
schemaAttribute = getSchemaAttributeByCatalogue(schemaAttributes, this.getEmailCatalogue());
if (schemaAttribute != null) {
createAttributeMappingBySchemaAttribute(dto, schemaAttribute, IdmIdentity_.email.getName(), false);
}
// Title before attribute
schemaAttribute = getSchemaAttributeByCatalogue(schemaAttributes, this.getTitleBeforeCatalogue());
if (schemaAttribute != null) {
createAttributeMappingBySchemaAttribute(dto, schemaAttribute, IdmIdentity_.titleBefore.getName(), false);
}
// Title after attribute
schemaAttribute = getSchemaAttributeByCatalogue(schemaAttributes, this.getTitleAfterCatalogue());
if (schemaAttribute != null) {
createAttributeMappingBySchemaAttribute(dto, schemaAttribute, IdmIdentity_.titleAfter.getName(), false);
}
// Phone attribute
schemaAttribute = getSchemaAttributeByCatalogue(schemaAttributes, this.getPhoneCatalogue());
if (schemaAttribute != null) {
createAttributeMappingBySchemaAttribute(dto, schemaAttribute, IdmIdentity_.phone.getName(), false);
}
// Password attribute
createAttributeMappingForPassword(dto, schemaAttributes);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class AdGroupConnectorTypeTest method createMemberSystem.
private SysSystemDto createMemberSystem() {
ConnectorType connectorType = connectorManager.getConnectorType(MockAdUserConnectorType.NAME);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
SysSystemDto systemDto = createSystem(this.getHelper().createName(), connectorTypeDto);
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
String newUserContainerMock = this.getHelper().createName();
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.NEW_USER_CONTAINER_KEY, newUserContainerMock);
String userContainerMock = this.getHelper().createName();
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.USER_SEARCH_CONTAINER_KEY, userContainerMock);
String deletedUserContainerMock = this.getHelper().createName();
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.DELETE_USER_CONTAINER_KEY, deletedUserContainerMock);
String domainMock = this.getHelper().createName();
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.DOMAIN_KEY, domainMock);
connectorTypeDto.setWizardStepName(MockAdUserConnectorType.STEP_FOUR);
// Generate mock schema.
generateMockMemberSchema(systemDto);
// Execute step four.
connectorManager.execute(connectorTypeDto);
// Check containers on the system's operationOptions.
systemDto = systemService.get(systemDto.getId());
IdmFormDefinitionDto operationOptionsFormDefinition = systemService.getOperationOptionsConnectorFormDefinition(systemDto);
String newUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.NEW_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
assertEquals(newUserContainerMock, newUserContainer);
String deletedUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.DELETE_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
// Protected mode is not active -> delete user container should be null.
assertNull(deletedUserContainer);
String searchUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.USER_SEARCH_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
assertEquals(userContainerMock, searchUserContainer);
String domain = getValueFromConnectorInstance(MockAdUserConnectorType.DOMAIN_KEY, systemDto, operationOptionsFormDefinition);
assertEquals(domainMock, domain);
// Check created schema attributes.
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> attributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.NAME.equals(attribute.getName())));
assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.PASSWORD.equals(attribute.getName())));
assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.ENABLE.equals(attribute.getName())));
assertTrue(attributes.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName())));
assertTrue(attributes.stream().anyMatch(attribute -> MockAdUserConnectorType.SAM_ACCOUNT_NAME_ATTRIBUTE.equals(attribute.getName())));
// Check created schema attributes.
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemId(systemDto.getId());
List<SysSystemAttributeMappingDto> attributeMappingDtos = attributeMappingService.find(attributeMappingFilter, null).getContent();
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.NAME.equals(attribute.getName())));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.PASSWORD.equals(attribute.getName())));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.ENABLE.equals(attribute.getName())));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName())));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName()) && AttributeMappingStrategyType.MERGE == attribute.getStrategyType()));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.SAM_ACCOUNT_NAME_ATTRIBUTE.equals(attribute.getName())));
return systemDto;
}
Aggregations