flowable 6.6.0 更新变动,相对于6.5.0版本,导致流程设计器免登录验证失败
前沿:
flowable和activiti是同一个团队开发的,activiti先,flowable后 。所以,flowable 算是 activiti的升级版。
flowable 确实要比activiti功能更完善。未来肯定flowable 是主流趋势,当下也已经是主流了。
目前最新版本的 flowable 6.6.0 版本,相对于6.5.0版本配置的免登录方案,对6.6.0版本就无效了
通过查看对比flowable源码,发现内置的 Security 权限代码有不少改动,这个是导致免登陆失败的根源
需要重新重构flowable源码的两个函数,如下
1. 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:www.fhadmin.org
*/
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;
}
}