use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto 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
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto 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
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto 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
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyServiceIntegrationTest method testValidateMinPasswordAgeFailedSameUser.
@Test(expected = PasswordChangeException.class)
public void testValidateMinPasswordAgeFailedSameUser() {
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());
//
try {
getHelper().login(identity);
//
passwordPolicyService.validate(validation, Lists.newArrayList(policy));
} finally {
getHelper().logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyServiceIntegrationTest method testValidateMinPasswordAgeSuccess.
@Test
public void testValidateMinPasswordAgeSuccess() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setType(IdmPasswordPolicyType.VALIDATE);
policy.setMinPasswordAge(1);
//
IdmPasswordValidationDto validation = new IdmPasswordValidationDto();
validation.setIdentity(identity);
validation.setPassword(getHelper().createName());
//
try {
// without password - ok
passwordPolicyService.validate(validation, policy);
//
// create password
PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
passwordChangeDto.setIdm(true);
GuardedString newPassword = new GuardedString(getHelper().createName());
passwordChangeDto.setNewPassword(newPassword);
IdmPasswordDto password = passwordService.save(identity, passwordChangeDto);
Assert.assertNull(password.getValidFrom());
//
identity.setPassword(newPassword);
getHelper().login(identity);
// null valid from - ok
passwordPolicyService.validate(validation, policy);
//
// in past - ok
password.setValidFrom(LocalDate.now().minusDays(1));
password = passwordService.save(password);
passwordPolicyService.validate(validation, policy);
//
// must change - ok
password.setValidFrom(LocalDate.now());
password.setMustChange(true);
password = passwordService.save(password);
passwordPolicyService.validate(validation, policy);
//
//
// prevalidate - ok
password.setMustChange(false);
password = passwordService.save(password);
passwordPolicyService.preValidate(validation, Lists.newArrayList(policy));
} finally {
getHelper().logout();
}
// under admin - ok
try {
getHelper().loginAdmin();
passwordPolicyService.validate(validation, policy);
} finally {
getHelper().logout();
}
//
// under different user - ok
IdmIdentityDto manager = getHelper().createIdentity();
try {
getHelper().login(manager);
passwordPolicyService.validate(validation, policy);
} finally {
getHelper().logout();
}
}
Aggregations