Search in sources :

Example 11 with IdentityEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.

the class EntityEventProcessorUnitTest method testSupportRoleDeleteOnly.

@Test
public void testSupportRoleDeleteOnly() {
    EntityEventProcessor<?> processor = new EventProcessorRole();
    assertFalse(processor.supports(new IdentityEvent(IdentityEventType.UPDATE, new IdmIdentityDto())));
    assertFalse(processor.supports(new IdentityEvent(IdentityEventType.DELETE, new IdmIdentityDto())));
    assertTrue(processor.supports(new RoleEvent(RoleEventType.DELETE, new IdmRoleDto())));
    assertFalse(processor.supports(new CoreEvent<IdmIdentityDto>(CustomType.SAVE, new IdmIdentityDto())));
    assertFalse(processor.supports(new CoreEvent<>(CustomType.CUSTOM, new IdmIdentityDto())));
    assertTrue(processor.supports(new CoreEvent<IdmRoleDto>(IdentityEventType.UPDATE, new IdmRoleDto())));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) RoleEvent(eu.bcvsolutions.idm.core.model.event.RoleEvent) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 12 with IdentityEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerIntergationTest method testOriginalSource.

@Test
public void testOriginalSource() {
    IdmIdentityDto createdIdentity = helper.createIdentity();
    // process change
    IdmIdentityDto updateIdentity = identityService.get(createdIdentity.getId());
    updateIdentity.setFirstName("newFirst");
    updateIdentity.setLastName("newLast");
    EntityEvent<IdmIdentityDto> event = new IdentityEvent(IdentityEventType.UPDATE, updateIdentity);
    EventContext<IdmIdentityDto> context = entityEventManager.process(event);
    IdmIdentityDto originalIdentity = context.getLastResult().getEvent().getOriginalSource();
    IdmIdentityDto savedIdentity = context.getLastResult().getEvent().getContent();
    // check
    assertEquals(createdIdentity.getUsername(), originalIdentity.getUsername());
    assertEquals(createdIdentity.getFirstName(), originalIdentity.getFirstName());
    assertEquals(createdIdentity.getLastName(), originalIdentity.getLastName());
    assertEquals(updateIdentity.getUsername(), savedIdentity.getUsername());
    assertEquals(updateIdentity.getFirstName(), savedIdentity.getFirstName());
    assertEquals(updateIdentity.getLastName(), savedIdentity.getLastName());
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with IdentityEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityService method passwordChange.

/**
 * Changes given identity's password
 *
 * @param identity
 * @param passwordChangeDto
 */
@Override
@Transactional
public List<OperationResult> passwordChange(IdmIdentityDto identity, PasswordChangeDto passwordChangeDto) {
    Assert.notNull(identity);
    // 
    LOG.debug("Changing password for identity [{}]", identity.getUsername());
    EventContext<IdmIdentityDto> context = entityEventManager.process(new IdentityEvent(IdentityEventType.PASSWORD, identity, ImmutableMap.of(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO, passwordChangeDto)));
    // get all password change results
    // more provisioning operation can be executed for one password change - we need to distinct them by account id
    // accountId / result
    Map<UUID, OperationResult> passwordChangeResults = new HashMap<>();
    context.getResults().forEach(eventResult -> {
        eventResult.getResults().forEach(result -> {
            if (result.getModel() != null) {
                boolean success = result.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name());
                boolean failure = result.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_FAILED.name());
                if (success || failure) {
                    IdmAccountDto resultAccount = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
                    if (!passwordChangeResults.containsKey(resultAccount.getId())) {
                        passwordChangeResults.put(resultAccount.getId(), result);
                    } else if (failure) {
                        // failure has higher priority
                        passwordChangeResults.put(resultAccount.getId(), result);
                    }
                }
            }
        });
    });
    return new ArrayList<>(passwordChangeResults.values());
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) HashMap(java.util.HashMap) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) ArrayList(java.util.ArrayList) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdentityEvent (eu.bcvsolutions.idm.core.model.event.IdentityEvent)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)12 Test (org.junit.Test)6 IdentityState (eu.bcvsolutions.idm.core.api.domain.IdentityState)4 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)4 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)4 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 RoleEvent (eu.bcvsolutions.idm.core.model.event.RoleEvent)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 IdmAccountDto (eu.bcvsolutions.idm.core.api.dto.IdmAccountDto)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 IdentityContractEvent (eu.bcvsolutions.idm.core.model.event.IdentityContractEvent)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Transactional (org.springframework.transaction.annotation.Transactional)1