use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto 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.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class ComplexHrProcessIntegrationTest method initOrgStructure.
/**
* Creates organization structure common for all test cases
*/
private void initOrgStructure() {
IdmTreeNodeDto root = null;
IdmTreeNodeDto node = null;
// get tree type dto
IdmTreeTypeFilter typeFilt = new IdmTreeTypeFilter();
typeFilt.setCode(orgTreeTypeName);
IdmTreeTypeDto treeType = treeTypeService.find(typeFilt, null).getContent().get(0);
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setCode(rootNodeName);
filter.setTreeTypeId(treeType.getId());
List<IdmTreeNodeDto> roots = treeNodeService.find(filter, null).getContent();
if (roots.size() == 0) {
root = new IdmTreeNodeDto();
root.setCode(rootNodeName);
root.setName(rootNodeName);
root.setTreeType(treeType.getId());
root = treeNodeService.save(root);
} else {
root = roots.get(0);
}
// Department1
node = new IdmTreeNodeDto();
node.setCode(dep1NodeName);
node.setName(dep1NodeName);
node.setTreeType(treeType.getId());
node.setParent(root.getId());
node = treeNodeService.save(node);
// Department2
node = new IdmTreeNodeDto();
node.setCode(dep2NodeName);
node.setName(dep2NodeName);
node.setTreeType(treeType.getId());
node.setParent(root.getId());
node = treeNodeService.save(node);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class SystemExportBulkActionIntegrationTest method testExportAndImportMappingWithTreeType.
@Test
public void testExportAndImportMappingWithTreeType() {
SysSystemDto system = createSystem();
IdmTreeTypeDto treeType = helper.createTreeType();
// Load configurations
List<SysSystemMappingDto> mappings = findMappings(system);
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto originalMapping = mappings.get(0);
originalMapping.setTreeType(treeType.getId());
originalMapping = systemMappingService.save(originalMapping);
// Make export, upload, delete system and import
IdmExportImportDto importBatch = executeExportAndImport(system, SystemExportBulkAction.NAME);
system = systemService.get(system.getId());
Assert.assertNotNull(system);
mappings = findMappings(system);
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto mapping = mappings.get(0);
Assert.assertEquals(originalMapping.getId(), mapping.getId());
SysSchemaObjectClassDto objectClassDto = new SysSchemaObjectClassDto();
objectClassDto.setId(mapping.getObjectClass());
helper.createMappingSystem(SystemEntityType.ROLE, objectClassDto);
mappings = findMappings(system);
Assert.assertEquals(2, mappings.size());
// Remove original tree-type. And create new with same code (simulate a different IdM ... same tree-type with different IDs).
originalMapping.setTreeType(null);
originalMapping = systemMappingService.save(originalMapping);
treeTypeService.delete(treeType);
IdmTreeTypeDto newTreeType = helper.createTreeType(treeType.getCode());
// Execute import (check authoritative mode)
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
// Second mapping had to be deleted!
mappings = findMappings(system);
Assert.assertEquals(1, mappings.size());
mapping = mappings.get(0);
Assert.assertEquals(originalMapping.getId(), mapping.getId());
Assert.assertEquals(newTreeType.getId(), mapping.getTreeType());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultUniformPasswordManagerIntegrationTest method testUniformPassword.
@Test
public void testUniformPassword() {
try {
// Turn on an async execution.
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
SysSystemDto contractSystem = initData();
Assert.assertNotNull(contractSystem);
IdmTreeTypeDto treeType = helper.createTreeType();
AbstractSysSyncConfigDto config = doCreateSyncConfig(contractSystem, treeType);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
SysSystemDto targetSystemOne = helper.createTestResourceSystem(true);
// Create system two with account suffix "_targetSystemTwo".
String targetSystemTwoSuffix = "_targetSystemTwo";
SysSystemDto targetSystemTwo = helper.createTestResourceSystem(true);
// Create uniform password definition.
AccUniformPasswordDto uniformPasswordDef = createUniformPasswordDef(targetSystemOne, targetSystemTwo);
SysSystemMappingDto provisioningMapping = systemMappingService.findProvisioningMapping(targetSystemTwo.getId(), SystemEntityType.IDENTITY);
List<SysSystemAttributeMappingDto> attributeMappingDtos = schemaAttributeMappingService.findBySystemMapping(provisioningMapping);
SysSystemAttributeMappingDto uidAttribute = schemaAttributeMappingService.getUidAttribute(attributeMappingDtos, targetSystemTwo);
uidAttribute.setTransformToResourceScript("return attributeValue + \"" + targetSystemTwoSuffix + "\"");
schemaAttributeMappingService.save(uidAttribute);
IdmRoleDto automaticRoleTreeOne = helper.createRole();
helper.createRoleSystem(automaticRoleTreeOne, targetSystemOne);
IdmTreeNodeDto treeNodeOne = helper.createTreeNode(treeType, null);
helper.createAutomaticRole(automaticRoleTreeOne, treeNodeOne);
IdmRoleDto automaticRoleTreeTwo = helper.createRole();
helper.createRoleSystem(automaticRoleTreeTwo, targetSystemTwo);
IdmTreeNodeDto treeNodeTwo = helper.createTreeNode(treeType, null);
helper.createAutomaticRole(automaticRoleTreeTwo, treeNodeTwo);
IdmIdentityDto ownerOne = helper.createIdentityOnly();
List<TestContractResource> contractResources = Lists.newArrayList(this.createContract("1", ownerOne.getUsername(), null, "true", treeNodeOne.getCode(), null, null, null), this.createContract("2", ownerOne.getUsername(), null, "false", treeNodeTwo.getCode(), null, null, null));
this.getBean().initContractData(contractResources);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(ownerOne.getId());
contractService.find(contractFilter, null).getContent().forEach(contract -> contractService.delete(contract));
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setAddPasswordMetadata(true);
ownerOne = identityService.get(ownerOne.getId(), identityFilter);
// Identities should be in the CREATED state.
Assert.assertEquals(IdentityState.CREATED, ownerOne.getState());
Assert.assertNull(ownerOne.getPassword());
Assert.assertNull(ownerOne.getPasswordMetadata());
SynchronizationSchedulableTaskExecutor lrt = new SynchronizationSchedulableTaskExecutor(config.getId());
LongRunningFutureTask<Boolean> longRunningFutureTask = longRunningTaskManager.execute(lrt);
UUID transactionIdLrt = longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getTransactionId();
// Waiting for the LRT will be running.
getHelper().waitForResult(res -> {
return !longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).isRunning();
}, 50, 40);
// Waiting for the LRT will be EXECUTED.
getHelper().waitForResult(res -> {
return longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getResultState() != OperationState.EXECUTED;
}, 250, 100);
Assert.assertEquals(longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getResultState(), OperationState.EXECUTED);
SysSyncLogDto log = helper.checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
UUID transactionId = log.getTransactionId();
Assert.assertNotNull(transactionId);
Assert.assertEquals(transactionIdLrt, transactionId);
contractFilter.setIdentity(ownerOne.getId());
Assert.assertEquals(2, contractService.count(contractFilter));
ownerOne = identityService.get(ownerOne.getId());
// Identities should have a valid state.
Assert.assertEquals(IdentityState.VALID, ownerOne.getState());
// Waiting for removing entity state.
IdmIdentityDto finalOwnerOne = ownerOne;
getHelper().waitForResult(res -> {
return uniformPasswordManager.getEntityState(finalOwnerOne.getId(), IdmIdentityDto.class, transactionId) != null;
}, 50, 100);
// LRT ended, entityStates must be removed.
IdmEntityStateDto entityStateDtoOwnerOne = uniformPasswordManager.getEntityState(ownerOne.getId(), IdmIdentityDto.class, transactionId);
Assert.assertNull(entityStateDtoOwnerOne);
TestResource resourceOwnerOne = helper.findResource(ownerOne.getUsername());
Assert.assertNotNull(resourceOwnerOne);
TestResource resourceOwnerTwo = helper.findResource(ownerOne.getUsername() + targetSystemTwoSuffix);
Assert.assertNotNull(resourceOwnerTwo);
String passwordOwnerOne = resourceOwnerOne.getPassword();
String passwordOwnerTwo = resourceOwnerTwo.getPassword();
Assert.assertNotNull(passwordOwnerOne);
Assert.assertNotNull(passwordOwnerTwo);
Assert.assertEquals(passwordOwnerOne, passwordOwnerTwo);
// Change in the IdM is disabled.
ownerOne = identityService.get(ownerOne.getId(), identityFilter);
Assert.assertNull(ownerOne.getPassword());
Assert.assertNull(ownerOne.getPasswordMetadata());
// One uniform password notification was send.
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setRecipient(ownerOne.getUsername());
notificationFilter.setNotificationType(IdmEmailLog.class);
notificationFilter.setTopic(CoreModule.TOPIC_UNIFORM_PASSWORD_SET);
List<IdmNotificationLogDto> notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
Assert.assertEquals(1, notificationLogDtos.size());
// Check if notification contains code of uniform password group.
IdmNotificationLogDto uniformPasswordSetNotification = notificationLogDtos.get(0);
String notificationBody = uniformPasswordSetNotification.getMessage().getHtmlMessage();
Assert.assertTrue(notificationBody.contains(uniformPasswordDef.getCode()));
// None a new password notification was send.
notificationFilter.setTopic(AccModuleDescriptor.TOPIC_NEW_PASSWORD);
notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
Assert.assertEquals(0, notificationLogDtos.size());
// None password set notification was send.
notificationFilter.setTopic(CoreModule.TOPIC_PASSWORD_SET);
notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
Assert.assertEquals(0, notificationLogDtos.size());
// None password change notification was send.
notificationFilter.setTopic(CoreModule.TOPIC_PASSWORD_CHANGED);
notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
Assert.assertEquals(0, notificationLogDtos.size());
// Delete log
syncLogService.delete(log);
// Delete identities.
identityService.delete(ownerOne);
// Delete uniform password def.
uniformPasswordService.delete(uniformPasswordDef);
} finally {
// Turn off an async execution.
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultUniformPasswordManagerIntegrationTest method testDisableUniformPassword.
@Test
public void testDisableUniformPassword() {
try {
// Turn on an async execution.
getHelper().enableAsynchronousProcessing();
// Create password generate policy if missing.
createGeneratePolicy();
SysSystemDto contractSystem = initData();
Assert.assertNotNull(contractSystem);
IdmTreeTypeDto treeType = helper.createTreeType();
AbstractSysSyncConfigDto config = doCreateSyncConfig(contractSystem, treeType);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
SysSystemDto targetSystemOne = helper.createTestResourceSystem(true);
// Create system two with account suffix "_targetSystemTwo".
String targetSystemTwoSuffix = "_targetSystemTwo";
SysSystemDto targetSystemTwo = helper.createTestResourceSystem(true);
// Create uniform password definition.
AccUniformPasswordDto uniformPasswordDef = createUniformPasswordDef(targetSystemOne, targetSystemTwo);
// Disable an uniform password definition.
uniformPasswordDef.setDisabled(true);
uniformPasswordDef = uniformPasswordService.save(uniformPasswordDef);
SysSystemMappingDto provisioningMapping = systemMappingService.findProvisioningMapping(targetSystemTwo.getId(), SystemEntityType.IDENTITY);
List<SysSystemAttributeMappingDto> attributeMappingDtos = schemaAttributeMappingService.findBySystemMapping(provisioningMapping);
SysSystemAttributeMappingDto uidAttribute = schemaAttributeMappingService.getUidAttribute(attributeMappingDtos, targetSystemTwo);
uidAttribute.setTransformToResourceScript("return attributeValue + \"" + targetSystemTwoSuffix + "\"");
schemaAttributeMappingService.save(uidAttribute);
IdmRoleDto automaticRoleTreeOne = helper.createRole();
helper.createRoleSystem(automaticRoleTreeOne, targetSystemOne);
IdmTreeNodeDto treeNodeOne = helper.createTreeNode(treeType, null);
helper.createAutomaticRole(automaticRoleTreeOne, treeNodeOne);
IdmRoleDto automaticRoleTreeTwo = helper.createRole();
helper.createRoleSystem(automaticRoleTreeTwo, targetSystemTwo);
IdmTreeNodeDto treeNodeTwo = helper.createTreeNode(treeType, null);
helper.createAutomaticRole(automaticRoleTreeTwo, treeNodeTwo);
IdmIdentityDto ownerOne = helper.createIdentityOnly();
List<TestContractResource> contractResources = Lists.newArrayList(this.createContract("1", ownerOne.getUsername(), null, "true", treeNodeOne.getCode(), null, null, null), this.createContract("2", ownerOne.getUsername(), null, "false", treeNodeTwo.getCode(), null, null, null));
this.getBean().initContractData(contractResources);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(ownerOne.getId());
contractService.find(contractFilter, null).getContent().forEach(contract -> contractService.delete(contract));
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
ownerOne = identityService.get(ownerOne.getId());
// Identities should be in the CREATED state.
Assert.assertEquals(IdentityState.CREATED, ownerOne.getState());
SynchronizationSchedulableTaskExecutor lrt = new SynchronizationSchedulableTaskExecutor(config.getId());
LongRunningFutureTask<Boolean> longRunningFutureTask = longRunningTaskManager.execute(lrt);
UUID transactionIdLrt = longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getTransactionId();
// Waiting for the LRT will be running.
getHelper().waitForResult(res -> {
return !longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).isRunning();
}, 50, 40);
// Waiting for the LRT will be EXECUTED.
getHelper().waitForResult(res -> {
return longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getResultState() != OperationState.EXECUTED;
}, 250, 100);
Assert.assertEquals(OperationState.EXECUTED, longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getResultState());
SysSyncLogDto log = helper.checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
UUID transactionId = log.getTransactionId();
Assert.assertNotNull(transactionId);
Assert.assertEquals(transactionIdLrt, transactionId);
contractFilter.setIdentity(ownerOne.getId());
Assert.assertEquals(2, contractService.count(contractFilter));
ownerOne = identityService.get(ownerOne.getId());
// Identities should have a valid state.
Assert.assertEquals(IdentityState.VALID, ownerOne.getState());
// Uniform password feature is disabled -> password could be not same.
IdmEntityStateDto entityStateDtoOwnerOne = uniformPasswordManager.getEntityState(ownerOne.getId(), IdmIdentityDto.class, transactionId);
Assert.assertNull(entityStateDtoOwnerOne);
TestResource resourceOwnerOne = helper.findResource(ownerOne.getUsername());
Assert.assertNotNull(resourceOwnerOne);
TestResource resourceOwnerTwo = helper.findResource(ownerOne.getUsername() + targetSystemTwoSuffix);
Assert.assertNotNull(resourceOwnerTwo);
String passwordOwnerOne = resourceOwnerOne.getPassword();
String passwordOwnerTwo = resourceOwnerTwo.getPassword();
Assert.assertNotNull(passwordOwnerOne);
Assert.assertNotNull(passwordOwnerTwo);
// Uniform password feature is disabled -> password cannot be not same.
Assert.assertNotEquals(passwordOwnerOne, passwordOwnerTwo);
// None a uniform password notification was send.
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setRecipient(ownerOne.getUsername());
notificationFilter.setNotificationType(IdmEmailLog.class);
notificationFilter.setTopic(CoreModule.TOPIC_UNIFORM_PASSWORD_SET);
List<IdmNotificationLogDto> notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
Assert.assertEquals(0, notificationLogDtos.size());
// None a new password notification was send.
notificationFilter.setTopic(AccModuleDescriptor.TOPIC_NEW_PASSWORD);
notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
Assert.assertEquals(2, notificationLogDtos.size());
// None a password change notification was send.
notificationFilter.setTopic(CoreModule.TOPIC_PASSWORD_SET);
notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
Assert.assertEquals(0, notificationLogDtos.size());
// Delete log
syncLogService.delete(log);
// Delete identities.
identityService.delete(ownerOne);
// Delete uniform password def.
uniformPasswordService.delete(uniformPasswordDef);
} finally {
// Turn off an async execution.
getHelper().disableAsynchronousProcessing();
}
}
Aggregations