Search in sources :

Example 26 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordMultiplePolicies.

@Test
public void testCreatePasswordMultiplePolicies() {
    IdmPasswordPolicyDto policy1 = getTestPolicy(true, IdmPasswordPolicyType.VALIDATE, 365);
    assertNotNull(policy1);
    IdmPasswordPolicyDto policy2 = getTestPolicy(true, IdmPasswordPolicyType.VALIDATE, 5);
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    assertEquals(LocalDate.now(), password.getValidFrom());
    assertEquals(identity.getId(), password.getIdentity());
    // default password policy may be only one
    assertEquals(LocalDate.now().plusDays(policy2.getMaxPasswordAge()), password.getValidTill());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) 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 27 with IdmPasswordPolicyDto

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

the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordDefaultPolicy.

@Test
public void testCreatePasswordDefaultPolicy() {
    IdmPasswordPolicyDto policy = getTestPolicy(true);
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    assertEquals(LocalDate.now(), password.getValidFrom());
    assertEquals(identity.getId(), password.getIdentity());
    assertEquals(LocalDate.now().plusDays(policy.getMaxPasswordAge()), password.getValidTill());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) 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 28 with IdmPasswordPolicyDto

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

the class PasswordPreValidationIntegrationTest method testAdvancedEnabled.

