Search in sources :

Example 11 with BasePermission

use of eu.bcvsolutions.idm.core.security.api.domain.BasePermission in project CzechIdMng by bcvsolutions.

the class DefaultIdmRequestIdentityRoleService method save.

@Override
@Transactional
public IdmRequestIdentityRoleDto save(IdmRequestIdentityRoleDto dto, BasePermission... permission) {
    LOG.debug(MessageFormat.format("Save idm-request-identity-role [{0}] ", dto));
    Assert.notNull(dto, "DTO is required.");
    // We don`t know if is given DTO identity-role or role-concept.
    if (dto.getId() != null && dto.getId().equals(dto.getIdentityRole())) {
        // Given DTO is identity-role -> create UPDATE concept
        IdmIdentityRoleDto identityRole = identityRoleService.get(dto.getId());
        Assert.notNull(identityRole, "Identity role is required.");
        IdmIdentityContractDto identityContractDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.identityContract.getName(), IdmIdentityContractDto.class);
        UUID requestId = dto.getRoleRequest();
        IdmRoleRequestDto request = null;
        if (requestId == null) {
            request = this.createRequest(identityContractDto.getIdentity());
            requestId = request.getId();
        }
        IdmConceptRoleRequestDto conceptRoleRequest = createConcept(identityRole, identityContractDto, requestId, identityRole.getRole(), identityContractDto.getValidFrom(), identityContractDto.getValidTill(), ConceptRoleRequestOperation.UPDATE);
        conceptRoleRequest.setValidFrom(dto.getValidFrom());
        conceptRoleRequest.setValidTill(dto.getValidTill());
        conceptRoleRequest.setRoleSystem(dto.getRoleSystem());
        conceptRoleRequest.setEavs(dto.getEavs());
        // Create concept with EAVs
        conceptRoleRequest = conceptRoleService.save(conceptRoleRequest, permission);
        if (request != null) {
            // Add request to concept. Will be used on the FE (prevent loading of request).
            conceptRoleRequest.getEmbedded().put(IdmConceptRoleRequest_.roleRequest.getName(), request);
        }
        return this.conceptToRequestIdentityRole(conceptRoleRequest, null);
    } else if (dto.getId() == null && dto.getIdentityRole() == null) {
        // Given DTO does not have ID neither identity-role ID -> create ADD concept
        Assert.notNull(dto.getIdentityContract(), "Contract is required.");
        Set<UUID> roles = Sets.newHashSet();
        if (dto.getRole() != null) {
            roles.add(dto.getRole());
        }
        if (dto.getRoles() != null) {
            roles.addAll(dto.getRoles());
        }
        Assert.notEmpty(roles, "Roles cannot be empty!");
        IdmIdentityContractDto identityContractDto = identityContractService.get(dto.getIdentityContract());
        UUID requestId = dto.getRoleRequest();
        IdmRoleRequestDto request = null;
        if (requestId == null) {
            request = this.createRequest(identityContractDto.getIdentity());
            requestId = request.getId();
        }
        List<IdmConceptRoleRequestDto> concepts = Lists.newArrayList();
        UUID finalRequestId = requestId;
        IdmRoleRequestDto finalRequest = request;
        roles.forEach(role -> {
            IdmConceptRoleRequestDto conceptRoleRequest = createConcept(null, identityContractDto, finalRequestId, role, dto.getValidFrom(), dto.getValidTill(), ConceptRoleRequestOperation.ADD);
            conceptRoleRequest.setEavs(dto.getEavs());
            conceptRoleRequest.setRoleSystem(dto.getRoleSystem());
            // Create concept with EAVs
            conceptRoleRequest = conceptRoleService.save(conceptRoleRequest);
            if (finalRequest != null) {
                // Add request to concept. Will be used on the FE (prevent loading of request).
                conceptRoleRequest.getEmbedded().put(IdmConceptRoleRequest_.roleRequest.getName(), finalRequest);
            }
            concepts.add(conceptRoleRequest);
        });
        // Beware more then one concepts could be created, but only first will be returned!
        return this.conceptToRequestIdentityRole(concepts.get(0), null);
    } else {
        // Try to find role-concept
        IdmConceptRoleRequestDto roleConceptDto = conceptRoleService.get(dto.getId());
        if (roleConceptDto != null) {
            dto.setState(roleConceptDto.getState());
            if (ConceptRoleRequestOperation.UPDATE == roleConceptDto.getOperation()) {
                // Given DTO is concept -> update exists UPDATE concept
                return this.conceptToRequestIdentityRole(conceptRoleService.save(dto, permission), null);
            }
            if (ConceptRoleRequestOperation.ADD == roleConceptDto.getOperation()) {
                // Given DTO is concept -> update exists ADD concept
                return this.conceptToRequestIdentityRole(conceptRoleService.save(dto, permission), null);
            }
        }
    }
    return null;
}
Also used : IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AbstractReadDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadDtoService) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) IdmConceptRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest_) AbstractBaseDtoService(eu.bcvsolutions.idm.core.rest.AbstractBaseDtoService) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) Pageable(org.springframework.data.domain.Pageable) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ContractBasePermission(eu.bcvsolutions.idm.core.security.api.domain.ContractBasePermission) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) LocalDate(java.time.LocalDate) PageImpl(org.springframework.data.domain.PageImpl) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) IdmRoleSystemService(eu.bcvsolutions.idm.core.api.service.IdmRoleSystemService) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ModelMapper(org.modelmapper.ModelMapper) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) IdmRoleSystemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleSystemFilter) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) Set(java.util.Set) HashSet(java.util.HashSet) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) List(java.util.List) ArrayList(java.util.ArrayList) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with BasePermission

