Search in sources :

Example 31 with IdmPasswordPolicyDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.

the class PasswordPreValidationIntegrationTest method testLenght.

@Test
public void testLenght() {
    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.setOwnership(true);
    account = accountIdentityService.save(account);
    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(5);
    policyDefault.setMaxPasswordLength(10);
    // password policy
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName(System.currentTimeMillis() + "test2");
    policy.setDefaultPolicy(false);
    policy.setMinPasswordLength(6);
    policy.setMaxPasswordLength(11);
    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) {
        assertEquals(6, ex.getError().getError().getParameters().get("minLength"));
        assertEquals(10, ex.getError().getError().getParameters().get("maxLength"));
        assertEquals(policy.getName() + ", " + policyDefault.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
        assertEquals(3, ex.getError().getError().getParameters().size());
        policyDefault.setDefaultPolicy(false);
        passwordPolicyService.save(policyDefault);
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) ArrayList(java.util.ArrayList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 32 with IdmPasswordPolicyDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.

the class IdentityPasswordPreValidateDefinitionProcessor method process.

@Override
public EventResult<PasswordChangeDto> process(EntityEvent<PasswordChangeDto> event) {
    PasswordChangeDto passwordChangeDto = event.getContent();
    IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
    List<IdmPasswordPolicyDto> passwordPolicyList = validateDefinition(passwordChangeDto);
    this.passwordPolicyService.preValidate(passwordValidationDto, passwordPolicyList);
    return new DefaultEventResult<>(event, this);
}
Also used : IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 33 with IdmPasswordPolicyDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningServiceTest method initData.

private void initData() {
    IdmIdentityDto identity;
    AccAccountDto accountOne;
    AccIdentityAccountDto accountIdentityOne;
    // create test system
    SysSystemDto system = helper.createSystem(TestResource.TABLE_NAME, SYSTEM_NAME);
    // set default generate password policy for system
    IdmPasswordPolicyDto passwordPolicy = new IdmPasswordPolicyDto();
    passwordPolicy.setName(PASSWORD_POLICY);
    passwordPolicy.setType(IdmPasswordPolicyType.GENERATE);
    passwordPolicy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    passwordPolicy.setLowerCharBase("a");
    passwordPolicy.setMinPasswordLength(2);
    passwordPolicy.setMaxPasswordLength(2);
    passwordPolicy.setMinLowerChar(2);
    passwordPolicy = passwordPolicyService.save(passwordPolicy);
    system.setPasswordPolicyGenerate(passwordPolicy.getId());
    system = systemService.save(system);
    // generate schema for system
    List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
    // Create test identity for provisioning test
    identity = new IdmIdentityDto();
    identity.setUsername(IDENTITY_USERNAME);
    identity.setFirstName(IDENTITY_USERNAME);
    identity.setLastName(IDENTITY_USERNAME);
    identity = idmIdentityService.save(identity);
    accountOne = new AccAccountDto();
    accountOne.setSystem(system.getId());
    accountOne.setUid("x" + IDENTITY_USERNAME);
    accountOne.setAccountType(AccountType.PERSONAL);
    accountOne.setEntityType(SystemEntityType.IDENTITY);
    accountOne = accountService.save(accountOne);
    accountIdentityOne = new AccIdentityAccountDto();
    accountIdentityOne.setIdentity(identity.getId());
    accountIdentityOne.setOwnership(true);
    accountIdentityOne.setAccount(accountOne.getId());
    accountIdentityOne = identityAccoutnService.save(accountIdentityOne);
    IdmIdentityDto identityTwo = new IdmIdentityDto();
    identityTwo.setUsername(IDENTITY_USERNAME_TWO);
    identityTwo.setFirstName(IDENTITY_USERNAME_TWO);
    identityTwo.setLastName(IDENTITY_USERNAME_TWO);
    identityTwo = idmIdentityService.save(identityTwo);
    AccAccountDto accountTwo = new AccAccountDto();
    accountTwo.setSystem(system.getId());
    accountTwo.setUid("x" + IDENTITY_USERNAME_TWO);
    accountTwo.setAccountType(AccountType.PERSONAL);
    accountTwo.setEntityType(SystemEntityType.IDENTITY);
    accountTwo = accountService.save(accountTwo);
    AccIdentityAccountDto accountIdentityTwo = new AccIdentityAccountDto();
    accountIdentityTwo.setIdentity(identityTwo.getId());
    accountIdentityTwo.setOwnership(true);
    accountIdentityTwo.setAccount(accountTwo.getId());
    accountIdentityTwo = identityAccoutnService.save(accountIdentityTwo);
    SysSystemMappingDto systemMapping = new SysSystemMappingDto();
    systemMapping.setName("default_" + System.currentTimeMillis());
    systemMapping.setEntityType(SystemEntityType.IDENTITY);
    systemMapping.setOperationType(SystemOperationType.PROVISIONING);
    systemMapping.setObjectClass(objectClasses.get(0).getId());
    final SysSystemMappingDto entityHandlingResult = systemEntityHandlingService.save(systemMapping);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(system.getId());
    Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
    schemaAttributesPage.forEach(schemaAttr -> {
        if ("__NAME__".equals(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setUid(true);
            attributeMapping.setEntityAttribute(true);
            attributeMapping.setIdmPropertyName(IdmIdentity_.username.getName());
            attributeMapping.setTransformToResourceScript("if(attributeValue){return \"x\"+ attributeValue;}");
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        } else if ("firstname".equalsIgnoreCase(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setIdmPropertyName(IdmIdentity_.firstName.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setTransformFromResourceScript("if(attributeValue){return attributeValue.substring(1);}");
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        } else if ("lastname".equalsIgnoreCase(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setIdmPropertyName(IdmIdentity_.lastName.getName());
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        } else if (IcConnectorFacade.PASSWORD_ATTRIBUTE_NAME.equalsIgnoreCase(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setIdmPropertyName("password");
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        } else if ("email".equalsIgnoreCase(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setIdmPropertyName(IdmIdentity_.email.getName());
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setStrategyType(AttributeMappingStrategyType.CREATE);
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping.setTransformToResourceScript("return \"" + EMAIL_ONE + "\";");
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        }
    });
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 34 with IdmPasswordPolicyDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordPolicyIntegrationTest method testCreateTwoDefaultPolicy.

@Test
public void testCreateTwoDefaultPolicy() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_18_default");
    policy.setType(IdmPasswordPolicyType.VALIDATE);
    policy.setDefaultPolicy(true);
    policy = saveInTransaction(policy, passwordPolicyService);
    IdmPasswordPolicyDto defaultValidatePolicy = this.passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.VALIDATE);
    assertEquals(policy.getId(), defaultValidatePolicy.getId());
    assertEquals(policy.getName(), defaultValidatePolicy.getName());
    assertEquals(policy.getType(), defaultValidatePolicy.getType());
    IdmPasswordPolicyDto policyNew = new IdmPasswordPolicyDto();
    policyNew.setName("test_19_default");
    policyNew.setType(IdmPasswordPolicyType.VALIDATE);
    policyNew.setDefaultPolicy(true);
    policyNew = saveInTransaction(policyNew, passwordPolicyService);
    defaultValidatePolicy = this.passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.VALIDATE);
    assertEquals(policyNew.getId(), defaultValidatePolicy.getId());
    assertEquals(policyNew.getName(), defaultValidatePolicy.getName());
    assertEquals(policyNew.getType(), defaultValidatePolicy.getType());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 35 with IdmPasswordPolicyDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordPolicyIntegrationTest method testValidationProhibitedChars.

@Test
public void testValidationProhibitedChars() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_14");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(5);
    policy.setMinPasswordLength(1);
    policy.setProhibitedCharacters("12abcDEF!@");
    IdmPasswordValidationDto password = new IdmPasswordValidationDto();
    try {
        password.setPassword("test");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("ABde");
        this.passwordPolicyService.validate(password, policy);
    } catch (Exception e) {
        fail("Password validate prohibited characters. " + policy);
    }
    try {
        password.setPassword("tEst");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validate prohibited characters. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("eddD");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validate prohibited characters. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("5416");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validate prohibited characters. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("test!");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validate prohibited characters. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)49 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)33 Test (org.junit.Test)33 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)13 ArrayList (java.util.ArrayList)11 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)9 IdmPasswordValidationDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto)9 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)8 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)7 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)6 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)6 HashMap (java.util.HashMap)4 Map (java.util.Map)3 AccModuleDescriptor (eu.bcvsolutions.idm.acc.AccModuleDescriptor)2 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)2 SysSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter)2 ProvisioningEvent (eu.bcvsolutions.idm.acc.event.ProvisioningEvent)2 AccIdentityAccountRepository (eu.bcvsolutions.idm.acc.repository.AccIdentityAccountRepository)2