Search in sources :

Example 21 with IdmPasswordValidationDto

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

the class DefaultIdmPasswordPolicyServiceIntegrationTest 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) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) PasswordChangeException(eu.bcvsolutions.idm.core.api.exception.PasswordChangeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 22 with IdmPasswordValidationDto

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

the class DefaultIdmPasswordPolicyServiceIntegrationTest method testValidateWithForbiddenBeginEnd.

@Test
public void testValidateWithForbiddenBeginEnd() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_14_1");
    policy.setType(IdmPasswordPolicyType.VALIDATE);
    policy.setMinPasswordLength(0);
    policy.setMinNumber(0);
    policy.setMinLowerChar(0);
    policy.setMinSpecialChar(0);
    policy.setMinUpperChar(0);
    policy.setProhibitedBeginCharacters("A");
    policy.setProhibitedEndCharacters("B");
    IdmPasswordValidationDto password = new IdmPasswordValidationDto();
    password.setPassword("aAsdfg12B3");
    this.passwordPolicyService.validate(password, policy);
    try {
        password.setPassword("Asdfg12s");
        this.passwordPolicyService.validate(password, policy);
        fail("A forbidden character at the beginning of the password was not detected");
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("asdfg12B");
        this.passwordPolicyService.validate(password, policy);
        fail("A forbidden character at the end of the password was not detected");
    } catch (Exception e) {
    // nothing, success
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) PasswordChangeException(eu.bcvsolutions.idm.core.api.exception.PasswordChangeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 23 with IdmPasswordValidationDto

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

the class DefaultIdmPasswordPolicyServiceIntegrationTest method testContainsPersonalNumber.

@Test
public void testContainsPersonalNumber() {
    IdmIdentityDto identity = this.getHelper().createIdentity((GuardedString) null);
    identity.setExternalCode("123-456-789-0_EEE");
    identity = identityService.save(identity);
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setType(IdmPasswordPolicyType.VALIDATE);
    policy.setEnchancedControl(true);
    policy.setIdentityAttributeCheck(IdmPasswordPolicyIdentityAttributes.EXTERNALCODE.name());
    IdmPasswordValidationDto validation = new IdmPasswordValidationDto();
    validation.setIdentity(identity);
    validation.setPassword("123456789");
    // Numbers only
    try {
        passwordPolicyService.validate(validation, policy);
        fail("Password pass.");
    } catch (ResultCodeException e) {
    // Success
    } catch (Exception e) {
        fail(e.getMessage());
    }
    validation.setPassword("jenda123");
    try {
        passwordPolicyService.validate(validation, policy);
        fail("Password pass.");
    } catch (ResultCodeException e) {
    // Success
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // Works with letters
    validation.setPassword("999999999ĚÉE");
    try {
        passwordPolicyService.validate(validation, policy);
        fail("Password pass.");
    } catch (ResultCodeException e) {
    // Success
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // Success
    validation.setPassword("XXXXXX0");
    try {
        passwordPolicyService.validate(validation, policy);
    } catch (ResultCodeException e) {
        fail("Password not pass.");
    } catch (Exception e) {
        fail(e.getMessage());
    }
    validation.setPassword("987-654-321");
    try {
        passwordPolicyService.validate(validation, policy);
    } catch (ResultCodeException e) {
        fail("Password not pass.");
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) PasswordChangeException(eu.bcvsolutions.idm.core.api.exception.PasswordChangeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 24 with IdmPasswordValidationDto

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

the class DefaultIdmPasswordPolicyServiceIntegrationTest method testValidateMinPasswordAgeFailedEnforce.

@Test(expected = PasswordChangeException.class)
public void testValidateMinPasswordAgeFailedEnforce() {
    IdmIdentityDto manager = getHelper().createIdentity();
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmPasswordDto password = getHelper().getPassword(identity);
    password.setValidFrom(LocalDate.now());
    password = passwordService.save(password);
    // 
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setType(IdmPasswordPolicyType.VALIDATE);
    policy.setMinPasswordAge(1);
    // 
    IdmPasswordValidationDto validation = new IdmPasswordValidationDto();
    validation.setIdentity(identity);
    validation.setPassword(getHelper().createName());
    validation.setEnforceMinPasswordAgeValidation(true);
    // 
    try {
        getHelper().login(manager);
        // 
        passwordPolicyService.validate(validation, Lists.newArrayList(policy));
    } finally {
        getHelper().logout();
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 25 with IdmPasswordValidationDto

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

the class DefaultIdmPasswordPolicyServiceIntegrationTest 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) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) PasswordChangeException(eu.bcvsolutions.idm.core.api.exception.PasswordChangeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmPasswordValidationDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto)29 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)27 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)24 Test (org.junit.Test)24 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)18 PasswordChangeException (eu.bcvsolutions.idm.core.api.exception.PasswordChangeException)15 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)14 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)5 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)5 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 IdmPasswordPolicyType (eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyType)2 PasswordChangeType (eu.bcvsolutions.idm.core.api.domain.PasswordChangeType)2 IdentityProcessor (eu.bcvsolutions.idm.core.api.event.processor.IdentityProcessor)2 IdmPasswordPolicyService (eu.bcvsolutions.idm.core.api.service.IdmPasswordPolicyService)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 AccModuleDescriptor (eu.bcvsolutions.idm.acc.AccModuleDescriptor)1 PasswordFilterEncoderConfiguration (eu.bcvsolutions.idm.acc.config.domain.PasswordFilterEncoderConfiguration)1 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)1