Search in sources :

Example 1 with BPSGroupIdentityManager

use of org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager in project carbon-business-process by wso2.

the class BPMNOSGIService method getGroupIdentityManager.

public static BPSGroupIdentityManager getGroupIdentityManager() {
    ProcessEngineImpl processEngine = (ProcessEngineImpl) getBPMNEngineService().getProcessEngine();
    ProcessEngineConfigurationImpl processEngineConfigurationImpl = null;
    if (processEngine != null) {
        processEngineConfigurationImpl = processEngine.getProcessEngineConfiguration();
        if (processEngineConfigurationImpl != null) {
            BPSGroupIdentityManager bpsGroupIdentityManager = null;
            if (processEngineConfigurationImpl.getSessionFactories() != null) {
                BPSGroupManagerFactory bpsGroupManagerFactory = (BPSGroupManagerFactory) processEngineConfigurationImpl.getSessionFactories().get(GroupIdentityManager.class);
                return (BPSGroupIdentityManager) bpsGroupManagerFactory.openSession();
            }
        }
    }
    throw new BPMNOSGIServiceException("Business Process Server Group manager couldn't be identified");
}
Also used : BPSGroupManagerFactory(org.wso2.carbon.bpmn.core.integration.BPSGroupManagerFactory) BPMNOSGIServiceException(org.wso2.carbon.bpmn.rest.common.exception.BPMNOSGIServiceException) GroupIdentityManager(org.activiti.engine.impl.persistence.entity.GroupIdentityManager) BPSGroupIdentityManager(org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager) BPSGroupIdentityManager(org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Example 2 with BPSGroupIdentityManager

use of org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager in project carbon-business-process by wso2.

the class ProcessInstanceService method isValidUserToStartProcess.

private boolean isValidUserToStartProcess(ProcessInstanceCreateRequest processInstanceCreateRequest) {
    // check whether the users/groups exist
    String processDefinitionId = processInstanceCreateRequest.getProcessDefinitionId();
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    if (processDefinitionId == null) {
        final String processDefinitionKey = processInstanceCreateRequest.getProcessDefinitionKey();
        final String tenantId = processInstanceCreateRequest.getTenantId();
        ProcessEngine processEngine = BPMNOSGIService.getBPMNEngineService().getProcessEngine();
        if (processEngine != null) {
            if (processDefinitionKey != null) {
                if (((ProcessEngineImpl) processEngine).getProcessEngineConfiguration() != null) {
                    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
                    if (commandExecutor != null) {
                        processDefinitionId = (String) commandExecutor.execute(new Command<Object>() {

                            public Object execute(CommandContext commandContext) {
                                ProcessDefinitionEntityManager processDefinitionEntityManager = commandContext.getSession(ProcessDefinitionEntityManager.class);
                                ProcessDefinitionEntity processDefinitionEntity = processDefinitionEntityManager.findLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId);
                                if (processDefinitionEntity != null && processDefinitionEntity.getProcessDefinition() != null) {
                                    return processDefinitionEntity.getProcessDefinition().getId();
                                }
                                return null;
                            }
                        });
                    }
                }
                if (processDefinitionId == null) {
                    return false;
                }
            }
            String messageName = processInstanceCreateRequest.getMessage();
            if (messageName != null && !messageName.isEmpty()) {
                ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().messageEventSubscriptionName(messageName);
                if (processDefinitionQuery != null) {
                    processDefinitionQuery = processDefinitionQuery.processDefinitionTenantId(processInstanceCreateRequest.getTenantId());
                    if (processDefinitionQuery != null && processDefinitionQuery.count() > 1) {
                        processDefinitionQuery = processDefinitionQuery.latestVersion();
                    }
                }
                if (processDefinitionQuery != null) {
                    ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
                    if (processDefinition != null) {
                        processDefinitionId = processDefinition.getId();
                    }
                }
                if (processDefinitionId == null) {
                    return false;
                }
            }
        }
    }
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    String userName = carbonContext.getUsername();
    String tenantDomain = carbonContext.getTenantDomain();
    String userNameWithTenantDomain = userName + "@" + tenantDomain;
    BPSGroupIdentityManager bpsGroupIdentityManager = BPMNOSGIService.getGroupIdentityManager();
    List<Group> groupList = bpsGroupIdentityManager.findGroupsByUser(userName);
    List<IdentityLink> identityLinkList = repositoryService.getIdentityLinksForProcessDefinition(processDefinitionId);
    boolean valueExistsForUserId = false;
    boolean valueExistsForGroupId = false;
    for (IdentityLink identityLink : identityLinkList) {
        String userId = identityLink.getUserId();
        if (userId != null) {
            valueExistsForUserId = true;
            if (userId.contains("$")) {
                userId = resolveVariable(processInstanceCreateRequest, userId);
            }
            if (!userId.isEmpty() && (userId.equals(userName) || userId.equals(userNameWithTenantDomain))) {
                return true;
            }
            continue;
        }
        String groupId = identityLink.getGroupId();
        if (groupId != null) {
            valueExistsForGroupId = true;
            if (groupId.contains("$")) {
                groupId = resolveVariable(processInstanceCreateRequest, groupId);
            }
            for (Group identityGroup : groupList) {
                if (!groupId.isEmpty() && identityGroup.getId() != null && identityGroup.getId().equals(groupId)) {
                    return true;
                }
            }
        }
    }
    if (!valueExistsForGroupId && !valueExistsForUserId) {
        return true;
    }
    return false;
}
Also used : Group(org.activiti.engine.identity.Group) ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink) IdentityLink(org.activiti.engine.task.IdentityLink) BPSGroupIdentityManager(org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) RepositoryService(org.activiti.engine.RepositoryService) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 3 with BPSGroupIdentityManager

use of org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager in project carbon-business-process by wso2.

the class BPSGroupManagerFactory method openSession.

@Override
public Session openSession() {
    try {
        RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
        Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        UserStoreManager userStoreManager = registryService.getUserRealm(tenantId).getUserStoreManager();
        BPSGroupIdentityManager bpsGroupIdentityManager = new BPSGroupIdentityManager(userStoreManager);
        return bpsGroupIdentityManager;
    } catch (Exception e) {
        String msg = "Failed to obtain a group identity manager.";
        log.error(msg, e);
        return null;
    }
}
Also used : UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) RegistryService(org.wso2.carbon.registry.core.service.RegistryService)

Aggregations

BPSGroupIdentityManager (org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager)2 ProcessEngine (org.activiti.engine.ProcessEngine)1 RepositoryService (org.activiti.engine.RepositoryService)1 Group (org.activiti.engine.identity.Group)1 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)1 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)1 GroupIdentityManager (org.activiti.engine.impl.persistence.entity.GroupIdentityManager)1 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)1 ProcessDefinitionEntityManager (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)1 IdentityLink (org.activiti.engine.task.IdentityLink)1 BPSGroupManagerFactory (org.wso2.carbon.bpmn.core.integration.BPSGroupManagerFactory)1 BPMNOSGIServiceException (org.wso2.carbon.bpmn.rest.common.exception.BPMNOSGIServiceException)1 RestIdentityLink (org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)1 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)1