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
}
}
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
}
}
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());
}
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);
}
}
}
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
}
}
Aggregations