Search in sources :

Example 6 with IdentityRoleEvent

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

the class DefaultIdmAutomaticRoleAttributeService method removeAutomaticRoles.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void removeAutomaticRoles(IdmIdentityRoleDto identityRole) {
    Assert.notNull(identityRole.getAutomaticRole(), "Automatic role is required.");
    // skip check granted authorities
    IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.DELETE, identityRole);
    event.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
    identityRoleService.publish(event);
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with IdentityRoleEvent

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

the class DefaultIdmRoleRequestService method updateAssignedRole.

/**
 * Update exists identity-role by concept
 *
 * @param concept
 * @param request
 * @param requestEvent
 */
private void updateAssignedRole(List<IdmConceptRoleRequestDto> allApprovedConcepts, IdmConceptRoleRequestDto concept, IdmRoleRequestDto request, EntityEvent<IdmRoleRequestDto> requestEvent) {
    IdmIdentityRoleDto identityRole = identityRoleService.get(concept.getIdentityRole());
    identityRole = convertConceptRoleToIdentityRole(allApprovedConcepts, concept, identityRole);
    @SuppressWarnings("deprecation") IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.UPDATE, identityRole, ImmutableMap.of(// ~ skip provisioning
    IdmAccountDto.SKIP_PROPAGATE, // ~ skip provisioning
    Boolean.TRUE, // sub roles are assigned by this request
    EntityEventManager.EVENT_PROPERTY_SKIP_SUB_ROLES, // sub roles are assigned by this request
    Boolean.TRUE));
    event.setPriority(PriorityType.IMMEDIATE);
    // propagate event
    identityRole = identityRoleService.publish(event, requestEvent).getContent();
    // Updated assigned roles by business roles
    Set<IdmIdentityRoleDto> subUpdatedIdentityRoles = event.getSetProperty(IdentityRoleEvent.PROPERTY_ASSIGNED_UPDATED_ROLES, IdmIdentityRoleDto.class);
    // Add to parent event
    Set<IdmIdentityRoleDto> updatedIdentityRoles = requestEvent.getSetProperty(IdentityRoleEvent.PROPERTY_ASSIGNED_UPDATED_ROLES, IdmIdentityRoleDto.class);
    updatedIdentityRoles.addAll(subUpdatedIdentityRoles);
    updatedIdentityRoles.add(identityRole);
    // Save created identity role id
    concept.setIdentityRole(identityRole.getId());
    concept.setState(RoleRequestState.EXECUTED);
    IdmRoleDto roleDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role);
    String message = MessageFormat.format("Role [{0}] was changed. Requested in concept [{1}].", roleDto.getCode(), concept.getId());
    conceptRoleRequestService.addToLog(concept, message);
    conceptRoleRequestService.addToLog(request, message);
    conceptRoleRequestService.save(concept);
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 8 with IdentityRoleEvent

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

the class DefaultIdmRoleRequestService method createAssignedRole.

/**
 * Create new identity-role by concept
 *
 * @param concept
 * @param request
 * @param requestEvent
 */
private void createAssignedRole(List<IdmConceptRoleRequestDto> allApprovedConcepts, IdmConceptRoleRequestDto concept, IdmRoleRequestDto request, EntityEvent<IdmRoleRequestDto> requestEvent) {
    IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
    identityRole = convertConceptRoleToIdentityRole(allApprovedConcepts, concept, identityRole);
    @SuppressWarnings("deprecation") IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.CREATE, identityRole, ImmutableMap.of(// ~ skip provisioning
    IdmAccountDto.SKIP_PROPAGATE, // ~ skip provisioning
    Boolean.TRUE, // sub roles are assigned by this request
    EntityEventManager.EVENT_PROPERTY_SKIP_SUB_ROLES, // sub roles are assigned by this request
    Boolean.TRUE));
    event.setPriority(PriorityType.IMMEDIATE);
    // propagate event
    identityRole = identityRoleService.publish(event, requestEvent).getContent();
    // New assigned roles by business roles
    Set<IdmIdentityRoleDto> subNewIdentityRoles = event.getSetProperty(IdentityRoleEvent.PROPERTY_ASSIGNED_NEW_ROLES, IdmIdentityRoleDto.class);
    // Add to parent event
    Set<IdmIdentityRoleDto> addedIdentityRoles = requestEvent.getSetProperty(IdentityRoleEvent.PROPERTY_ASSIGNED_NEW_ROLES, IdmIdentityRoleDto.class);
    addedIdentityRoles.addAll(subNewIdentityRoles);
    addedIdentityRoles.add(identityRole);
    // Save created identity role id
    concept.setIdentityRole(identityRole.getId());
    concept.setState(RoleRequestState.EXECUTED);
    IdmRoleDto roleDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role);
    String message = MessageFormat.format("Role [{0}] was added to applicant. Requested in concept [{1}].", roleDto.getCode(), concept.getId());
    conceptRoleRequestService.addToLog(concept, message);
    conceptRoleRequestService.addToLog(request, message);
    conceptRoleRequestService.save(concept);
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 9 with IdentityRoleEvent

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

