Search in sources :

Example 11 with IdmPasswordDto

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

the class AbstractIdentityPasswordValidateProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto identity = event.getContent();
    PasswordChangeDto passwordChangeDto = (PasswordChangeDto) event.getProperties().get(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO);
    Assert.notNull(passwordChangeDto);
    // 
    if (requiresOriginalPassword()) {
        PasswordChangeType passwordChangeType = identityConfiguration.getPasswordChangeType();
        if (passwordChangeType == PasswordChangeType.DISABLED) {
            // check if isn't disable password change
            throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_DISABLED);
        } else if (passwordChangeType == PasswordChangeType.ALL_ONLY && !passwordChangeDto.isAll()) {
            // for all only must change also password for czechidm
            throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_ALL_ONLY);
        }
        // checkAccess(identity, IdentityBasePermission.PASSWORDCHANGE) is called before event publishing
        if (identity.getId().equals(securityService.getCurrentId()) && identityConfiguration.isRequireOldPassword()) {
            if (passwordChangeDto.getOldPassword() == null) {
                throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_CURRENT_FAILED_IDM);
            }
            // authentication trough chain
            boolean successChainAuthentication = authenticationManager.validate(identity.getUsername(), passwordChangeDto.getOldPassword());
            if (!successChainAuthentication) {
                throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_CURRENT_FAILED_IDM);
            }
        }
    }
    if (passwordChangeDto.isAll() || passwordChangeDto.isIdm()) {
        // change identity's password
        // validate password
        IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
        // set old password for validation - valid till, from and history check
        IdmPasswordDto oldPassword = this.passwordService.findOneByIdentity(identity.getId());
        passwordValidationDto.setOldPassword(oldPassword == null ? null : oldPassword.getId());
        passwordValidationDto.setPassword(passwordChangeDto.getNewPassword());
        passwordValidationDto.setIdentity(identity);
        this.passwordPolicyService.validate(passwordValidationDto);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : PasswordChangeType(eu.bcvsolutions.idm.core.api.domain.PasswordChangeType) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 12 with IdmPasswordDto

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

the class DefaultIdmPasswordServiceIntegrationTest method testTwoPoliciesSecondValidTillNull.

@Test
public void testTwoPoliciesSecondValidTillNull() {
    IdmPasswordPolicyDto policy1 = getTestPolicy(false, IdmPasswordPolicyType.VALIDATE, null);
    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());
    assertEquals(LocalDate.now().plusDays(policy2.getMaxPasswordAge()), password.getValidTill());
    // 
    policy1.setDefaultPolicy(true);
    policy1 = policyService.save(policy1);
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setAll(true);
    passwordChangeDto.setIdm(true);
    passwordChangeDto.setNewPassword(new GuardedString("testPassword"));
    identityService.passwordChange(identity, passwordChangeDto);
    password = passwordService.findOneByIdentity(identity.getId());
    assertNull(password.getValidTill());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) 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) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with IdmPasswordDto

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

the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordNonDefaultPolicy.

@Test
public void testCreatePasswordNonDefaultPolicy() {
    IdmPasswordPolicyDto policy = getTestPolicy(false);
    assertNotNull(policy);
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    assertEquals(LocalDate.now(), password.getValidFrom());
    assertEquals(identity.getId(), password.getIdentity());
    // when not exists default validation policy valid till be null
    assertNull(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 14 with IdmPasswordDto

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

the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordValidationPolicy.

@Test
public void testCreatePasswordValidationPolicy() {
    getTestPolicy(false, IdmPasswordPolicyType.VALIDATE, 365);
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    assertEquals(LocalDate.now(), password.getValidFrom());
    assertEquals(identity.getId(), password.getIdentity());
    assertNull(password.getValidTill());
}
Also used : 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 15 with IdmPasswordDto

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

the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordNoPolicy.

@Test
public void testCreatePasswordNoPolicy() {
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    assertEquals(LocalDate.now(), password.getValidFrom());
    assertEquals(identity.getId(), password.getIdentity());
    assertNull(password.getValidTill());
}
Also used : 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)

Aggregations

IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)20 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)14 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)11 Test (org.junit.Test)11 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)6 LocalDate (org.joda.time.LocalDate)5 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)4 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)4 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)4 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)4 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PasswordChangeType (eu.bcvsolutions.idm.core.api.domain.PasswordChangeType)2 IdmPasswordValidationDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto)2 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 AccModuleDescriptor (eu.bcvsolutions.idm.acc.AccModuleDescriptor)1 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)1