use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class PasswordPreValidationIntegrationTest method testAdvancedEnabled.
@Test
public void testAdvancedEnabled() {
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername("test" + System.currentTimeMillis());
identity.setFirstName("testFirst");
identity.setLastName("testSecond");
identity = idmIdentityService.save(identity);
//
SysSystemDto system = testHelper.createTestResourceSystem(true);
//
AccAccountDto acc = new AccAccountDto();
acc.setId(UUID.randomUUID());
acc.setUid(System.currentTimeMillis() + "");
acc.setAccountType(AccountType.PERSONAL);
acc.setSystem(system.getId());
//
acc = accountService.save(acc);
//
AccIdentityAccountDto account = testHelper.createIdentityAccount(system, identity);
account.setAccount(acc.getId());
account = accountIdentityService.save(account);
account.setOwnership(true);
List<String> accounts = new ArrayList<String>();
accounts.add(acc.getId() + "");
// password policy default
IdmPasswordPolicyDto policyDefault = new IdmPasswordPolicyDto();
policyDefault.setName(System.currentTimeMillis() + "test1");
policyDefault.setDefaultPolicy(true);
policyDefault.setMinPasswordLength(10);
policyDefault.setMaxPasswordLength(20);
policyDefault.setPasswordLengthRequired(true);
policyDefault.setMinUpperChar(5);
policyDefault.setUpperCharRequired(true);
policyDefault.setMinLowerChar(4);
policyDefault.setLowerCharRequired(true);
policyDefault.setEnchancedControl(true);
policyDefault.setMinRulesToFulfill(1);
policyDefault.setMinNumber(3);
policyDefault.setNumberRequired(false);
policyDefault.setMinSpecialChar(6);
policyDefault.setSpecialCharRequired(false);
policyDefault.setIdentityAttributeCheck("");
// password policy
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName(System.currentTimeMillis() + "test2");
policy.setDefaultPolicy(false);
policy.setMinPasswordLength(9);
policy.setMaxPasswordLength(21);
policy.setPasswordLengthRequired(true);
policy.setMinUpperChar(4);
policy.setUpperCharRequired(true);
policy.setMinLowerChar(3);
policy.setLowerCharRequired(true);
policy.setEnchancedControl(true);
policy.setMinRulesToFulfill(1);
policy.setMinNumber(5);
policy.setNumberRequired(false);
policy.setMinSpecialChar(4);
policy.setSpecialCharRequired(false);
policy.setIdentityAttributeCheck("");
policyDefault = passwordPolicyService.save(policyDefault);
policy = passwordPolicyService.save(policy);
system.setPasswordPolicyValidate(policy.getId());
systemService.save(system);
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setIdm(true);
passwordChange.setAccounts(accounts);
passwordChange.setAll(true);
try {
idmIdentityService.validatePassword(passwordChange);
} catch (ResultCodeException ex) {
Map<String, Object> parametrs = new HashMap<String, Object>();
parametrs.put("minNumber", 3);
parametrs.put("minSpecialChar", 6);
assertEquals(10, ex.getError().getError().getParameters().get("minLength"));
assertEquals(20, ex.getError().getError().getParameters().get("maxLength"));
assertEquals(5, ex.getError().getError().getParameters().get("minUpperChar"));
assertEquals(4, ex.getError().getError().getParameters().get("minLowerChar"));
assertEquals(parametrs.toString(), ex.getError().getError().getParameters().get("minRulesToFulfill").toString());
;
assertEquals(policy.getName() + ", " + policyDefault.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
// special char base -> 8
assertEquals(8, ex.getError().getError().getParameters().size());
policyDefault.setDefaultPolicy(false);
passwordPolicyService.save(policyDefault);
}
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method deleteContractAccountTest.
@Test
public void deleteContractAccountTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contracts.size());
// Find the account for this contract
IdmIdentityContractDto contract = contracts.get(0);
AccContractAccountFilter contractAccountFilter = new AccContractAccountFilter();
contractAccountFilter.setContractId(contract.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractAccountDto> contractAccounts = contractAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete this account directly test
accountService.delete(account);
account = accountService.get(contractAccount.getAccount());
Assert.assertNull(account);
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method getValueByMappedAttribute.
@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
if (transformedValue != null && PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
String parentUid = transformedValue.toString();
SysSystemMappingDto systemMapping = systemMappingService.get(((SysSystemAttributeMappingDto) attribute).getSystemMapping());
SysSchemaObjectClassDto schemaObjectClass = schemaObjectClassService.get(systemMapping.getObjectClass());
UUID systemId = schemaObjectClass.getSystem();
// Find account by UID from parent field
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setUid(parentUid);
accountFilter.setSystemId(systemId);
transformedValue = null;
List<AccAccountDto> parentAccounts = accountService.find(accountFilter, null).getContent();
if (!parentAccounts.isEmpty()) {
UUID parentAccount = parentAccounts.get(0).getId();
// Find relation between tree and account
AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
treeAccountFilter.setAccountId(parentAccount);
List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
if (!treeAccounts.isEmpty()) {
// Find parent tree node by ID
// TODO: resolve more treeAccounts situations
// parent uuid - we are working with dtos
transformedValue = treeAccounts.get(0).getTreeNode();
} else {
LOG.warn("For parent UID: [{}] on system ID [{}] and acc account: [{}], was not found tree accounts! Return null value in parent!!", parentUid, systemId, parentAccount);
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_TREE_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId, "parentAccount", parentAccount));
}
} else {
LOG.warn("For parent UID: [{}] on system ID [{}], was not found parents account! Return null value in parent!!", parentUid, systemId);
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId));
}
}
return transformedValue;
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class AsynchronousAccountManagementIntegrationTest method testAsynchronousAccountManagementError.
@Test
public void testAsynchronousAccountManagementError() {
// add error to some script
SysSystemDto system = helper.createTestResourceSystem(true);
SysSystemMappingDto mapping = helper.getDefaultMapping(system);
SysSystemAttributeMappingDto attributeHandlingUserName = schemaAttributeHandlingService.findBySystemMappingAndName(mapping.getId(), TestHelper.ATTRIBUTE_MAPPING_NAME);
// username is transformed with error
attributeHandlingUserName.setTransformToResourceScript("returan \"" + "error" + "\";");
attributeHandlingUserName = schemaAttributeHandlingService.save(attributeHandlingUserName);
IdmIdentityDto identity = helper.createIdentity();
IdmRoleDto role = helper.createRole();
helper.createRoleSystem(role, system);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
try {
helper.waitForResult(res -> {
return !(entityEventService.findByState(configurationService.getInstanceId(), OperationState.CREATED).isEmpty() && entityEventService.findByState(configurationService.getInstanceId(), OperationState.RUNNING).isEmpty());
});
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNull(account);
//
// find event result with exception
IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
eventFilter.setOwnerId(identityRole.getId());
eventFilter.setStates(Lists.newArrayList(OperationState.EXCEPTION));
List<IdmEntityEventDto> failedEvents = entityEventService.find(eventFilter, null).getContent();
//
Assert.assertEquals(1, failedEvents.size());
Assert.assertEquals(CoreResultCode.GROOVY_SCRIPT_EXCEPTION.getCode(), failedEvents.get(0).getResult().getCode());
} finally {
identityService.delete(identity);
systemService.delete(system);
}
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class AsynchronousAccountManagementIntegrationTest method testAsynchronousAccountManagementGreenLine.
@Test
public void testAsynchronousAccountManagementGreenLine() {
IdmIdentityDto identity = helper.createIdentity();
SysSystemDto system = helper.createTestResourceSystem(true);
IdmRoleDto role = helper.createRole();
helper.createRoleSystem(role, system);
helper.createIdentityRole(identity, role);
try {
helper.waitForResult(res -> {
return !(entityEventService.findByState(configurationService.getInstanceId(), OperationState.CREATED).isEmpty() && entityEventService.findByState(configurationService.getInstanceId(), OperationState.RUNNING).isEmpty());
});
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertNotNull(helper.findResource(account.getRealUid()));
} finally {
identityService.delete(identity);
systemService.delete(system);
}
}
Aggregations