Search in sources :

Example 26 with PasswordChangeDto

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

the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangePasswordUnsupportSystem.

@Test(expected = ProvisioningException.class)
public void doIdentityProvisioningChangePasswordUnsupportSystem() {
    IdmIdentityDto identity = idmIdentityService.getByUsername(IDENTITY_USERNAME);
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
    SysSystemDto system = systemService.get(accountService.get(accountIdentityOne.getAccount()).getSystem());
    SysSystemDto clonedSystem = systemService.duplicate(system.getId());
    clonedSystem.setReadonly(false);
    clonedSystem.setDisabled(false);
    clonedSystem = systemService.save(clonedSystem);
    SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
    attributeMappingFilter.setSystemId(clonedSystem.getId());
    SysSystemAttributeMappingDto passwordAttribute = systemAttributeMappingService.find(attributeMappingFilter, null).getContent().stream().filter(attribute -> {
        return ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME.equals(schemaAttributeService.get(attribute.getSchemaAttribute()).getName());
    }).findFirst().orElse(null);
    Assert.assertNotNull(passwordAttribute);
    SysSystemAttributeMappingDto uidAttribute = systemAttributeMappingService.find(attributeMappingFilter, null).getContent().stream().filter(attribute -> {
        return attribute.isUid();
    }).findFirst().orElse(null);
    Assert.assertNotNull(uidAttribute);
    uidAttribute.setTransformToResourceScript("if(attributeValue){return \"y\"+ attributeValue;}");
    uidAttribute = systemAttributeMappingService.save(uidAttribute);
    SysSystemEntityDto sysEntity = new SysSystemEntityDto("y" + IDENTITY_USERNAME, SystemEntityType.IDENTITY);
    sysEntity.setSystem(clonedSystem.getId());
    sysEntity = systemEntityService.save(sysEntity);
    AccAccountDto account = new AccAccountDto();
    account.setSystem(clonedSystem.getId());
    account.setUid("y" + IDENTITY_USERNAME);
    account.setAccountType(AccountType.PERSONAL);
    account.setEntityType(SystemEntityType.IDENTITY);
    account.setSystemEntity(sysEntity.getId());
    account = accountService.save(account);
    AccIdentityAccountDto accountIdentity = new AccIdentityAccountDto();
    accountIdentity.setIdentity(identity.getId());
    accountIdentity.setOwnership(true);
    accountIdentity.setAccount(account.getId());
    accountIdentity = identityAccoutnService.save(accountIdentity);
    provisioningService.doProvisioning(account);
    TestResource createdAccount = entityManager.find(TestResource.class, accountService.get(accountIdentity.getAccount()).getUid());
    Assert.assertNotNull(createdAccount);
    Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
    String password = createdAccount.getPassword();
    AccAccountFilter accountFilter = new AccAccountFilter();
    accountFilter.setIdentityId(identity.getId());
    accountFilter.setOwnership(Boolean.TRUE);
    accountFilter.setSupportChangePassword(Boolean.TRUE);
    // Two accounts supported change password expects
    Assert.assertEquals(2, accountService.find(accountFilter, null).getContent().size());
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setNewPassword(new GuardedString("newPWD"));
    passwordChange.getAccounts().add(account.getId().toString());
    idmIdentityService.passwordChange(identity, passwordChange);
    createdAccount = entityManager.find(TestResource.class, accountService.get(accountIdentity.getAccount()).getUid());
    Assert.assertNotEquals(password, createdAccount.getPassword());
    // After success password change, we delete password attribute.
    systemAttributeMappingService.delete(passwordAttribute);
    // One account supported change password expects
    Assert.assertEquals(1, accountService.find(accountFilter, null).getContent().size());
    // Change password .. must end with exception
    passwordChange = new PasswordChangeDto();
    passwordChange.setNewPassword(new GuardedString("newPWDUnsupported"));
    passwordChange.getAccounts().add(account.getId().toString());
    idmIdentityService.passwordChange(identity, passwordChange);
    fail();
}
Also used : SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 27 with PasswordChangeDto

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

use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto 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 29 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() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName(System.currentTimeMillis() + "");
    policy.setDefaultPolicy(true);
    policy.setMinPasswordLength(5);
    policy.setMaxPasswordLength(10);
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setIdm(true);
    policy = passwordPolicyService.save(policy);
    try {
        idmIdentityService.validatePassword(passwordChange);
    } catch (ResultCodeException ex) {
        assertEquals(5, ex.getError().getError().getParameters().get("minLength"));
        assertEquals(10, ex.getError().getError().getParameters().get("maxLength"));
        assertEquals(policy.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
        assertEquals(3, 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) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 30 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() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName(System.currentTimeMillis() + "");
    policy.setDefaultPolicy(true);
    policy.setMinNumber(5);
    policy.setMinSpecialChar(10);
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setIdm(true);
    policy = passwordPolicyService.save(policy);
    try {
        idmIdentityService.validatePassword(passwordChange);
    } catch (ResultCodeException ex) {
        assertEquals(5, ex.getError().getError().getParameters().get("minNumber"));
        assertEquals(10, ex.getError().getError().getParameters().get("minSpecialChar"));
        assertEquals(policy.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
        assertFalse(ex.getError().getError().getParameters().get("specialCharacterBase") == null);
        assertEquals(4, 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) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

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