Search in sources :

Example 16 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testValidateMinNumbers.

@Test
public void testValidateMinNumbers() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_12");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(3);
    policy.setMinPasswordLength(1);
    policy.setMinNumber(2);
    IdmPasswordValidationDto password = new IdmPasswordValidationDto();
    try {
        password.setPassword("123");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("12");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("12a");
        this.passwordPolicyService.validate(password, policy);
    } catch (Exception e) {
        fail("Password validation numbers. " + e.getMessage());
    }
    try {
        password.setPassword("1");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation numbers. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("1234");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation numbers. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("test");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation numbers. " + 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)

Example 17 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testValidateComplex.

@Test
public void testValidateComplex() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_16");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(20);
    policy.setMinPasswordLength(6);
    policy.setMinNumber(3);
    policy.setMinLowerChar(3);
    policy.setMinSpecialChar(3);
    policy.setMinUpperChar(3);
    policy.setSpecialCharBase("@#");
    policy.setNumberBase("0");
    policy.setProhibitedCharacters("*/^mn");
    IdmPasswordValidationDto password = new IdmPasswordValidationDto();
    try {
        password.setPassword("000abc@@@DEF");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("F0a@0Ec0b@@D");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("#3aBb@C3A1#0c00");
        this.passwordPolicyService.validate(password, policy);
    } catch (Exception e) {
        fail("Password complex validation. " + policy);
    }
    try {
        password.setPassword("001abc@@@DEF");
        this.passwordPolicyService.validate(password, policy);
        fail("Password complex validation. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("000abc##$DEF");
        this.passwordPolicyService.validate(password, policy);
        fail("Password complex validation. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("000abc)()DEF");
        this.passwordPolicyService.validate(password, policy);
        fail("Password complex validation. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("#3aBb@C3A1#0c00idheff");
        this.passwordPolicyService.validate(password, policy);
        fail("Password complex validation. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("#3aBmb@C3A1#0c00");
        this.passwordPolicyService.validate(password, policy);
        fail("Password complex validation. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("#3aBb@C3A1n#0c00");
        this.passwordPolicyService.validate(password, policy);
        fail("Password complex validation. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("#3mBb*@C3A1n#0c00");
        this.passwordPolicyService.validate(password, policy);
        fail("Password complex validation. " + 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)

Example 18 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testCreateAndFoundPasswordPolicy.

@Test
public void testCreateAndFoundPasswordPolicy() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_17_saved");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setDefaultPolicy(false);
    policy.setMaxPasswordLength(20);
    policy.setMinPasswordLength(6);
    policy = this.passwordPolicyService.save(policy);
    IdmPasswordPolicyDto foundPolicyByName = this.passwordPolicyService.findOneByName("test_17_saved");
    assertEquals(policy.getName(), foundPolicyByName.getName());
    assertEquals(policy.getType(), foundPolicyByName.getType());
    assertEquals(policy.getMaxPasswordLength(), foundPolicyByName.getMaxPasswordLength());
    assertEquals(policy.getMinPasswordLength(), foundPolicyByName.getMinPasswordLength());
    IdmPasswordPolicyDto foundPolicyById = this.passwordPolicyService.get(policy.getId());
    assertEquals(policy.getName(), foundPolicyById.getName());
    assertEquals(policy.getType(), foundPolicyById.getType());
    assertEquals(policy.getMaxPasswordLength(), foundPolicyById.getMaxPasswordLength());
    assertEquals(policy.getMinPasswordLength(), foundPolicyById.getMinPasswordLength());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 19 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateOnlyAlpha.

@Test
public void testGenerateOnlyAlpha() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_07");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(10);
    policy.setMinPasswordLength(1);
    policy.setSpecialCharBase("");
    policy.setNumberBase("");
    for (int index = 0; index < ATTEMPTS; index++) {
        String password = passwordPolicyService.generatePassword(policy);
        if (!password.matches("[a-zA-Z]+")) {
            fail("Password must cointain only aplha characters, password: " + password);
        }
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 20 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testValidateLength.

@Test
public void testValidateLength() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_11");
    policy.setType(IdmPasswordPolicyType.VALIDATE);
    policy.setMaxPasswordLength(10);
    policy.setMinPasswordLength(5);
    IdmPasswordValidationDto password = new IdmPasswordValidationDto();
    try {
        password.setPassword("12345");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("123456");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("1234567");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("12345678");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("123456789");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("1234567890");
        this.passwordPolicyService.validate(password, policy);
    } catch (Exception e) {
        fail("Password validation length.");
    }
    try {
        password.setPassword("1234");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation length.");
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation length.");
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("123456789123");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation length.");
    } 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