Search in sources :

Example 26 with IdmRoleTreeNodeDto

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

the class RoleTreeNodeDeleteProcessor method process.

@Override
public EventResult<IdmRoleTreeNodeDto> process(EntityEvent<IdmRoleTreeNodeDto> event) {
    IdmRoleTreeNodeDto roleTreeNode = event.getContent();
    // Find all automatic role requests and remove relation on automatic role
    if (roleTreeNode.getId() != null) {
        // 
        // delete all assigned roles gained by this automatic role by long running task
        RemoveAutomaticRoleTaskExecutor automaticRoleTask = AutowireHelper.createBean(RemoveAutomaticRoleTaskExecutor.class);
        automaticRoleTask.setAutomaticRoleId(roleTreeNode.getId());
        longRunningTaskManager.executeSync(automaticRoleTask);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) RemoveAutomaticRoleTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.RemoveAutomaticRoleTaskExecutor)

Example 27 with IdmRoleTreeNodeDto

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

the class RoleTreeNodeSaveProcessor method process.

@Override
public EventResult<IdmRoleTreeNodeDto> process(EntityEvent<IdmRoleTreeNodeDto> event) {
    IdmRoleTreeNodeDto dto = event.getContent();
    // 
    dto = service.saveInternal(dto);
    event.setContent(dto);
    // 
    // assign role by this added automatic role to all existing identity contracts with long running task
    AddNewAutomaticRoleTaskExecutor automaticRoleTask = AutowireHelper.createBean(AddNewAutomaticRoleTaskExecutor.class);
    automaticRoleTask.setAutomaticRoleId(dto.getId());
    longRunningTaskManager.execute(automaticRoleTask);
    return new DefaultEventResult<>(event, this);
}
Also used : AddNewAutomaticRoleTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.AddNewAutomaticRoleTaskExecutor) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 28 with IdmRoleTreeNodeDto

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

the class DefaultIdmAutomaticRoleRequestService method executeRequestInternal.

private IdmAutomaticRoleRequestDto executeRequestInternal(UUID requestId) {
    Assert.notNull(requestId, "Role request ID is required!");
    IdmAutomaticRoleRequestDto request = this.get(requestId);
    Assert.notNull(request, "Role request is required!");
    IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
    ruleFilter.setRoleRequestId(requestId);
    List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
    UUID automaticRoleId = request.getAutomaticRole();
    if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType()) {
        // Automatic role by attributes
        if (RequestOperationType.REMOVE == request.getOperation()) {
            // Remove automatic role by attributes
            Assert.notNull(automaticRoleId, "Id of automatic role in the request (for delete) is required!");
            automaticRoleAttributeService.delete(automaticRoleAttributeService.get(automaticRoleId));
            request.setAutomaticRole(null);
        } else {
            // Add new or update (rules) for automatic role by attributes
            IdmAutomaticRoleAttributeDto automaticRole = null;
            if (automaticRoleId != null) {
                automaticRole = automaticRoleAttributeService.get(automaticRoleId);
            } else {
                automaticRole = new IdmAutomaticRoleAttributeDto();
                automaticRole = initAttributeAutomaticRole(request, automaticRole);
                automaticRole = automaticRoleAttributeService.save(automaticRole);
                request.setAutomaticRole(automaticRole.getId());
            }
            UUID roleId = automaticRole.getRole() != null ? automaticRole.getRole() : request.getRole();
            Assert.notNull(roleId, "Id of role is required in the automatic role request!");
            IdmRoleDto role = roleService.get(request.getRole());
            Assert.notNull(role, "Role is required in the automatic role request!");
            // Before we do any change, we have to sets the automatic role to concept state
            automaticRole.setConcept(true);
            automaticRoleAttributeService.save(automaticRole);
            // Realize changes for rules
            realizeAttributeRules(request, automaticRole, ruleConcepts);
            // Sets automatic role as no concept -> execute recalculation this role
            automaticRole.setConcept(false);
            automaticRoleAttributeService.recalculate(automaticRoleAttributeService.save(automaticRole).getId());
        }
    } else if (AutomaticRoleRequestType.TREE == request.getRequestType()) {
        // Automatic role by node in a tree
        if (RequestOperationType.REMOVE == request.getOperation()) {
            // Remove tree automatic role
            Assert.notNull(automaticRoleId, "Id of automatic role in the request (for delete) is required!");
            // Recount (remove) assigned roles ensures LRT during delete
            automaticRoleTreeService.delete(automaticRoleTreeService.get(automaticRoleId));
            request.setAutomaticRole(null);
        } else if (RequestOperationType.ADD == request.getOperation()) {
            // Create new tree automatic role
            IdmRoleTreeNodeDto treeAutomaticRole = new IdmRoleTreeNodeDto();
            treeAutomaticRole = initTreeAutomaticRole(request, treeAutomaticRole);
            // Recount of assigned roles ensures LRT after save
            treeAutomaticRole = automaticRoleTreeService.save(treeAutomaticRole);
            request.setAutomaticRole(treeAutomaticRole.getId());
        } else {
            // Update is not supported
            throw new ResultCodeException(CoreResultCode.METHOD_NOT_ALLOWED, "Tree automatic role update is not supported");
        }
    }
    request.setState(RequestState.EXECUTED);
    request.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
    return this.save(request);
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UUID(java.util.UUID) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 29 with IdmRoleTreeNodeDto

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

the class DefaultIdmRoleTreeNodeService method delete.

/**
 * Publish {@link RoleTreeNodeEvent} only.
 *
 * @see {@link RoleTreeNodeDeleteProcessor}
 */
@Override
@Transactional(noRollbackFor = AcceptedException.class)
public void delete(IdmRoleTreeNodeDto roleTreeNode, BasePermission... permission) {
    Assert.notNull(roleTreeNode);
    checkAccess(this.getEntity(roleTreeNode.getId()), permission);
    // 
    LOG.debug("Deleting automatic role [{}] - [{}] - [{}]", roleTreeNode.getRole(), roleTreeNode.getTreeNode(), roleTreeNode.getRecursionType());
    // 
    EventContext<IdmRoleTreeNodeDto> context = entityEventManager.process(new RoleTreeNodeEvent(RoleTreeNodeEventType.DELETE, roleTreeNode));
    // 
    if (context.isSuspended()) {
        throw new AcceptedException();
    }
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) RoleTreeNodeEvent(eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)29 Test (org.junit.Test)16 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)9 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)7 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)6 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)6 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)6 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)6 UUID (java.util.UUID)6 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)5 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)5 IdmRoleGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)3 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)2 ApiOperation (io.swagger.annotations.ApiOperation)2 LocalDate (org.joda.time.LocalDate)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2