use of eu.bcvsolutions.idm.core.security.api.domain.BasePermission in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleCompositionService method findAllSubRoles.

private void findAllSubRoles(List<IdmRoleCompositionDto> results, List<IdmRoleCompositionDto> parents, UUID superiorId, BasePermission... permission) {
    IdmRoleCompositionFilter filter = new IdmRoleCompositionFilter();
    filter.setSuperiorId(superiorId);
    // 
    find(filter, null, permission).stream().filter(// cyclic composition in the first level is ignored
    subRole -> !subRole.getSuperior().equals(subRole.getSub())).forEach(subRole -> {
        if (!// duplicate composition is enabled, but from different superior role => is not cycle, is duplicate but ok
        parents.stream().map(IdmRoleCompositionDto::getSuperior).anyMatch(superior -> superior.equals(subRole.getSub()))) {
            results.add(subRole);
            List<IdmRoleCompositionDto> lineParents = Lists.newArrayList(parents);
            lineParents.add(subRole);
            // 
            IdmRoleDto subRoleDto = DtoUtils.getEmbedded(subRole, IdmRoleComposition_.sub);
            if (subRoleDto.getChildrenCount() > 0) {
                findAllSubRoles(results, lineParents, subRole.getSub(), permission);
            }
        }
    });
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRoleCompositionRepository(eu.bcvsolutions.idm.core.model.repository.IdmRoleCompositionRepository) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IdmRoleComposition(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) Lists(com.google.common.collect.Lists) Predicate(javax.persistence.criteria.Predicate) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdentityRoleEventType(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent.IdentityRoleEventType) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleComposition_(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_) AbstractEventableDtoService(eu.bcvsolutions.idm.core.api.service.AbstractEventableDtoService) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) Set(java.util.Set) IdmRoleCompositionService(eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService) IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) UUID(java.util.UUID) Serializable(java.io.Serializable) List(java.util.List) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter)

Example 13 with BasePermission

use of eu.bcvsolutions.idm.core.security.api.domain.BasePermission in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleCompositionService method findAllSuperiorRoles.

/**
 * @param results found parents
 * @param subId original role, for which parent are found => used for prevent cycles
 * @param subChildId curently processed sub role
 * @param permission
 */
private void findAllSuperiorRoles(List<IdmRoleCompositionDto> results, UUID subId, UUID subChildId, BasePermission... permission) {
    IdmRoleCompositionFilter filter = new IdmRoleCompositionFilter();
    filter.setSubId(subChildId);
    // 
    find(filter, null, permission).filter(// cyclic composition in the first level is ignored
    superiorRole -> !superiorRole.getSuperior().equals(superiorRole.getSub())).filter(// cyclic to original
    superiorRole -> !superiorRole.getSuperior().equals(subId)).forEach(superiorRole -> {
        if (!results.contains(superiorRole)) {
            results.add(superiorRole);
            // 
            findAllSuperiorRoles(results, subId, superiorRole.getSuperior(), permission);
        }
    });
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRoleCompositionRepository(eu.bcvsolutions.idm.core.model.repository.IdmRoleCompositionRepository) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IdmRoleComposition(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) Lists(com.google.common.collect.Lists) Predicate(javax.persistence.criteria.Predicate) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdentityRoleEventType(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent.IdentityRoleEventType) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleComposition_(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_) AbstractEventableDtoService(eu.bcvsolutions.idm.core.api.service.AbstractEventableDtoService) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) Set(java.util.Set) IdmRoleCompositionService(eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService) IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) UUID(java.util.UUID) Serializable(java.io.Serializable) List(java.util.List) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter)

