use of eu.bcvsolutions.idm.acc.entity.TestResource 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.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method initIdentityData.
@Transactional
public void initIdentityData(String username, String email) {
deleteAllResourceData();
TestResource resourceUserOne = new TestResource();
resourceUserOne.setName(username);
resourceUserOne.setFirstname(username);
resourceUserOne.setLastname(username);
resourceUserOne.setEavAttribute("1");
resourceUserOne.setEmail(email);
entityManager.persist(resourceUserOne);
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class DefaultRoleSynchronizationExecutorTest method testSyncRolesAssignToUsers.
@Test
public void testSyncRolesAssignToUsers() {
AbstractSysSyncConfigDto syncConfigCustom = createSyncConfig();
SysSystemDto userSystem = helper.createTestResourceSystem(true);
List<SysSystemMappingDto> userSystemMappings = systemMappingService.findBySystem(userSystem, SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY);
Assert.assertNotNull(userSystemMappings);
Assert.assertEquals(1, userSystemMappings.size());
SysSystemMappingDto userMappingDto = userSystemMappings.get(0);
// Switch to the sync.
userMappingDto.setOperationType(SystemOperationType.SYNCHRONIZATION);
userMappingDto = systemMappingService.save(userMappingDto);
SysSyncIdentityConfigDto userSyncConfig = createUserSyncConfig(userSystem);
List<SysSystemAttributeMappingDto> attributeMappingDtos = schemaAttributeMappingService.findBySystemMapping(userMappingDto);
SysSystemAttributeMappingDto userEmailAttribute = attributeMappingDtos.stream().filter(attribute -> attribute.getName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_EMAIL)).findFirst().orElse(null);
Assert.assertNotNull(userEmailAttribute);
SysSystemAttributeMappingDto enableAttribute = attributeMappingDtos.stream().filter(attribute -> attribute.getName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_ENABLE)).findFirst().orElse(null);
Assert.assertNotNull(enableAttribute);
enableAttribute.setDisabledAttribute(true);
attributeMappingService.save(enableAttribute);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
Assert.assertTrue(syncConfigCustom instanceof SysSyncRoleConfigDto);
SysSyncRoleConfigDto roleConfigDto = (SysSyncRoleConfigDto) syncConfigCustom;
SysSystemMappingDto systemMappingDto = DtoUtils.getEmbedded(syncConfigCustom, SysSyncConfig_.systemMapping, SysSystemMappingDto.class);
SysSchemaObjectClassDto schemaObjectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
UUID roleSystemId = schemaObjectClassDto.getSystem();
Assert.assertNotNull(roleSystemId);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(roleSystemId);
schemaAttributeFilter.setObjectClassId(schemaObjectClassDto.getId());
SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.find(schemaAttributeFilter, null).getContent().stream().filter(attribute -> attribute.getName().equalsIgnoreCase("name")).findFirst().orElse(null);
Assert.assertNotNull(schemaAttributeDto);
SysSystemDto roleSystemDto = new SysSystemDto();
roleSystemDto.setId(roleSystemId);
List<SysSystemMappingDto> roleSystemMappings = systemMappingService.findBySystem(roleSystemDto, SystemOperationType.SYNCHRONIZATION, SystemEntityType.ROLE);
Assert.assertNotNull(roleSystemMappings);
Assert.assertEquals(1, roleSystemMappings.size());
SysSystemMappingDto roleMappingDto = roleSystemMappings.get(0);
// Create mapping attribute for get ID of role.
SysSystemAttributeMappingDto roleIdAttribute = new SysSystemAttributeMappingDto();
roleIdAttribute.setEntityAttribute(true);
roleIdAttribute.setUid(false);
roleIdAttribute.setSystemMapping(roleMappingDto.getId());
roleIdAttribute.setExtendedAttribute(false);
roleIdAttribute.setIdmPropertyName(RoleSynchronizationExecutor.ROLE_MEMBERSHIP_ID_FIELD);
roleIdAttribute.setSchemaAttribute(schemaAttributeDto.getId());
roleIdAttribute.setName(helper.createName());
attributeMappingService.save(roleIdAttribute);
String usernameOne = getHelper().createName();
String usernameTwo = getHelper().createName();
// Create mapping attribute for get ID of role.
SysSystemAttributeMappingDto membersRoleAttribute = new SysSystemAttributeMappingDto();
membersRoleAttribute.setEntityAttribute(true);
membersRoleAttribute.setUid(false);
membersRoleAttribute.setSystemMapping(roleMappingDto.getId());
membersRoleAttribute.setExtendedAttribute(false);
membersRoleAttribute.setIdmPropertyName(RoleSynchronizationExecutor.ROLE_MEMBERS_FIELD);
membersRoleAttribute.setSchemaAttribute(schemaAttributeDto.getId());
membersRoleAttribute.setName(helper.createName());
membersRoleAttribute.setTransformFromResourceScript("return ['" + usernameOne + "', '" + usernameTwo + "'];");
membersRoleAttribute = attributeMappingService.save(membersRoleAttribute);
SysSchemaAttributeFilter schemaUserAttributeFilter = new SysSchemaAttributeFilter();
schemaUserAttributeFilter.setSystemId(userSystem.getId());
SysSchemaAttributeDto nameUserSchemaAttribute = schemaAttributeService.find(schemaUserAttributeFilter, null).getContent().stream().filter(attribute -> "name".equalsIgnoreCase(attribute.getName())).findFirst().orElse(null);
Assert.assertNotNull(nameUserSchemaAttribute);
// Enable membership, assign role to users, and use the user system.
roleConfigDto.setMembershipSwitch(true);
roleConfigDto.setMemberSystemMapping(userMappingDto.getId());
roleConfigDto.setMemberOfAttribute(enableAttribute.getId());
roleConfigDto.setAssignRoleSwitch(true);
roleConfigDto.setRoleMembersMappingAttribute(membersRoleAttribute.getId());
roleConfigDto.setMemberIdentifierAttribute(nameUserSchemaAttribute.getId());
roleConfigDto = (SysSyncRoleConfigDto) syncConfigService.save(roleConfigDto);
Assert.assertNotNull(roleConfigDto.getMemberOfAttribute());
Assert.assertNotNull(roleConfigDto.getRoleIdentifiersMappingAttribute());
Assert.assertNotNull(roleConfigDto.getRoleMembersMappingAttribute());
Assert.assertNotNull(roleConfigDto.getMemberIdentifierAttribute());
// Init users on system.
helper.deleteAllResourceData();
TestResource resource = new TestResource();
resource.setName(usernameOne);
resource.setFirstname(usernameOne);
resource.setLastname(usernameOne);
helper.saveResource(resource);
resource.setName(usernameTwo);
resource.setFirstname(usernameTwo);
resource.setLastname(usernameTwo);
helper.saveResource(resource);
// Start sync of users
helper.startSynchronization(userSyncConfig);
helper.checkSyncLog(userSyncConfig, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.SUCCESS);
IdmIdentityDto identityOne = identityService.getByUsername(usernameOne);
Assert.assertNotNull(identityOne);
IdmIdentityDto identityTwo = identityService.getByUsername(usernameTwo);
Assert.assertNotNull(identityTwo);
// Start sync of roles
helper.startSynchronization(syncConfigCustom);
//
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.CREATE_ENTITY, 5, OperationResultType.SUCCESS);
AccRoleAccountFilter roleAccountFilter = new AccRoleAccountFilter();
roleAccountFilter.setSystemId(roleSystemId);
List<AccRoleAccountDto> roleAccountDtos = roleAccountService.find(roleAccountFilter, null).getContent();
Assert.assertEquals(5, roleAccountDtos.size());
// Every role should be assigned to userOne and userTwo.
roleAccountDtos.forEach(roleAccountDto -> {
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(roleAccountDto.getRole());
identityRoleFilter.setIdentityId(identityOne.getId());
Assert.assertEquals(1, identityRoleService.find(identityRoleFilter, null).getContent().size());
identityRoleFilter.setIdentityId(identityTwo.getId());
Assert.assertEquals(1, identityRoleService.find(identityRoleFilter, null).getContent().size());
});
cleanAfterTest(syncConfigCustom, roleSystemId, log, roleAccountDtos);
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testNotExecutedOperationOnDisabledSystem.
@Test
public void testNotExecutedOperationOnDisabledSystem() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
system.setReadonly(true);
system = systemService.save(system);
IdmRoleDto role = getHelper().createRole();
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
getHelper().createRoleSystem(role, system);
getHelper().assignRoles(contract, role);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(system.getId());
List<SysProvisioningOperationDto> provisionings = provisioningOperationService.find(filter, null).getContent();
assertEquals(1, provisionings.size());
assertEquals(OperationState.NOT_EXECUTED, provisionings.get(0).getResultState());
String uid = provisionings.get(0).getSystemEntityUid();
// Account cannot exist now
TestResource resource = getHelper().findResource(uid);
Assert.assertNull(resource);
// Set system as enabled.
system.setReadonly(false);
system = systemService.save(system);
// Execute the provisioning -> System is enabled now, but in provisioning queue
// is active operation -> so next provisioning cannot be executed!
identitySerivce.save(identity);
// Account cannot exist now
resource = getHelper().findResource(uid);
Assert.assertNull(resource);
provisionings = provisioningOperationService.find(filter, null).getContent();
assertEquals(2, provisionings.size());
assertEquals(OperationState.NOT_EXECUTED, provisionings.get(0).getResultState());
assertEquals(OperationState.NOT_EXECUTED, provisionings.get(1).getResultState());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testRunningOperationInQueue.
@Test
public void testRunningOperationInQueue() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
system.setQueue(true);
system = systemService.save(system);
//
// create test provisioning context
SysProvisioningOperationDto provisioningOperation = createProvisioningOperation(system, "firstname");
Map<ProvisioningAttributeDto, Object> accoutObject = provisioningOperation.getProvisioningContext().getAccountObject();
String uid = (String) accoutObject.get(getProvisioningAttribute(TestHelper.ATTRIBUTE_MAPPING_NAME));
//
// publish event
provisioningExecutor.execute(provisioningOperation);
// is necessary to get again operation from service
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemEntity(provisioningOperation.getSystemEntity());
filter.setSystemId(system.getId());
SysProvisioningOperationDto operation = provisioningOperationService.find(filter, null).getContent().get(0);
assertEquals(OperationState.CREATED, operation.getResultState());
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
assertTrue(systemEntity.isWish());
assertNull(getHelper().findResource(uid));
SysProvisioningBatchDto batch = DtoUtils.getEmbedded(operation, SysProvisioningOperation_.batch);
Assert.assertNull(batch.getNextAttempt());
//
// set operation state to running manually
operation.getResult().setState(OperationState.RUNNING);
operation = provisioningOperationService.save(operation);
//
// created the second operation
ProvisioningContext context = new ProvisioningContext();
String firstname = "firstname2";
accoutObject = createAccountObject(systemEntity, firstname);
context.setAccountObject(accoutObject);
//
// prepare provisioning operation
SysSystemMappingDto systemMapping = getHelper().getDefaultMapping(system);
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassService.get(systemMapping.getObjectClass()).getObjectClassName());
IcConnectorObject connectorObject = new IcConnectorObjectImpl(null, objectClass, null);
SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(ProvisioningOperationType.CREATE).setSystemEntity(systemEntity).setProvisioningContext(new ProvisioningContext(accoutObject, connectorObject));
SysProvisioningOperationDto secondOperation = operationBuilder.build();
// for quick search
secondOperation.setId(UUID.randomUUID());
//
// publish event
provisioningExecutor.execute(secondOperation);
//
secondOperation = provisioningOperationService.get(secondOperation);
batch = provisioningBatchService.get(batch);
Assert.assertNotNull(batch.getNextAttempt());
//
// retry - the operation is still running
RetryProvisioningTaskExecutor retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
Boolean result = longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
Assert.assertTrue(result);
operation = provisioningOperationService.get(operation);
secondOperation = provisioningOperationService.get(secondOperation);
//
Assert.assertEquals(OperationState.RUNNING, operation.getResultState());
Assert.assertEquals(OperationState.NOT_EXECUTED, secondOperation.getResultState());
//
operation.getResult().setState(OperationState.EXECUTED);
operation = provisioningOperationService.save(operation);
// Account cannot exist now
TestResource resource = getHelper().findResource(uid);
Assert.assertNull(resource);
//
// retry - expected success now
retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
result = longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
Assert.assertTrue(result);
//
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
Assert.assertFalse(systemEntity.isWish());
resource = getHelper().findResource(uid);
Assert.assertNotNull(resource);
Assert.assertEquals(firstname, resource.getFirstname());
batch = provisioningBatchService.get(batch.getId());
Assert.assertNull(batch.getNextAttempt());
}
Aggregations