Search in sources :

Example 1 with PasswordChangeDto

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

the class DefaultSysProvisioningServiceTest method testPasswordChangeWithAdditionalAttributesInTwoOperations.

@Test
public void testPasswordChangeWithAdditionalAttributesInTwoOperations() {
    configurationService.setBooleanValue(ProvisioningConfiguration.PROPERTY_SEND_PASSWORD_ATTRIBUTES_TOGETHER, false);
    try {
        Assert.assertFalse(provisioningConfiguration.isSendPasswordAttributesTogether());
        // prepare account on target system
        SysSystemDto system = helper.createTestResourceSystem(true);
        SysSystemMappingDto systemMapping = helper.getDefaultMapping(system);
        SysSystemAttributeMappingDto firtstNameAttribute = systemAttributeMappingService.findBySystemMappingAndName(systemMapping.getId(), TestHelper.ATTRIBUTE_MAPPING_FIRSTNAME);
        firtstNameAttribute.setSendOnPasswordChange(Boolean.TRUE);
        systemAttributeMappingService.save(firtstNameAttribute);
        IdmRoleDto role = helper.createRole();
        helper.createRoleSystem(role, system);
        IdmIdentityDto identity = helper.createIdentity();
        helper.createIdentityRole(identity, role);
        // 
        AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
        filter.setIdentityId(identity.getId());
        AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
        AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
        // Create new password one
        PasswordChangeDto passwordChange = new PasswordChangeDto();
        passwordChange.setAccounts(ImmutableList.of(account.getId().toString()));
        passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_ONE));
        passwordChange.setIdm(true);
        // 
        // Do change of password for selected accounts
        String firstNameChange = "firstname-change";
        identity.setFirstName(firstNameChange);
        idmIdentityService.passwordChange(identity, passwordChange);
        // 
        // Check correct password One
        TestResource resource = helper.findResource(account.getRealUid());
        Assert.assertNotNull(resource);
        Assert.assertEquals(IDENTITY_PASSWORD_ONE, resource.getPassword());
        Assert.assertEquals(firstNameChange, resource.getFirstname());
    } finally {
        configurationService.setBooleanValue(ProvisioningConfiguration.PROPERTY_SEND_PASSWORD_ATTRIBUTES_TOGETHER, true);
        Assert.assertTrue(provisioningConfiguration.isSendPasswordAttributesTogether());
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) 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 2 with PasswordChangeDto

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

the class DefaultSysProvisioningServiceTest method testPasswordChangeWithoutAdditionalAttributes.

@Test
public void testPasswordChangeWithoutAdditionalAttributes() {
    // prepare account on target system
    SysSystemDto system = helper.createTestResourceSystem(true);
    IdmRoleDto role = helper.createRole();
    helper.createRoleSystem(role, system);
    IdmIdentityDto identity = helper.createIdentity();
    helper.createIdentityRole(identity, role);
    // 
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
    AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
    // Create new password one
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setAccounts(ImmutableList.of(account.getId().toString()));
    passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_ONE));
    passwordChange.setIdm(true);
    // 
    // Do change of password for selected accounts
    String previousFirtsName = identity.getFirstName();
    String firstNameChange = "firstname-change";
    identity.setFirstName(firstNameChange);
    idmIdentityService.passwordChange(identity, passwordChange);
    // 
    // Check correct password One
    TestResource resource = helper.findResource(account.getRealUid());
    Assert.assertNotNull(resource);
    Assert.assertEquals(IDENTITY_PASSWORD_ONE, resource.getPassword());
    Assert.assertEquals(previousFirtsName, resource.getFirstname());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) 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 3 with PasswordChangeDto

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

the class DefaultSysProvisioningServiceTest method testPasswordChangeWithAdditionalAttributesInOneOperation.

@Test
public void testPasswordChangeWithAdditionalAttributesInOneOperation() {
    Assert.assertTrue(provisioningConfiguration.isSendPasswordAttributesTogether());
    // 
    // prepare account on target system
    SysSystemDto system = helper.createTestResourceSystem(true);
    SysSystemMappingDto systemMapping = helper.getDefaultMapping(system);
    SysSystemAttributeMappingDto firtstNameAttribute = systemAttributeMappingService.findBySystemMappingAndName(systemMapping.getId(), TestHelper.ATTRIBUTE_MAPPING_FIRSTNAME);
    firtstNameAttribute.setSendOnPasswordChange(Boolean.TRUE);
    systemAttributeMappingService.save(firtstNameAttribute);
    IdmRoleDto role = helper.createRole();
    helper.createRoleSystem(role, system);
    IdmIdentityDto identity = helper.createIdentity();
    helper.createIdentityRole(identity, role);
    // 
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
    AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
    // Create new password one
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setAccounts(ImmutableList.of(account.getId().toString()));
    passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_ONE));
    passwordChange.setIdm(true);
    // 
    // Do change of password for selected accounts
    String firstNameChange = "firstname-change";
    identity.setFirstName(firstNameChange);
    idmIdentityService.passwordChange(identity, passwordChange);
    // 
    // Check correct password One
    TestResource resource = helper.findResource(account.getRealUid());
    Assert.assertNotNull(resource);
    Assert.assertEquals(IDENTITY_PASSWORD_ONE, resource.getPassword());
    Assert.assertEquals(firstNameChange, resource.getFirstname());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) 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 4 with PasswordChangeDto

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

the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangePassword.

@Test
public void doIdentityProvisioningChangePassword() {
    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());
    // Create new password one
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setAccounts(ImmutableList.of(accountIdentityOne.getAccount().toString()));
    passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_ONE));
    passwordChange.setIdm(true);
    // Do change of password for selected accounts
    idmIdentityService.passwordChange(identity, passwordChange);
    accountIdentityOne = identityAccoutnService.get(accountIdentityOne.getId());
    // Check correct password One
    provisioningService.authenticate(accountService.get(accountIdentityOne.getAccount()).getUid(), new GuardedString(IDENTITY_PASSWORD_ONE), system, SystemEntityType.IDENTITY);
    // Check incorrect password
    try {
        provisioningService.authenticate(accountService.get(accountIdentityOne.getAccount()).getUid(), new GuardedString(IDENTITY_PASSWORD_TWO), system, SystemEntityType.IDENTITY);
        fail("Bad credentials exception is expected here!");
    } catch (ResultCodeException ex) {
    // 
    }
    // Do change of password for selected accounts
    passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_TWO));
    idmIdentityService.passwordChange(idmIdentityService.get(accountIdentityOne.getIdentity()), passwordChange);
    // Check correct password Two
    accountIdentityOne = identityAccoutnService.get(accountIdentityOne.getId());
    provisioningService.authenticate(accountService.get(accountIdentityOne.getAccount()).getUid(), new GuardedString(IDENTITY_PASSWORD_TWO), system, SystemEntityType.IDENTITY);
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) 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 5 with PasswordChangeDto

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

the class IdentityPasswordProvisioningProcessor 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);
    // 
    LOG.debug("Call provisioning for identity password [{}]", event.getContent().getUsername());
    List<OperationResult> results = provisioningService.changePassword(identity, passwordChangeDto);
    // 
    return new DefaultEventResult.Builder<>(event, this).setResults(results).build();
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

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