Chinaunix首页 | 论坛 | 博客
  • 博客访问: 601879
  • 博文数量: 298
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3077
  • 用 户 组: 普通用户
  • 注册时间: 2019-06-17 10:57
文章分类

全部博文(298)

文章存档

2022年(96)

2021年(201)

2019年(1)

我的朋友

分类: Java

2021-07-27 11:29:49

 1.pom

点击(此处)折叠或打开

  1. <parent>
  2.         <groupId>org.springframework.boot</groupId>
  3.         <artifactId>spring-boot-starter-parent</artifactId>
  4.         <version>2.5.2</version>
  5.         <relativePath /> <!-- lookup parent from repository -->
  6.     </parent>


  7.     <properties>
  8.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  9.         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  10.         <java.version>1.8</java.version>
  11.         <flowable.version>6.6.0</flowable.version>
  12.     </properties>

  13.          <!--flowable工作流依赖-->
  14.         <dependency>
  15.             <groupId>org.flowable</groupId>
  16.             <artifactId>flowable-spring-boot-starter</artifactId>
  17.             <version>${flowable.version}</version>
  18.         </dependency>
  19.          <!-- https://mvnrepository.com/artifact/org.flowable/flowable-json-converter -->
  20.         <dependency>
  21.          <groupId>org.flowable</groupId>
  22.          <artifactId>flowable-json-converter</artifactId>
  23.          <version>${flowable.version}</version>
  24.         </dependency>
  25.         <!-- app 依赖 包含 rest,logic,conf -->
  26.         <dependency>
  27.          <groupId>org.flowable</groupId>
  28.          <artifactId>flowable-ui-modeler-rest</artifactId>
  29.          <version>${flowable.version}</version>
  30.         </dependency>
  31.         <dependency>
  32.          <groupId>org.flowable</groupId>
  33.          <artifactId>flowable-ui-modeler-logic</artifactId>
  34.          <version>${flowable.version}</version>
  35.          <exclusions>
  36.          <exclusion>
  37.          <groupId>org.apache.logging.log4j</groupId>
  38.          <artifactId>log4j-slf4j-impl</artifactId>
  39.          </exclusion>
  40.          </exclusions>
  41.         </dependency>
  42.         <dependency>
  43.          <groupId>org.flowable</groupId>
  44.          <artifactId>flowable-ui-modeler-conf</artifactId>
  45.          <version>${flowable.version}</version>
  46.         </dependency>

2. FlowableConfig配置类

点击(此处)折叠或打开

  1. package org.fh.config;

  2. import org.flowable.spring.SpringProcessEngineConfiguration;
  3. import org.flowable.spring.boot.EngineConfigurationConfigurer;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.stereotype.Controller;

  6. /**
  7.  * 说明:Flowable配置
  8.  * 作者:FH Admin
  9.  * from:fhadmin.cn
  10.  */
  11. @Controller
  12. @Configuration
  13. public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {
  14.     
  15.     @Override
  16.     public void configure(SpringProcessEngineConfiguration engineConfiguration) {
  17.         engineConfiguration.setActivityFontName("宋体");
  18.         engineConfiguration.setLabelFontName("宋体");
  19.         engineConfiguration.setAnnotationFontName("宋体");
  20.     }
  21.     
  22. }
3.重写 SecurityUtils 重构流程编辑器获取用户信息

点击(此处)折叠或打开

  1. package org.flowable.ui.common.security;

  2. import org.fh.util.Jurisdiction;
  3. import org.flowable.common.engine.api.FlowableIllegalStateException;
  4. import org.flowable.idm.api.User;
  5. import org.flowable.ui.common.model.RemoteUser;
  6. import org.springframework.security.core.Authentication;
  7. import org.springframework.security.core.context.SecurityContext;
  8. import org.springframework.security.core.context.SecurityContextHolder;

  9. import java.util.ArrayList;
  10. import java.util.List;

  11. /**
  12.  * 说明:重构流程编辑器获取用户信息
  13.  * 作者:FH Admin
  14.  * from:fhadmin.cn
  15.  */
  16. public class SecurityUtils {

  17.     private static User assumeUser;
  18.     
  19.     private static SecurityScopeProvider securityScopeProvider = new FlowableSecurityScopeProvider();

  20.     private SecurityUtils() {
  21.     }

  22.     /**
  23.      * Get the login of the current user.
  24.      */
  25.     public static String getCurrentUserId() {
  26.         User user = getCurrentUserObject();
  27.         if (user != null) {
  28.             return user.getId();
  29.         }
  30.         return null;
  31.     }

  32.     /**
  33.      * @return the {@link User} object associated with the current logged in user.
  34.      */
  35.     public static User getCurrentUserObject() {
  36.         if (assumeUser != null) {
  37.             return assumeUser;
  38.         }

  39.         RemoteUser user = new RemoteUser();
  40.         user.setId(Jurisdiction.getUsername());
  41.         user.setDisplayName(Jurisdiction.getName());
  42.         user.setFirstName(Jurisdiction.getName());
  43.         user.setLastName(Jurisdiction.getName());
  44.         user.setEmail("admin@flowable.com");
  45.         user.setPassword("123456");
  46.         List<String> pris = new ArrayList<>();
  47.         pris.add(DefaultPrivileges.ACCESS_MODELER);
  48.         pris.add(DefaultPrivileges.ACCESS_IDM);
  49.         pris.add(DefaultPrivileges.ACCESS_ADMIN);
  50.         pris.add(DefaultPrivileges.ACCESS_TASK);
  51.         pris.add(DefaultPrivileges.ACCESS_REST_API);
  52.         user.setPrivileges(pris);
  53.         return user;
  54.     }
  55.     
  56.     public static void setSecurityScopeProvider(SecurityScopeProvider securityScopeProvider) {
  57.         SecurityUtils.securityScopeProvider = securityScopeProvider;
  58.     }

  59.     public static SecurityScope getCurrentSecurityScope() {
  60.         SecurityContext securityContext = SecurityContextHolder.getContext();
  61.         if (securityContext != null && securityContext.getAuthentication() != null) {
  62.             return getSecurityScope(securityContext.getAuthentication());
  63.         }
  64.         return null;
  65.     }

  66.     public static SecurityScope getSecurityScope(Authentication authentication) {
  67.         return securityScopeProvider.getSecurityScope(authentication);
  68.     }

  69.     public static SecurityScope getAuthenticatedSecurityScope() {
  70.         SecurityScope currentSecurityScope = getCurrentSecurityScope();
  71.         if (currentSecurityScope != null) {
  72.             return currentSecurityScope;
  73.         }
  74.         throw new FlowableIllegalStateException("User is not authenticated");
  75.     }

  76.     public static void assumeUser(User user) {
  77.         assumeUser = user;
  78.     }

  79.     public static void clearAssumeUser() {
  80.         assumeUser = null;
  81.     }
  82. }


阅读(1293) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~