Search in sources :

Example 16 with PasswordChangeDto

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

the class DefaultIdmPasswordServiceIntegrationTest method testResetUsuccessfulAttemptsAfterPasswordChange.

@Test
@Transactional
public void testResetUsuccessfulAttemptsAfterPasswordChange() {
    IdmIdentityDto identity = testHelper.createIdentity();
    // login
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(identity.getUsername());
    loginDto.setPassword(new GuardedString("wrong"));
    try {
        loginController.login(loginDto);
    } catch (IdmAuthenticationException ex) {
    // nothing
    }
    try {
        loginController.login(loginDto);
    } catch (IdmAuthenticationException ex) {
    // nothing
    }
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    // 
    Assert.assertEquals(2, password.getUnsuccessfulAttempts());
    // 
    // password change
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setIdm(true);
    passwordChange.setNewPassword(new GuardedString("new"));
    passwordService.save(identity, passwordChange);
    // 
    password = passwordService.findOneByIdentity(identity.getId());
    // 
    Assert.assertEquals(0, password.getUnsuccessfulAttempts());
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmAuthenticationException(eu.bcvsolutions.idm.core.security.exception.IdmAuthenticationException) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with PasswordChangeDto

use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto 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 18 with PasswordChangeDto

use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto 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 19 with PasswordChangeDto

use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto 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)

Example 20 with PasswordChangeDto

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

the class PasswordPreValidationIntegrationTest method testLenght.

@Test
public void testLenght() {
    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.setOwnership(true);
    account = accountIdentityService.save(account);
    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(5);
    policyDefault.setMaxPasswordLength(10);
    // password policy
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName(System.currentTimeMillis() + "test2");
    policy.setDefaultPolicy(false);
    policy.setMinPasswordLength(6);
    policy.setMaxPasswordLength(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("minLength"));
        assertEquals(10, ex.getError().getError().getParameters().get("maxLength"));
        assertEquals(policy.getName() + ", " + policyDefault.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
        assertEquals(3, 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

PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)36 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)30 Test (org.junit.Test)27 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)23 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)21 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)16 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)13 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)11 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)11 ArrayList (java.util.ArrayList)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)9 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)7 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)7 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)5 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)5 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)4 IdmPasswordValidationDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto)4