Example 14 with BasePermission

use of eu.bcvsolutions.idm.core.security.api.domain.BasePermission in project CzechIdMng by bcvsolutions.

the class WorkflowTaskInstanceController method addDelegationToTask.

/**
 * Find and add definition of the delegation connected with this task.
 *
 * @param dto
 */
private void addDelegationToTask(WorkflowTaskInstanceDto dto, BasePermission... permission) {
    if (dto != null && dto.getId() != null) {
        // We need to create mock task, because DTO can be instance of historic task here.
        WorkflowTaskInstanceDto mockTask = new WorkflowTaskInstanceDto();
        mockTask.setId(dto.getId());
        UUID currentUserId = securityService.getCurrentId();
        boolean currentUserIsCandidate = dto.getIdentityLinks().stream().filter(identityLink -> IdentityLinkType.CANDIDATE.equals(identityLink.getType()) || IdentityLinkType.ASSIGNEE.equals(identityLink.getType())).anyMatch(identityLink -> currentUserId != null && UUID.fromString(identityLink.getUserId()).equals(currentUserId));
        boolean filterOnlyForCurrentUser = currentUserIsCandidate && !workflowTaskInstanceService.canReadAllTask(permission);
        List<IdmDelegationDto> delegations = delegationManager.findDelegationForOwner(mockTask, permission).stream().filter(delegation -> {
            // Filter only delegation where delegator or delegate is logged user (and user is not admin).
            if (!filterOnlyForCurrentUser) {
                return true;
            }
            IdmDelegationDefinitionDto definition = DtoUtils.getEmbedded(delegation, IdmDelegation_.definition.getName(), IdmDelegationDefinitionDto.class);
            return definition.getDelegate().equals(currentUserId) || definition.getDelegator().equals(currentUserId);
        }).sorted(Comparator.comparing(IdmDelegationDto::getCreated)).collect(Collectors.toList());
        // TODO: ONLY first delegation definition is sets to the task!
        if (!CollectionUtils.isEmpty(delegations)) {
            Collections.reverse(delegations);
            IdmDelegationDto delegation = delegations.get(0);
            IdmDelegationDefinitionDto definition = DtoUtils.getEmbedded(delegation, IdmDelegation_.definition.getName(), IdmDelegationDefinitionDto.class);
            dto.setDelegationDefinition(definition);
        }
    }
}
Also used : IdmDelegation_(eu.bcvsolutions.idm.core.model.entity.IdmDelegation_) FormDataWrapperDto(eu.bcvsolutions.idm.core.workflow.model.dto.FormDataWrapperDto) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Valid(javax.validation.Valid) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) ApiOperation(io.swagger.annotations.ApiOperation) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) Pageable(org.springframework.data.domain.Pageable) AuthorizationScope(io.swagger.annotations.AuthorizationScope) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) WorkflowTaskInstanceAbstractDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceAbstractDto) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) AbstractReadDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadDtoController) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) DelegationManager(eu.bcvsolutions.idm.core.api.service.DelegationManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) BulkActionManager(eu.bcvsolutions.idm.core.api.bulk.action.BulkActionManager) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) RequestBody(org.springframework.web.bind.annotation.RequestBody) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SwaggerConfig(eu.bcvsolutions.idm.core.api.config.swagger.SwaggerConfig) CollectionUtils(org.apache.commons.collections.CollectionUtils) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) Api(io.swagger.annotations.Api) MultiValueMap(org.springframework.util.MultiValueMap) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) BaseDtoController(eu.bcvsolutions.idm.core.api.rest.BaseDtoController) PageableDefault(org.springframework.data.web.PageableDefault) Resources(org.springframework.hateoas.Resources) ResponseEntity(org.springframework.http.ResponseEntity) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) Comparator(java.util.Comparator) Authorization(io.swagger.annotations.Authorization) Collections(java.util.Collections) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) UUID(java.util.UUID)