the class DefaultIdmRoleCompositionService method removeSubRoles.

@Override
@Transactional
public void removeSubRoles(EntityEvent<IdmIdentityRoleDto> event, BasePermission... permission) {
    Assert.notNull(event, "Event is required.");
    IdmIdentityRoleDto directRole = event.getContent();
    Assert.notNull(directRole, "Direct role is required.");
    Assert.notNull(directRole.getId(), "Direct role identifier is required.");
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setDirectRoleId(directRole.getId());
    // 
    identityRoleService.find(filter, null).forEach(subIdentityRole -> {
        IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.DELETE, subIdentityRole);
        // 
        identityRoleService.publish(subEvent, event, permission);
        // Notes identity-accounts to ACM
        notingIdentityAccountForDelayedAcm(event, subEvent);
    });
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with IdentityRoleEvent

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

the class DefaultIdmRoleCompositionService method assignSubRoles.

/**
 * @Transactional is not needed - (asynchronous) events is thrown for every sub role anyway ...
 * Can be called repetitively for given identity role => checks or creates missing sub roles by composition.
 */
@Override
@SuppressWarnings("unchecked")
public void assignSubRoles(EntityEvent<IdmIdentityRoleDto> event, UUID roleCompositionId, BasePermission... permission) {
    Assert.notNull(event, "Event is required.");
    IdmIdentityRoleDto identityRole = event.getContent();
    Assert.notNull(identityRole, "Identity role identifier is required.");
    // find direct sub roles
    IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
    compositionFilter.setSuperiorId(identityRole.getRole());
    compositionFilter.setId(roleCompositionId);
    // 
    List<IdmRoleCompositionDto> directSubRoles = find(compositionFilter, null, permission).getContent();
    LOG.debug("Assign sub roles [{}] for identity role [{}], role [{}]", directSubRoles.size(), identityRole.getId(), identityRole.getRole());
    // 
    Map<String, Serializable> props = resolveProperties(event);
    Set<UUID> processedRoles = (Set<UUID>) props.get(IdentityRoleEvent.PROPERTY_PROCESSED_ROLES);
    processedRoles.add(identityRole.getRole());
    // 
    directSubRoles.forEach(subRoleComposition -> {
        IdmRoleDto subRole = DtoUtils.getEmbedded(subRoleComposition, IdmRoleComposition_.sub);
        if (processedRoles.contains(subRole.getId())) {
            LOG.debug("Role [{}] was already processed by other business role composition - cycle, skipping", subRole.getCode());
        } else {
            // try to find currently assigned subrole by this configuration (return operation)
            IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
            filter.setRoleCompositionId(subRoleComposition.getId());
            filter.setDirectRoleId(identityRole.getDirectRole() == null ? identityRole.getId() : identityRole.getDirectRole());
            if (identityRoleService.find(filter, null).getTotalElements() > 0) {
                LOG.debug("Role [{}] was already processed by other business role composition - cycle, skipping", subRole.getCode());
            } else {
                // 
                IdmIdentityRoleDto subIdentityRole = new IdmIdentityRoleDto();
                subIdentityRole.setRole(subRole.getId());
                subIdentityRole.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_ROLE, subRole);
                subIdentityRole.setIdentityContract(identityRole.getIdentityContract());
                subIdentityRole.setContractPosition(identityRole.getContractPosition());
                subIdentityRole.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT, identityRole.getEmbedded().get(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT));
                subIdentityRole.setValidFrom(identityRole.getValidFrom());
                subIdentityRole.setValidTill(identityRole.getValidTill());
                subIdentityRole.setDirectRole(identityRole.getDirectRole() == null ? identityRole.getId() : identityRole.getDirectRole());
                subIdentityRole.setRoleComposition(subRoleComposition.getId());
                // 
                processedRoles.add(subRole.getId());
                IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.CREATE, subIdentityRole, props);
                // 
                identityRoleService.publish(subEvent, event, permission);
                // Notes new created assigned role to parent event
                IdmIdentityRoleDto subContent = subEvent.getContent();
                notingAssignedRole(event, subEvent, subContent, IdentityRoleEvent.PROPERTY_ASSIGNED_NEW_ROLES);
            }
        }
    });
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) Serializable(java.io.Serializable) HashSet(java.util.HashSet) Set(java.util.Set) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter)

Aggregations

IdentityRoleEvent (eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent)14 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)11 Transactional (org.springframework.transaction.annotation.Transactional)6 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)5 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 UUID (java.util.UUID)3 IdmIdentityRoleValidRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleValidRequestDto)1 IdmRoleCompositionDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto)1 IdmConceptRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter)1 IdmRoleCompositionFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 Serializable (java.io.Serializable)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1