Search in sources :

Example 1 with IdmIdentityDto

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

the class IdentityDeleteProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto identity = event.getContent();
    // contracts
    identityContractService.findAllByIdentity(identity.getId()).forEach(identityContract -> {
        // when identity is deleted, then HR processes has to be shipped (prevent to update deleted identity, when contract is removed)
        Map<String, Serializable> properties = new HashMap<>();
        properties.put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
        identityContractService.publish(new CoreEvent<>(CoreEventType.DELETE, identityContract, properties));
    });
    // contract guaratee - set to null
    // delete contract guarantees
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setGuaranteeId(identity.getId());
    contractGuaranteeService.find(filter, null).forEach(guarantee -> {
        contractGuaranteeService.delete(guarantee);
    });
    // remove role guarantee
    IdmRoleGuaranteeFilter roleGuaranteeFilter = new IdmRoleGuaranteeFilter();
    roleGuaranteeFilter.setGuarantee(identity.getId());
    roleGuaranteeService.find(roleGuaranteeFilter, null).forEach(roleGuarantee -> {
        roleGuaranteeService.delete(roleGuarantee);
    });
    // remove password
    passwordProcessor.deletePassword(identity);
    // set to null all notification recipients - real recipient remains (email etc.)
    notificationRecipientRepository.clearIdentity(identity.getId());
    // remove authorities last changed relation
    deleteAuthorityChange(identity);
    // Delete all role requests where is this identity applicant
    IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
    roleRequestFilter.setApplicantId(identity.getId());
    roleRequestService.find(roleRequestFilter, null).forEach(request -> {
        roleRequestService.delete(request);
    });
    // remove all IdentityRoleValidRequest for this identity
    List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityId(identity.getId());
    identityRoleValidRequestService.deleteAll(validRequests);
    // deletes identity
    service.deleteInternal(identity);
    return new DefaultEventResult<>(event, this);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmIdentityRoleValidRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleValidRequestDto)

Example 2 with IdmIdentityDto

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

the class IdentityMonitoredFieldsProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    List<String> fields = getCommaSeparatedValues((String) this.getConfigurationMap().get(PROPERTY_MONITORED_FIELDS));
    String recipientsRole = (String) this.getConfigurationMap().get(PROPERTY_RECIPIENTS_ROLE);
    if (CollectionUtils.isEmpty(fields)) {
        LOG.debug("None monitored fields found in configuration.");
        return new DefaultEventResult<>(event, this);
    }
    List<IdmIdentityDto> recipients = service.findAllByRoleName(recipientsRole);
    if (CollectionUtils.isEmpty(recipients)) {
        LOG.debug("None recievers found in configuration.");
        return new DefaultEventResult<>(event, this);
    }
    IdmIdentityDto newIdentity = event.getContent();
    IdmIdentityDto identity = event.getOriginalSource();
    List<ChangedField> changedFields = new ArrayList<>();
    // Check monitored fields on some changes
    fields.forEach(field -> {
        try {
            Object value = EntityUtils.getEntityValue(identity, field);
            Object newValue = EntityUtils.getEntityValue(newIdentity, field);
            if (value == null && newValue == null) {
                return;
            }
            if (value != null && !value.equals(newValue)) {
                changedFields.add(new ChangedField(field, value.toString(), newValue == null ? null : newValue.toString()));
                return;
            }
            if (newValue != null && !newValue.equals(value)) {
                changedFields.add(new ChangedField(field, value == null ? null : value.toString(), newValue.toString()));
                return;
            }
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | IntrospectionException e) {
            throw new ResultCodeException(CoreResultCode.BAD_REQUEST, e);
        }
    });
    if (!changedFields.isEmpty()) {
        IdmMessageDto message = new IdmMessageDto.Builder(NotificationLevel.WARNING).addParameter("fullName", service.getNiceLabel(identity)).addParameter("identity", identity).addParameter("changedFields", changedFields).addParameter("url", configurationService.getFrontendUrl(String.format("identity/%s/profile", identity.getId()))).build();
        notificationManager.send(String.format("core:%s", TOPIC), message, recipients);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) ArrayList(java.util.ArrayList) IntrospectionException(java.beans.IntrospectionException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 3 with IdmIdentityDto

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

the class AuditableListener method onPreInsert.

@Override
public boolean onPreInsert(PreInsertEvent event) {
    if (event.getEntity() instanceof Auditable) {
        DateTime date = new DateTime();
        Auditable entity = (Auditable) event.getEntity();
        // 
        setValue(event.getState(), event, Auditable.PROPERTY_CREATED, date);
        entity.setCreated(date);
        // 
        AbstractAuthentication authentication = securityService.getAuthentication();
        IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
        IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
        if (entity.getCreator() == null) {
            String creator = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
            setValue(event.getState(), event, Auditable.PROPERTY_CREATOR, creator);
            entity.setCreator(creator);
            // 
            UUID creatorId = currentIdentity == null ? null : currentIdentity.getId();
            setValue(event.getState(), event, Auditable.PROPERTY_CREATOR_ID, creatorId);
            entity.setCreatorId(creatorId);
        }
        // could be filled in wf (applicant) ...
        if (entity.getOriginalCreator() == null) {
            String originalCreator = originalIdentity == null ? null : originalIdentity.getUsername();
            setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_CREATOR, originalCreator);
            entity.setOriginalCreator(originalCreator);
            // 
            UUID originalCreatorId = originalIdentity == null ? null : originalIdentity.getId();
            setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_CREATOR_ID, originalCreatorId);
            entity.setOriginalCreatorId(originalCreatorId);
        }
    }
    return false;
}
Also used : Auditable(eu.bcvsolutions.idm.core.api.domain.Auditable) AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) DateTime(org.joda.time.DateTime)

