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

全部博文(298)

文章存档

2022年(96)

2021年(201)

2019年(1)

我的朋友

分类: Java

2021-06-12 11:44:35

  

前沿:

flowable和activiti是同一个团队开发的,activiti先,flowable后 。所以,flowable 算是 activiti的升级版。
flowable 确实要比activiti功能更完善。未来肯定flowable 是主流趋势,当下也已经是主流了。

目前最新版本的 flowable 6.6.0 版本,相对于6.5.0版本配置的免登录方案,对6.6.0版本就无效了

通过查看对比flowable源码,发现内置的 Security 权限代码有不少改动,这个是导致免登陆失败的根源

需要重新重构flowable源码的两个函数,如下

1. 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:www fhadmin org
  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. }


2.FlowableUiSecurityAutoConfiguration

点击(此处)折叠或打开

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

  2. import org.flowable.spring.boot.FlowableSecurityAutoConfiguration;
  3. import org.flowable.spring.boot.idm.IdmEngineServicesAutoConfiguration;
  4. import org.springframework.boot.autoconfigure.AutoConfigureAfter;
  5. import org.springframework.boot.autoconfigure.AutoConfigureBefore;
  6. import org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration;
  7. import org.springframework.context.annotation.Configuration;

  8. /**
  9.  * 说明:重构FlowableUiSecurity自动配置
  10.  * 作者:FH Admin
  11.  * from:www fhadmin org
  12.  */
  13. @Configuration(proxyBeanMethods = false)
  14. @AutoConfigureAfter({
  15.         IdmEngineServicesAutoConfiguration.class,
  16. })
  17. @AutoConfigureBefore({
  18.         FlowableSecurityAutoConfiguration.class,
  19.         OAuth2ClientAutoConfiguration.class,
  20. })
  21. public class FlowableUiSecurityAutoConfiguration {}


package org.flowable.ui.common.security;

import org.flowable.spring.boot.FlowableSecurityAutoConfiguration;
import org.flowable.spring.boot.idm.IdmEngineServicesAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration;
import org.springframework.context.annotation.Configuration;

/**
 * 说明:重构FlowableUiSecurity自动配置
 * 作者:FH Admin
 * from:
 */
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter({
        IdmEngineServicesAutoConfiguration.class,
})
@AutoConfigureBefore({
        FlowableSecurityAutoConfiguration.class,
        OAuth2ClientAutoConfiguration.class,
})
public class FlowableUiSecurityAutoConfiguration {} 
阅读(1265) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~