Search in sources :

Example 1 with IdentityAccountEvent

use of eu.bcvsolutions.idm.acc.event.IdentityAccountEvent in project CzechIdMng by bcvsolutions.

the class RoleRequestRealizationProcessor method process.

@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
    IdmRoleRequestDto request = event.getContent();
    IdmIdentityDto identity = identityService.get(request.getApplicant());
    Set<IdmIdentityRoleDto> addedIdentityRoles = this.getSetProperty(IdentityRoleEvent.PROPERTY_ASSIGNED_NEW_ROLES, event, IdmIdentityRoleDto.class);
    Set<IdmIdentityRoleDto> updatedIdentityRoles = this.getSetProperty(IdentityRoleEvent.PROPERTY_ASSIGNED_UPDATED_ROLES, event, IdmIdentityRoleDto.class);
    Set<UUID> removedIdentityAccounts = this.getSetProperty(IdmAccountDto.IDENTITY_ACCOUNT_FOR_DELAYED_ACM, event, UUID.class);
    Set<UUID> accountsForAdditionalProvisioning = this.getSetProperty(IdmAccountDto.ACCOUNT_FOR_ADDITIONAL_PROVISIONING, event, UUID.class);
    boolean skipProvisioning = this.getBooleanProperty(ProvisioningService.SKIP_PROVISIONING, event.getProperties());
    Set<UUID> accountsForProvisioning = new HashSet<>(accountsForAdditionalProvisioning);
    if (addedIdentityRoles.size() > 0) {
        LOG.debug("Call account management for identity [{}] and new identity-roles [{}]", identity.getUsername(), addedIdentityRoles);
        List<UUID> accounts = accountManagementService.resolveNewIdentityRoles(identity, addedIdentityRoles.toArray(new IdmIdentityRoleDto[0]));
        addAccounts(accountsForProvisioning, accounts);
    }
    if (updatedIdentityRoles.size() > 0) {
        LOG.debug("Call account management for identity [{}] and updated identity-roles [{}]", identity.getUsername(), updatedIdentityRoles);
        List<UUID> accounts = accountManagementService.resolveUpdatedIdentityRoles(identity, updatedIdentityRoles.toArray(new IdmIdentityRoleDto[0]));
        addAccounts(accountsForProvisioning, accounts);
    }
    // Remove delayed identity-accounts (includes provisioning)
    if (removedIdentityAccounts.size() > 0) {
        LOG.debug("Call account management for identity [{}] - remove identity-accounts [{}]", identity.getUsername(), removedIdentityAccounts);
        removedIdentityAccounts.stream().distinct().forEach(identityAccountId -> {
            AccIdentityAccountDto identityAccountDto = identityAccountService.get(identityAccountId);
            if (identityAccountDto != null) {
                IdentityAccountEvent eventIdentityAccount = new IdentityAccountEvent(IdentityAccountEventType.DELETE, identityAccountDto, ImmutableMap.of(AccIdentityAccountService.DELETE_TARGET_ACCOUNT_KEY, Boolean.TRUE, AccIdentityAccountService.FORCE_DELETE_OF_IDENTITY_ACCOUNT_KEY, Boolean.FALSE, IdmRoleRequestService.ROLE_REQUEST_ID_KEY, request.getId()));
                identityAccountService.publish(eventIdentityAccount);
                accountsForProvisioning.add(identityAccountDto.getAccount());
            }
        });
    }
    // Init context in identity DTO and set ID of role-request to it.
    initContext(identity, request);
    // Skip provisionig
    if (skipProvisioning) {
        return new DefaultEventResult<>(event, this);
    }
    // Provisioning for modified account
    accountsForProvisioning.forEach(accountId -> {
        AccAccountDto account = accountService.get(accountId);
        if (account != null) {
            // Account could be null (was deleted).
            LOG.debug("Call provisioning for identity [{}] and account [{}]", identity.getUsername(), account.getUid());
            provisioningService.doProvisioning(account, identity);
        }
    });
    return new DefaultEventResult<>(event, this);
}
Also used : AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdentityAccountEvent(eu.bcvsolutions.idm.acc.event.IdentityAccountEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) HashSet(java.util.HashSet)

Example 2 with IdentityAccountEvent

use of eu.bcvsolutions.idm.acc.event.IdentityAccountEvent in project CzechIdMng by bcvsolutions.

the class DefaultAccIdentityAccountService method delete.

private void delete(AccIdentityAccountDto entity, boolean deleteTargetAccount, boolean forceDelete, BasePermission... permission) {
    Assert.notNull(entity, "Entity is required.");
    checkAccess(this.getEntity(entity.getId()), permission);
    // 
    LOG.debug("Deleting identity account [{}]", entity);
    entityEventManager.process(new IdentityAccountEvent(IdentityAccountEventType.DELETE, entity, ImmutableMap.of(AccIdentityAccountService.DELETE_TARGET_ACCOUNT_KEY, deleteTargetAccount, AccIdentityAccountService.FORCE_DELETE_OF_IDENTITY_ACCOUNT_KEY, forceDelete)));
}
Also used : IdentityAccountEvent(eu.bcvsolutions.idm.acc.event.IdentityAccountEvent)

Aggregations

IdentityAccountEvent (eu.bcvsolutions.idm.acc.event.IdentityAccountEvent)2 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)1 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1