Example 4 with IdmIdentityDto

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

the class IdmAuditListener method changeRevisionDto.

private void changeRevisionDto(Class<AbstractEntity> entityClass, String entityName, UUID entityId, IdmAuditDto revisionEntity, RevisionType revisionType) {
    // List<String> changedColumns;
    // name of entity class - full name.
    revisionEntity.setType(entityName);
    // revision type - MOD, DEL, ADD
    revisionEntity.setModification(revisionType.name());
    // action executer identity
    AbstractAuthentication authentication = securityService.getAuthentication();
    IdmIdentityDto currentModifierIdentity = authentication == null ? null : authentication.getCurrentIdentity();
    IdmIdentityDto originalModifierIdentity = authentication == null ? null : authentication.getOriginalIdentity();
    // 
    revisionEntity.setModifier(securityService.getUsername());
    revisionEntity.setModifierId(currentModifierIdentity == null ? null : currentModifierIdentity.getId());
    // original action executer identity (before switch)
    revisionEntity.setOriginalModifier(securityService.getOriginalUsername());
    revisionEntity.setOriginalModifierId(originalModifierIdentity == null ? null : originalModifierIdentity.getId());
    // entity id
    revisionEntity.setEntityId((UUID) entityId);
    // 
    // get entity in new transaction if revision type is delete
    AbstractEntity currentEntity = null;
    if (revisionType == RevisionType.DEL) {
        currentEntity = auditService.getActualRemovedEntity(entityClass, entityId);
    } else {
        currentEntity = (AbstractEntity) entityManger.find(entityClass, entityId);
    }
    // 
    if (currentEntity instanceof AuditSearchable) {
        AuditSearchable searchableEntity = ((AuditSearchable) currentEntity);
        revisionEntity.setOwnerCode(searchableEntity.getOwnerCode());
        revisionEntity.setOwnerId(searchableEntity.getOwnerId());
        revisionEntity.setOwnerType(searchableEntity.getOwnerType());
        revisionEntity.setSubOwnerCode(searchableEntity.getSubOwnerCode());
        revisionEntity.setSubOwnerId(searchableEntity.getSubOwnerId());
        revisionEntity.setSubOwnerType(searchableEntity.getSubOwnerType());
    } else if (currentEntity instanceof Codeable) {
        revisionEntity.setOwnerCode(((Codeable) currentEntity).getCode());
    }
}
Also used : AuditSearchable(eu.bcvsolutions.idm.core.api.domain.AuditSearchable) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 5 with IdmIdentityDto

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

the class PasswordExpiredTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmPasswordDto dto) {
    IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, dto.getIdentity());
    LOG.info("Publishing [{}] event to identity [{}], password expired in [{}]", IdentityEventType.PASSWORD_EXPIRED, identity.getUsername(), dto.getValidTill());
    try {
        entityEventManager.process(new IdentityEvent(IdentityEventType.PASSWORD_EXPIRED, identity));
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    } catch (Exception ex) {
        LOG.error("Publishing [{}] event to identity [{}], password expired in [{}] failed", IdentityEventType.PASSWORD_EXPIRED, dto.getIdentity(), dto.getValidTill(), ex);
        return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build());
    }
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Aggregations

IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)568 Test (org.junit.Test)433 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)328 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)206 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)157 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)99 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)95 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)69 ArrayList (java.util.ArrayList)63 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)61 UUID (java.util.UUID)59 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)58 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)55 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)54 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)54 Transactional (org.springframework.transaction.annotation.Transactional)53 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)51 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)50 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)49 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)48