@Test
public void testAdvancedEnabled() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName(System.currentTimeMillis() + "");
    policy.setDefaultPolicy(true);
    policy.setMinPasswordLength(10);
    policy.setMaxPasswordLength(20);
    policy.setPasswordLengthRequired(true);
    policy.setMinUpperChar(5);
    policy.setUpperCharRequired(true);
    policy.setMinLowerChar(4);
    policy.setLowerCharRequired(true);
    policy.setEnchancedControl(true);
    policy.setMinRulesToFulfill(1);
    policy.setMinNumber(3);
    policy.setNumberRequired(false);
    policy.setMinSpecialChar(2);
    policy.setSpecialCharRequired(false);
    policy.setIdentityAttributeCheck("EMAIL, USERNAME");
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setIdm(true);
    policy = passwordPolicyService.save(policy);
    try {
        idmIdentityService.validatePassword(passwordChange);
    } catch (ResultCodeException ex) {
        Map<String, Object> parametrs = new HashMap<String, Object>();
        parametrs.put("minNumber", 3);
        parametrs.put("minSpecialChar", 2);
        assertEquals(10, ex.getError().getError().getParameters().get("minLength"));
        assertEquals(20, ex.getError().getError().getParameters().get("maxLength"));
        assertEquals(5, ex.getError().getError().getParameters().get("minUpperChar"));
        assertEquals(4, ex.getError().getError().getParameters().get("minLowerChar"));
        assertEquals(parametrs.toString(), ex.getError().getError().getParameters().get("minRulesToFulfill").toString());
        assertEquals(policy.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
        // special char base, passwordSimilarUsername, passwordSimilarEmail ->
        assertEquals(10, ex.getError().getError().getParameters().size());
        policy.setDefaultPolicy(false);
        passwordPolicyService.save(policy);
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 29 with IdmPasswordPolicyDto

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

the class PasswordPreValidationIntegrationTest method testAdvancedEnabledSimilarAttributes.

@Test
public void testAdvancedEnabledSimilarAttributes() {
    IdmIdentityDto identity = new IdmIdentityDto();
    identity.setUsername("test" + System.currentTimeMillis());
    identity.setFirstName("testFirst");
    identity.setLastName("testSecond");
    identity = idmIdentityService.save(identity);
    // 
    SysSystemDto system = testHelper.createTestResourceSystem(true);
    // 
    AccAccountDto acc = new AccAccountDto();
    acc.setId(UUID.randomUUID());
    acc.setUid(System.currentTimeMillis() + "");
    acc.setAccountType(AccountType.PERSONAL);
    acc.setSystem(system.getId());
    // 
    acc = accountService.save(acc);
    // 
    AccIdentityAccountDto account = testHelper.createIdentityAccount(system, identity);
    account.setAccount(acc.getId());
    account = accountIdentityService.save(account);
    account.setOwnership(true);
    List<String> accounts = new ArrayList<String>();
    accounts.add(acc.getId() + "");
    // password policy default
    IdmPasswordPolicyDto policyDefault = new IdmPasswordPolicyDto();
    policyDefault.setName(System.currentTimeMillis() + "test1");
    policyDefault.setDefaultPolicy(true);
    policyDefault.setMinPasswordLength(10);
    policyDefault.setMaxPasswordLength(20);
    policyDefault.setPasswordLengthRequired(true);
    policyDefault.setMinUpperChar(5);
    policyDefault.setUpperCharRequired(true);
    policyDefault.setMinLowerChar(4);
    policyDefault.setLowerCharRequired(true);
    policyDefault.setEnchancedControl(true);
    policyDefault.setMinRulesToFulfill(1);
    policyDefault.setMinNumber(3);
    policyDefault.setNumberRequired(false);
    policyDefault.setMinSpecialChar(4);
    policyDefault.setSpecialCharRequired(false);
    policyDefault.setIdentityAttributeCheck("EMAIL, FIRSTNAME");
    // password policy
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName(System.currentTimeMillis() + "test2");
    policy.setDefaultPolicy(false);
    policy.setMinPasswordLength(9);
    policy.setMaxPasswordLength(21);
    policy.setPasswordLengthRequired(true);
    policy.setMinUpperChar(4);
    policy.setUpperCharRequired(true);
    policy.setMinLowerChar(3);
    policy.setLowerCharRequired(true);
    policy.setEnchancedControl(true);
    policy.setMinRulesToFulfill(1);
    policy.setMinNumber(5);
    policy.setNumberRequired(false);
    policy.setMinSpecialChar(2);
    policy.setSpecialCharRequired(false);
    policy.setIdentityAttributeCheck("USERNAME");
    policyDefault = passwordPolicyService.save(policyDefault);
    policy = passwordPolicyService.save(policy);
    system.setPasswordPolicyValidate(policy.getId());
    systemService.save(system);
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setIdm(true);
    passwordChange.setAccounts(accounts);
    passwordChange.setAll(true);
    try {
        idmIdentityService.validatePassword(passwordChange);
    } catch (ResultCodeException ex) {
        Map<String, Object> parametrs = new HashMap<String, Object>();
        parametrs.put("minNumber", 3);
        parametrs.put("minSpecialChar", 4);
        assertEquals(10, ex.getError().getError().getParameters().get("minLength"));
        assertEquals(20, ex.getError().getError().getParameters().get("maxLength"));
        assertEquals(5, ex.getError().getError().getParameters().get("minUpperChar"));
        assertEquals(4, ex.getError().getError().getParameters().get("minLowerChar"));
        assertEquals(parametrs.toString(), ex.getError().getError().getParameters().get("minRulesToFulfill").toString());
        assertEquals(policy.getName() + ", " + policyDefault.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
        // special char base, passwordSimilarUsername, passwordSimilarLastName,
        // passwordSimilarEmail -> 11
        assertEquals(11, ex.getError().getError().getParameters().size());
        policyDefault.setDefaultPolicy(false);
        passwordPolicyService.save(policyDefault);
    }
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) ArrayList(java.util.ArrayList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) HashMap(java.util.HashMap) Map(java.util.Map) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 30 with IdmPasswordPolicyDto

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

the class PasswordPreValidationIntegrationTest method testNumberSpecialChar.

@Test
public void testNumberSpecialChar() {
    IdmIdentityDto identity = new IdmIdentityDto();
    identity.setUsername("test" + System.currentTimeMillis());
    identity.setFirstName("testFirst");
    identity.setLastName("testSecond");
    identity = idmIdentityService.save(identity);
    // 
    SysSystemDto system = testHelper.createTestResourceSystem(true);
    // 
    AccAccountDto acc = new AccAccountDto();
    acc.setId(UUID.randomUUID());
    acc.setUid(System.currentTimeMillis() + "");
    acc.setAccountType(AccountType.PERSONAL);
    acc.setSystem(system.getId());
    // 
    acc = accountService.save(acc);
    // 
    AccIdentityAccountDto account = testHelper.createIdentityAccount(system, identity);
    account.setAccount(acc.getId());
    account = accountIdentityService.save(account);
    account.setOwnership(true);
    List<String> accounts = new ArrayList<String>();
    accounts.add(acc.getId() + "");
    // password policy default
    IdmPasswordPolicyDto policyDefault = new IdmPasswordPolicyDto();
    policyDefault.setName(System.currentTimeMillis() + "test1");
    policyDefault.setDefaultPolicy(true);
    policyDefault.setMinNumber(6);
    policyDefault.setMinSpecialChar(10);
    // password policy
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName(System.currentTimeMillis() + "test2");
    policy.setDefaultPolicy(false);
    policy.setMinNumber(5);
    policy.setMinSpecialChar(11);
    policyDefault = passwordPolicyService.save(policyDefault);
    policy = passwordPolicyService.save(policy);
    system.setPasswordPolicyValidate(policy.getId());
    systemService.save(system);
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setIdm(true);
    passwordChange.setAccounts(accounts);
    passwordChange.setAll(true);
    try {
        idmIdentityService.validatePassword(passwordChange);
    } catch (ResultCodeException ex) {
        assertEquals(6, ex.getError().getError().getParameters().get("minNumber"));
        assertEquals(11, ex.getError().getError().getParameters().get("minSpecialChar"));
        assertEquals(policy.getName() + ", " + policyDefault.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
        assertFalse(ex.getError().getError().getParameters().get("specialCharacterBase") == null);
        assertEquals(4, ex.getError().getError().getParameters().size());
        policyDefault.setDefaultPolicy(false);
        passwordPolicyService.save(policyDefault);
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) ArrayList(java.util.ArrayList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

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