flowable 整合 springboot

简介: flowable 整合 springboot

1.pom

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.2</version>
    <relativePath /> <!-- lookup parent from repository -->
  </parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <flowable.version>6.6.0</flowable.version>
  </properties>
    <!--flowable工作流依赖-->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>${flowable.version}</version>
        </dependency>
    <!-- https://mvnrepository.com/artifact/org.flowable/flowable-json-converter -->
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-json-converter</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <!-- app 依赖 包含 rest,logic,conf -->
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-ui-modeler-rest</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-ui-modeler-logic</artifactId>
        <version>${flowable.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-slf4j-impl</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-ui-modeler-conf</artifactId>
        <version>${flowable.version}</version>
    </dependency>

2. FlowableConfig配置类

package org.fh.config;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
/**
 * 说明:Flowable配置
 * 作者:FH Admin
 * from:fhadmin.cn
 */
@Controller
@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {
    @Override
    public void configure(SpringProcessEngineConfiguration engineConfiguration) {
        engineConfiguration.setActivityFontName("宋体");
        engineConfiguration.setLabelFontName("宋体");
        engineConfiguration.setAnnotationFontName("宋体");
    }
}

3.重写 SecurityUtils 重构流程编辑器获取用户信息

package org.flowable.ui.common.security;
import org.fh.util.Jurisdiction;
import org.flowable.common.engine.api.FlowableIllegalStateException;
import org.flowable.idm.api.User;
import org.flowable.ui.common.model.RemoteUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.ArrayList;
import java.util.List;
/**
 * 说明:重构流程编辑器获取用户信息
 * 作者:FH Admin
 * from:fhadmin.cn
 */
public class SecurityUtils {
  private static User assumeUser;
  private static SecurityScopeProvider securityScopeProvider = new FlowableSecurityScopeProvider();
  private SecurityUtils() {
  }
  /**
   * Get the login of the current user.
   */
  public static String getCurrentUserId() {
    User user = getCurrentUserObject();
    if (user != null) {
      return user.getId();
    }
    return null;
  }
  /**
   * @return the {@link User} object associated with the current logged in user.
   */
  public static User getCurrentUserObject() {
    if (assumeUser != null) {
      return assumeUser;
    }
    RemoteUser user = new RemoteUser();
    user.setId(Jurisdiction.getUsername());
    user.setDisplayName(Jurisdiction.getName());
    user.setFirstName(Jurisdiction.getName());
    user.setLastName(Jurisdiction.getName());
    user.setEmail("admin@flowable.com");
    user.setPassword("123456");
    List<String> pris = new ArrayList<>();
    pris.add(DefaultPrivileges.ACCESS_MODELER);
    pris.add(DefaultPrivileges.ACCESS_IDM);
    pris.add(DefaultPrivileges.ACCESS_ADMIN);
    pris.add(DefaultPrivileges.ACCESS_TASK);
    pris.add(DefaultPrivileges.ACCESS_REST_API);
    user.setPrivileges(pris);
    return user;
  }
    public static void setSecurityScopeProvider(SecurityScopeProvider securityScopeProvider) {
        SecurityUtils.securityScopeProvider = securityScopeProvider;
    }
    public static SecurityScope getCurrentSecurityScope() {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        if (securityContext != null && securityContext.getAuthentication() != null) {
            return getSecurityScope(securityContext.getAuthentication());
        }
        return null;
    }
    public static SecurityScope getSecurityScope(Authentication authentication) {
        return securityScopeProvider.getSecurityScope(authentication);
    }
    public static SecurityScope getAuthenticatedSecurityScope() {
        SecurityScope currentSecurityScope = getCurrentSecurityScope();
        if (currentSecurityScope != null) {
            return currentSecurityScope;
        }
        throw new FlowableIllegalStateException("User is not authenticated");
    }
  public static void assumeUser(User user) {
    assumeUser = user;
  }
  public static void clearAssumeUser() {
    assumeUser = null;
  }
}

 

目录
相关文章
|
数据可视化 前端开发 Java
SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(图解)(一)
SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(图解)
1002 0
|
4月前
|
数据可视化 Java 数据库
手把手实现springboot整合flowable,非常简单【附源码.视频】
手把手实现springboot整合flowable,非常简单【附源码.视频】
243 2
|
5月前
|
开发框架 Java API
Spring Boot与Flowable的完美整合
【4月更文挑战第20天】
1816 2
|
5月前
|
监控 Java API
|
数据可视化 安全 前端开发
SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(图解)(三)
SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(图解)
364 0
|
XML 数据可视化 Java
SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(图解)(二)
SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(图解)
448 0
|
存储 消息中间件 JavaScript
Spring Boot + flowable 快速实现工作流
Spring Boot + flowable 快速实现工作流
Spring Boot + flowable 快速实现工作流
|
SQL Java 关系型数据库
手把手教大家在 Spring Boot 中处理 flowable 中的用户和组
手把手教大家在 Spring Boot 中处理 flowable 中的用户和组
|
XML 前端开发 JavaScript
SpringBoot+Vue+Flowable,模拟一个请假审批流程
SpringBoot+Vue+Flowable,模拟一个请假审批流程
|
存储 XML 监控
Springboot整合Flowable流程引擎
Springboot整合Flowable流程引擎