Search in sources :

Example 21 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateRandomPasswordLength.

@Test
public void testGenerateRandomPasswordLength() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_01");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMinPasswordLength(5);
    policy.setMaxPasswordLength(12);
    for (int index = 0; index < ATTEMPTS; index++) {
        String password = passwordPolicyService.generatePassword(policy);
        assertTrue(password.length() >= 5);
        assertTrue(password.length() <= 12);
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 22 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateComplexPassword.

@Test
public void testGenerateComplexPassword() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_09");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(10);
    policy.setMinPasswordLength(5);
    policy.setSpecialCharBase("!");
    policy.setNumberBase("123");
    policy.setMinNumber(3);
    policy.setMinLowerChar(2);
    policy.setMinSpecialChar(2);
    policy.setMinUpperChar(1);
    for (int index = 0; index < ATTEMPTS * 5; index++) {
        String password = passwordPolicyService.generatePassword(policy);
        assertTrue(password.length() >= 8);
        assertTrue(StringUtils.countMatches(password, "!") >= 2);
        assertTrue(StringUtils.containsNone(password, "@#$%^&*()"));
        assertTrue(StringUtils.containsNone(password, "0456789"));
        assertTrue(password.matches(".*[A-Z].*{1,}"));
        assertTrue(password.matches(".*[a-z].*{2,}"));
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 23 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testFailGenerateRandom.

@Test
public void testFailGenerateRandom() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_03");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(5);
    String password = passwordPolicyService.generatePassword(policy);
    assertTrue(password.length() <= 5);
    policy.setMinNumber(2);
    policy.setMinSpecialChar(2);
    policy.setMinLowerChar(2);
    try {
        password = passwordPolicyService.generatePassword(policy);
        fail("Password cant be generate");
    } catch (Exception e) {
    // nothing
    }
    policy.setMinLowerChar(1);
    password = passwordPolicyService.generatePassword(policy);
    assertEquals(5, password.length());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 24 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateOnlyNumbers.

@Test
public void testGenerateOnlyNumbers() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_06");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(10);
    policy.setMinPasswordLength(1);
    policy.setLowerCharBase("");
    policy.setSpecialCharBase("");
    policy.setNumberBase("0123456789");
    policy.setUpperCharBase("");
    for (int index = 0; index < ATTEMPTS; index++) {
        try {
            String password = passwordPolicyService.generatePassword(policy);
            Long.parseLong(password);
        } catch (Exception e) {
            fail("Password must cointains only numbers: " + e.getMessage());
        }
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 25 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testGenerateProhibited.

@Test
public void testGenerateProhibited() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_10");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(2);
    policy.setMinPasswordLength(2);
    policy.setSpecialCharBase("");
    policy.setLowerCharBase("a");
    policy.setUpperCharBase("");
    policy.setNumberBase("123");
    policy.setProhibitedCharacters("asd2!@#%3$");
    for (int index = 0; index < ATTEMPTS; index++) {
        String password = passwordPolicyService.generatePassword(policy);
        assertTrue(password.length() == 2);
        assertTrue(StringUtils.countMatches(password, "1") == 2);
        assertTrue(StringUtils.containsNone(password, "asd2!@#%3$"));
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) 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