Example 15 with BasePermission

use of eu.bcvsolutions.idm.core.security.api.domain.BasePermission in project CzechIdMng by bcvsolutions.

the class DefaultFormService method findFormInstance.

@Override
@Transactional(readOnly = true)
public IdmFormInstanceDto findFormInstance(Identifiable owner, IdmFormDefinitionDto formDefinition, FormableFilter filter, BasePermission... permission) {
    Assert.notNull(owner, "Form values owner is required.");
    Assert.notNull(owner.getId(), "Owner id is required.");
    // 
    BasePermission[] permissions = PermissionUtils.trimNull(permission);
    FormableEntity ownerEntity = getOwnerEntity(owner);
    // Definition will be reloaded only if is given definition trimmed (we need to not reloading the definition in case use the sub-definition (role-attributes))
    formDefinition = checkDefaultDefinition(owner.getClass(), formDefinition);
    if (formDefinition.isTrimmed()) {
        // load => prevent to modify input definition
        formDefinition = getDefinition(formDefinition.getId());
    }
    FormValueService<FormableEntity> formValueService = getFormValueService(owner);
    // 
    // construct value filter
    IdmFormValueFilter<FormableEntity> valueFilter = toValueFilter(ownerEntity, formDefinition, filter);
    // find form values
    List<IdmFormValueDto> values = formValueService.find(valueFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(AbstractFormValue_.seq.getName())), permission).getContent();
    IdmFormInstanceDto formInstance = new IdmFormInstanceDto(ownerEntity, formDefinition, values);
    // evaluate permissions for form definition attributes by values - change attribute properties or remove attribute at all
    if (!ObjectUtils.isEmpty(permissions)) {
        Set<UUID> checkedAttributes = new HashSet<>(values.size());
        for (IdmFormValueDto value : values) {
            checkedAttributes.add(value.getFormAttribute());
            Set<String> valuePermissions = formValueService.getPermissions(value);
            if (!PermissionUtils.hasPermission(valuePermissions, IdmBasePermission.READ)) {
                // TODO: hidden?
                formInstance.getFormDefinition().removeFormAttribute(value.getFormAttribute());
            } else if (!PermissionUtils.hasPermission(valuePermissions, IdmBasePermission.UPDATE)) {
                formInstance.getMappedAttribute(value.getFormAttribute()).setReadonly(true);
            }
        }
        // evaluate permissions for new values - iterate through unprocessed attributes and check update permission
        List<IdmFormAttributeDto> formAttributes = Lists.newArrayList(formInstance.getFormDefinition().getFormAttributes());
        for (IdmFormAttributeDto formAttribute : formAttributes) {
            if (checkedAttributes.contains(formAttribute.getId())) {
                continue;
            }
            IdmFormValueDto newValue = new IdmFormValueDto();
            newValue.setOwnerAndAttribute(ownerEntity, formAttribute);
            Set<String> valuePermissions = formValueService.getPermissions(newValue);
            if (!PermissionUtils.hasPermission(valuePermissions, IdmBasePermission.READ)) {
                // TODO: hidden?
                formInstance.getFormDefinition().removeFormAttribute(newValue.getFormAttribute());
            } else if (!PermissionUtils.hasPermission(valuePermissions, IdmBasePermission.UPDATE)) {
                formAttribute.setReadonly(true);
            }
        }
    }
    // 
    // apply overridden attributes by form projection
    formInstance.setFormDefinition(formProjectionManager.overrideFormDefinition(owner, formInstance.getFormDefinition()));
    // 
    return formInstance;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) UUID(java.util.UUID) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BasePermission (eu.bcvsolutions.idm.core.security.api.domain.BasePermission)18 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)10 ArrayList (java.util.ArrayList)10 UUID (java.util.UUID)10 List (java.util.List)9 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Lists (com.google.common.collect.Lists)7 HashSet (java.util.HashSet)7 Transactional (org.springframework.transaction.annotation.Transactional)7 DtoUtils (eu.bcvsolutions.idm.core.api.utils.DtoUtils)6 Serializable (java.io.Serializable)6 Collectors (java.util.stream.Collectors)6 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)5 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)5 AuthorizableType (eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType)5 HashMap (java.util.HashMap)5 Set (java.util.Set)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)5