Search in sources :

Example 6 with IdmPasswordValidationDto

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

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

the class IdentityCreatePasswordValidateProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    GuardedString password = event.getContent().getPassword();
    IdmIdentityDto identity = event.getContent();
    // when create identity password can be null
    if (password != null) {
        IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
        passwordValidationDto.setPassword(password);
        passwordValidationDto.setIdentity(identity);
        // validate create new password by default password policy
        this.passwordPolicyService.validate(passwordValidationDto);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 8 with IdmPasswordValidationDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testValidationProhibitedChars.

@Test
public void testValidationProhibitedChars() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_14");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(5);
    policy.setMinPasswordLength(1);
    policy.setProhibitedCharacters("12abcDEF!@");
    IdmPasswordValidationDto password = new IdmPasswordValidationDto();
    try {
        password.setPassword("test");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("ABde");
        this.passwordPolicyService.validate(password, policy);
    } catch (Exception e) {
        fail("Password validate prohibited characters. " + policy);
    }
    try {
        password.setPassword("tEst");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validate prohibited characters. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("eddD");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validate prohibited characters. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("5416");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validate prohibited characters. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("test!");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validate prohibited characters. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 9 with IdmPasswordValidationDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testValidateSpecialChar.

@Test
public void testValidateSpecialChar() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_13");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(3);
    policy.setMinPasswordLength(1);
    policy.setMinSpecialChar(2);
    IdmPasswordValidationDto password = new IdmPasswordValidationDto();
    try {
        password.setPassword("!@");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("!@#");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("!@a");
        this.passwordPolicyService.validate(password, policy);
    } catch (Exception e) {
        fail("Password validation special chars. " + e.getMessage());
    }
    try {
        password.setPassword("!");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation special chars. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("!@#$");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation special chars. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("test");
        this.passwordPolicyService.validate(password, policy);
        fail("Password validation special chars. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 10 with IdmPasswordValidationDto

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

the class DefaultIdmPasswordPolicyIntegrationTest method testValidateBase.

@Test
public void testValidateBase() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_15");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(5);
    policy.setMinPasswordLength(1);
    policy.setNumberBase("123");
    policy.setMinNumber(3);
    IdmPasswordValidationDto password = new IdmPasswordValidationDto();
    try {
        password.setPassword("123");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("1234");
        this.passwordPolicyService.validate(password, policy);
        password.setPassword("111");
        this.passwordPolicyService.validate(password, policy);
    } catch (Exception e) {
        fail("Password base validation. " + policy);
    }
    try {
        password.setPassword("124");
        this.passwordPolicyService.validate(password, policy);
        fail("Password base validation. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
    try {
        password.setPassword("456");
        this.passwordPolicyService.validate(password, policy);
        fail("Password base validation. " + policy);
    } catch (Exception e) {
    // nothing, success
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmPasswordValidationDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto)10 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)8 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)6 Test (org.junit.Test)6 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)3 PasswordChangeType (eu.bcvsolutions.idm.core.api.domain.PasswordChangeType)2 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 AccModuleDescriptor (eu.bcvsolutions.idm.acc.AccModuleDescriptor)1 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)1 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)1 ProvisioningEvent (eu.bcvsolutions.idm.acc.event.ProvisioningEvent)1 AccIdentityAccountRepository (eu.bcvsolutions.idm.acc.repository.AccIdentityAccountRepository)1 AccIdentityAccountService (eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService)1 IdentityConfiguration (eu.bcvsolutions.idm.core.api.config.domain.IdentityConfiguration)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 IdmPasswordPolicyType (eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyType)1 CoreEventProcessor (eu.bcvsolutions.idm.core.api.event.CoreEventProcessor)1