use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method executeStepFour.
/**
* Step for filling additional information as connector (OU) DNs. Enable protected mode. Add pairing sync.
*/
private void executeStepFour(ConnectorTypeDto connectorType) {
String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
String pairingSyncId = connectorType.getMetadata().get(PAIRING_SYNC_ID);
Assert.notNull(systemId, "System ID cannot be null!");
SysSystemDto systemDto = this.getSystemService().get(systemId);
connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
boolean pairingSyncSwitch = Boolean.parseBoolean(connectorType.getMetadata().get(PAIRING_SYNC_SWITCH_KEY));
String pairingSyncAttributeCode = connectorType.getMetadata().get(PAIRING_SYNC_DN_ATTR_KEY);
if (pairingSyncAttributeCode == null) {
pairingSyncAttributeCode = DN_ATTR_CODE;
}
boolean protectedModeSwitch = Boolean.parseBoolean(connectorType.getMetadata().get(PROTECTED_MODE_SWITCH_KEY));
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
String port = getValueFromConnectorInstance(PORT, systemDto, connectorFormDef);
String host = getValueFromConnectorInstance(HOST, systemDto, connectorFormDef);
String user = getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef);
boolean ssl = Boolean.parseBoolean(getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
String password = getConfidentialValueFromConnectorInstance(CREDENTIALS, systemDto, connectorFormDef);
String domainContainer = connectorType.getMetadata().get(DOMAIN_KEY);
Assert.notNull(domainContainer, "Domain cannot be null!");
String newUserContainer = connectorType.getMetadata().get(NEW_USER_CONTAINER_KEY);
Assert.notNull(newUserContainer, "Container for new users cannot be null!");
String searchUserContainer = connectorType.getMetadata().get(USER_SEARCH_CONTAINER_KEY);
Assert.notNull(searchUserContainer, "Container for search users cannot be null!");
String deleteUserContainer = null;
// Delete user container should be used only if protected mode is active.
if (protectedModeSwitch) {
deleteUserContainer = connectorType.getMetadata().get(DELETE_USER_CONTAINER_KEY);
}
String newUserContainerAD = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", newUserContainer), port, host, user, password, ssl);
if (Strings.isBlank(newUserContainerAD)) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", newUserContainer));
}
String searchUserContainerAD = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", searchUserContainer), port, host, user, password, ssl);
if (Strings.isBlank(searchUserContainerAD)) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", searchUserContainer));
}
if (Strings.isNotBlank(deleteUserContainer) && protectedModeSwitch) {
String deleteUserContainerAD = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", deleteUserContainer), port, host, user, password, ssl);
if (Strings.isBlank(deleteUserContainerAD)) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", deleteUserContainer));
}
}
IdmFormDefinitionDto operationOptionsFormDefinition = getSystemService().getOperationOptionsConnectorFormDefinition(systemDto);
if (operationOptionsFormDefinition != null) {
// Set domain to system's operation options.
operationOptionsFormDefinition = initFormAttributeDefinition(operationOptionsFormDefinition, DOMAIN_KEY, (short) 3);
setValueToConnectorInstance(DOMAIN_KEY, domainContainer, systemDto, operationOptionsFormDefinition);
// Set container for new users to system's operation options.
operationOptionsFormDefinition = initFormAttributeDefinition(operationOptionsFormDefinition, NEW_USER_CONTAINER_KEY, (short) 4);
setValueToConnectorInstance(NEW_USER_CONTAINER_KEY, newUserContainer, systemDto, operationOptionsFormDefinition);
// Set container for deleted users to system's operation options.
operationOptionsFormDefinition = initFormAttributeDefinition(operationOptionsFormDefinition, DELETE_USER_CONTAINER_KEY, (short) 5);
setValueToConnectorInstance(DELETE_USER_CONTAINER_KEY, deleteUserContainer, systemDto, operationOptionsFormDefinition);
// Set container for exists users to system's operation options.
operationOptionsFormDefinition = initFormAttributeDefinition(operationOptionsFormDefinition, USER_SEARCH_CONTAINER_KEY, (short) 6);
setValueToConnectorInstance(USER_SEARCH_CONTAINER_KEY, searchUserContainer, systemDto, operationOptionsFormDefinition);
}
String mappingSyncId = connectorType.getMetadata().get(MAPPING_SYNC_ID);
String mappingId = connectorType.getMetadata().get(MAPPING_ID);
if (mappingId == null && mappingSyncId == null) {
// This attributes will be updated only if system doesn't have mapping.
// Checking by existing mapping and not by reopen flag solves a problem with reopen wizard for to early closed wizard. For example in the certificate step.
initDefaultConnectorSettings(systemDto, connectorFormDef);
}
// Attributes below will updated everytime (for reopen system too).
// Base context for search users.
// We need to searching in all containers (for new, existed and deleted users). So all three values will be use in the base context.
List<Serializable> values = Lists.newArrayList(Sets.newHashSet(searchUserContainer, newUserContainer, deleteUserContainer));
this.setValueToConnectorInstance(BASE_CONTEXT_USER_KEY, values, systemDto, connectorFormDef);
// Set root suffixes and generate a schema.
SysSchemaObjectClassDto schemaDto = generateSchema(connectorType, systemDto, connectorFormDef, searchUserContainer, values);
// Find sAMAccountName attribute in the schema.
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setObjectClassId(schemaDto.getId());
schemaAttributeFilter.setSystemId(systemDto.getId());
schemaAttributeFilter.setName(SAM_ACCOUNT_NAME_ATTRIBUTE);
SysSchemaAttributeDto sAMAccountNameAttribute = schemaAttributeService.find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
if (sAMAccountNameAttribute == null) {
// Attribute missing -> create it now.
sAMAccountNameAttribute = createSchemaAttribute(schemaDto, SAM_ACCOUNT_NAME_ATTRIBUTE, String.class.getName(), true, true, false);
}
// Find __ENABLE__ attribute in the schema.
schemaAttributeFilter.setName(IcAttributeInfo.ENABLE);
SysSchemaAttributeDto enableAttribute = schemaAttributeService.find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
if (enableAttribute == null) {
// Attribute missing -> create it now.
createSchemaAttribute(schemaDto, IcAttributeInfo.ENABLE, Boolean.class.getName(), true, true, false);
}
// Find __PASSWORD__ attribute in the schema.
schemaAttributeFilter.setName(IcAttributeInfo.PASSWORD);
SysSchemaAttributeDto passwordAttribute = schemaAttributeService.find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
if (passwordAttribute == null) {
// Attribute missing -> create it now.
createSchemaAttribute(schemaDto, IcAttributeInfo.PASSWORD, GuardedString.class.getName(), false, true, false);
} else {
passwordAttribute.setUpdateable(true);
schemaAttributeService.save(passwordAttribute);
}
// Find Ldap groups attribute in the schema.
schemaAttributeFilter.setName(LDAP_GROUPS_ATTRIBUTE);
SysSchemaAttributeDto ldapGroupsAttribute = schemaAttributeService.find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
if (ldapGroupsAttribute == null) {
// Attribute missing -> create it now.
createSchemaAttribute(schemaDto, LDAP_GROUPS_ATTRIBUTE, String.class.getName(), true, true, true);
}
mappingId = connectorType.getMetadata().get(MAPPING_ID);
if (mappingId == null) {
// Create identity mapping for provisioning.
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setObjectClass(schemaDto.getId());
mappingDto.setOperationType(SystemOperationType.PROVISIONING);
mappingDto.setEntityType(SystemEntityType.IDENTITY);
mappingDto.setName("AD users provisioning mapping.");
mappingDto.setProtectionEnabled(protectedModeSwitch);
mappingDto = systemMappingService.publish(new SystemMappingEvent(SystemMappingEvent.SystemMappingEventType.CREATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, Boolean.TRUE))).getContent();
mappingDto = systemMappingService.save(mappingDto);
connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
connectorType.getMetadata().put(DefaultConnectorType.MAPPING_ID, mappingDto.getId().toString());
} else {
SysSystemMappingDto mappingDto = systemMappingService.get(UUID.fromString(mappingId));
// If protected mode switch changed, then mapping will be updated.
if (mappingDto.isProtectionEnabled() != protectedModeSwitch) {
mappingDto.setProtectionEnabled(protectedModeSwitch);
mappingDto = systemMappingService.save(mappingDto);
}
connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
}
if (pairingSyncSwitch) {
createPairingSync(connectorType, pairingSyncAttributeCode, schemaDto, schemaAttributeFilter, sAMAccountNameAttribute);
}
if (pairingSyncId != null) {
// If is protected mode activated, then set strategy to LINK_PROTECTED, otherwise set DO_NOT_LINK.
AbstractSysSyncConfigDto pairingSync = syncConfigService.get(UUID.fromString(pairingSyncId));
if (pairingSync instanceof SysSyncIdentityConfigDto) {
SysSyncIdentityConfigDto sync = (SysSyncIdentityConfigDto) pairingSync;
if (protectedModeSwitch) {
sync.setInactiveOwnerBehavior(SynchronizationInactiveOwnerBehaviorType.LINK_PROTECTED);
} else {
sync.setInactiveOwnerBehavior(SynchronizationInactiveOwnerBehaviorType.DO_NOT_LINK);
}
syncConfigService.save(sync);
}
}
}
use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class AbstractConnectorType method executeMappingStep.
/**
* Execute simple mapping step.
*
* @param connectorTypeDto
*/
private void executeMappingStep(ConnectorTypeDto connectorTypeDto) {
String schemaId = connectorTypeDto.getMetadata().get(SCHEMA_ID);
SysSchemaObjectClassDto schemaDto = null;
if (schemaId != null) {
schemaDto = schemaService.get(UUID.fromString(schemaId), IdmBasePermission.READ);
} else {
String systemId = connectorTypeDto.getMetadata().get(SYSTEM_DTO_KEY);
SysSchemaObjectClassFilter filter = new SysSchemaObjectClassFilter();
Assert.isTrue(Strings.isNotBlank(systemId), "System ID cannot be empty!");
filter.setSystemId(UUID.fromString(systemId));
List<SysSchemaObjectClassDto> schemas = schemaService.find(filter, null, IdmBasePermission.READ).getContent().stream().sorted(Comparator.comparing(SysSchemaObjectClassDto::getCreated)).collect(Collectors.toList());
if (!schemas.isEmpty()) {
schemaDto = schemas.get(0);
}
}
Assert.notNull(schemaDto, "System schema must exists!");
String entityType = connectorTypeDto.getMetadata().get(ENTITY_TYPE);
SystemEntityType systemEntityType = SystemEntityType.valueOf(entityType);
Assert.notNull(systemEntityType, "Entity type cannot be null!");
// For tree type have to be filled tree type ID too.
IdmTreeTypeDto treeTypeDto = null;
if (SystemEntityType.TREE == systemEntityType) {
String treeTypeId = connectorTypeDto.getMetadata().get(TREE_TYPE_ID);
Assert.notNull(treeTypeId, "Tree type ID cannot be null for TREE entity type!");
treeTypeDto = treeTypeService.get(UUID.fromString(treeTypeId));
Assert.notNull(treeTypeDto, "Tree type DTO cannot be null for TREE entity type!");
}
String operationType = connectorTypeDto.getMetadata().get(OPERATION_TYPE);
SystemOperationType systemOperationType = SystemOperationType.valueOf(operationType);
Assert.notNull(systemOperationType, "Operation type cannot be null!");
// Load existing mapping or create new one.
String mappingId = connectorTypeDto.getMetadata().get(MAPPING_ID);
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setName("Mapping");
boolean isNew = true;
if (mappingId != null) {
SysSystemMappingDto mappingExisted = systemMappingService.get(mappingId, IdmBasePermission.READ);
if (mappingExisted != null) {
isNew = false;
mappingDto = mappingExisted;
}
}
// For tree type have to be filled tree type ID too.
if (SystemEntityType.TREE == systemEntityType) {
mappingDto.setTreeType(treeTypeDto.getId());
}
mappingDto.setEntityType(systemEntityType);
mappingDto.setOperationType(systemOperationType);
mappingDto.setObjectClass(schemaDto.getId());
// Save mapping. Event must be publish with property for enable automatic mapping.
mappingDto = systemMappingService.publish(new SystemMappingEvent(isNew ? SystemMappingEvent.SystemMappingEventType.CREATE : SystemMappingEvent.SystemMappingEventType.UPDATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, Boolean.TRUE)), isNew ? IdmBasePermission.CREATE : IdmBasePermission.UPDATE).getContent();
connectorTypeDto.getEmbedded().put(MAPPING_DTO_KEY, mappingDto);
}
use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class TreeTypeDeleteProcessor method process.
@Override
public EventResult<IdmTreeTypeDto> process(EntityEvent<IdmTreeTypeDto> event) {
IdmTreeTypeDto treeType = event.getContent();
UUID treeTypeId = treeType.getId();
Asserts.notNull(treeTypeId, "Tree type identifier is required.");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
SysSystemMappingFilter filter = new SysSystemMappingFilter();
filter.setTreeTypeId(treeTypeId);
List<SysSystemMappingDto> mappings = systemMappingService.find(filter, null).getContent();
if (!forceDelete) {
long count = mappings.size();
if (count > 0) {
SysSystemDto systemDto = systemService.get(schemaObjectClassService.get(mappings.get(0).getObjectClass()).getSystem());
throw new TreeTypeException(AccResultCode.SYSTEM_MAPPING_TREE_TYPE_DELETE_FAILED, ImmutableMap.of("treeType", treeType.getCode(), "system", systemDto.getCode()));
}
} else {
mappings.forEach(mapping -> {
SystemMappingEvent mappingEvent = new SystemMappingEvent(SystemMappingEventType.DELETE, mapping);
//
systemMappingService.publish(mappingEvent, event);
});
}
// Delete link to sync contract configuration.
syncConfigRepository.findByDefaultTreeType(treeTypeId).forEach(config -> {
SysSyncContractConfigDto configDto = (SysSyncContractConfigDto) syncConfigService.get(config.getId());
configDto.setDefaultTreeType(null);
syncConfigService.save(configDto);
});
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemMappingServiceIntegrationTest method testAutomaticGenerateOfMappedAttributesTree.
@Test
public void testAutomaticGenerateOfMappedAttributesTree() {
SysSystemDto system = testHelper.createSystem(testHelper.createName());
SysSchemaObjectClassDto schema = this.createObjectClass(system);
createSchemaAttribute("__NAME__", schema);
createSchemaAttribute("parent", schema);
createSchemaAttribute("name", schema);
// redundant to __NAME__
createSchemaAttribute("code", schema);
createSchemaAttribute("description", schema);
createSchemaAttribute("not_exist", schema);
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setName(testHelper.createName());
mappingDto.setEntityType(SystemEntityType.TREE);
mappingDto.setObjectClass(schema.getId());
mappingDto.setOperationType(SystemOperationType.PROVISIONING);
mappingDto = mappingService.publish(new SystemMappingEvent(SystemMappingEvent.SystemMappingEventType.CREATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, true))).getContent();
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(mappingDto.getId());
List<SysSystemAttributeMappingDto> mappingAttributes = mappingAttributeService.find(attributeMappingFilter, null).getContent();
// Automatic attribute generating is enabled.
assertEquals(3, mappingAttributes.size());
SysSystemAttributeMappingDto primaryAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("__NAME__")).findFirst().orElse(null);
assertNotNull(primaryAttribute);
assertTrue(primaryAttribute.isUid());
assertEquals(IdmTreeNode_.code.getName(), primaryAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto nameAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("name")).findFirst().orElse(null);
assertNotNull(nameAttribute);
assertFalse(nameAttribute.isUid());
assertEquals(IdmTreeNode_.name.getName(), nameAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto parentAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("parent")).findFirst().orElse(null);
assertNotNull(parentAttribute);
assertFalse(parentAttribute.isUid());
assertEquals(IdmTreeNode_.parent.getName(), parentAttribute.getIdmPropertyName());
}
Aggregations