springBoot 整合flowable-modeler

springBoot 整合flowable-modeler

  • 摘要
    • 背景
    • 步骤
      • 引入配置文件
      • 重写配置类
        • org.flowable.ui.common.rest.idm.remote.RemoteAccountResource
        • org.flowable.ui.common.security.SecurityUtils
        • org.flowable.ui.modeler.conf.SecurityConfiguration
    • 参考链接

摘要

flowable 和activiti6 一脉相承,如同JBPM分出activiti一样,自成一派。目前修复了activiti 6 大部分bug,从activiti 切换到flowable 不难。本文主要基于flowable-ui-modeler(6.4。1)来介绍如何集成flowable-modeler 使用自己的用户体系进行认证授权。

背景

flowable和activiti大致上没什么差别,但在集成工具时发现flowable的绑定有点蛋疼,模型生成器和rest-api嵌入了spring security来连接授权项目IDM。因此,开始搜集资料进行解耦,并对网上资料进行补充。

步骤

下载flowable-modeler 源码,查看并重写授权代码

引入配置文件

 
            org.flowable
            flowable-ui-modeler-app
            6.4.1
 

重写配置类

org.flowable.ui.common.rest.idm.remote.RemoteAccountResource

将以下方法进行修改

@RequestMapping(value = "/rest/account", method = RequestMethod.GET, produces = "application/json")
    public UserRepresentation getAccount() {
        UserRepresentation userRepresentation = new UserRepresentation();
        userRepresentation.setFirstName("admin");
        userRepresentation.setLastName("admin");
        userRepresentation.setFullName("admin");
        userRepresentation.setId("admin");
        
        List 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);
        userRepresentation.setPrivileges(pris);

        if (userRepresentation != null) {
            return userRepresentation;
        } else {
            throw new NotFoundException();
        }
    }

org.flowable.ui.common.security.SecurityUtils

public static User getCurrentUserObject() {
        if (assumeUser != null) {
            return assumeUser;
        }

        RemoteUser user = new RemoteUser();
        user.setId("admin");
        user.setDisplayName("admin");
        user.setFirstName("admin");
        user.setLastName("admin");
        user.setEmail("[email protected]");
        user.setPassword("test");
        List 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;
    }

org.flowable.ui.modeler.conf.SecurityConfiguration

注释bean定义: FlowableCookieFilterRegistrationBean

@Configuration
    @Order(10)
    public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {


        @Autowired
        protected AjaxLogoutSuccessHandler ajaxLogoutSuccessHandler;

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .sessionManagement()
                    .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                    .and()
                    .logout()
                    .logoutUrl("/app/logout")
                    .logoutSuccessHandler(ajaxLogoutSuccessHandler)
                    .addLogoutHandler(new ClearFlowableCookieLogoutHandler())
                    .and()
                    .csrf()
                    .disable() // Disabled, cause enabling it will cause sessions
                    .headers()
                    .frameOptions()
                    .sameOrigin()
                    .addHeaderWriter(new XXssProtectionHeaderWriter())
                    .and()
                    .authorizeRequests()
                    .antMatchers(REST_ENDPOINTS_PREFIX + "/**").permitAll();
        }
    }
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {

        protected final FlowableRestAppProperties restAppProperties;
        protected final FlowableModelerAppProperties modelerAppProperties;

        public ApiWebSecurityConfigurationAdapter(FlowableRestAppProperties restAppProperties,
                                                  FlowableModelerAppProperties modelerAppProperties) {
            this.restAppProperties = restAppProperties;
            this.modelerAppProperties = modelerAppProperties;
        }

        protected void configure(HttpSecurity http) throws Exception {

            http
                    .sessionManagement()
                    .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                    .and()
                    .csrf()
                    .disable();

            http.antMatcher("/api/**").authorizeRequests().antMatchers("/api/**").permitAll();
        }
    }

至此,modeler 破解完成,此时访问模型首页显示正常。

源码

参考链接

书山登峰人 https://blog.csdn.net/houyj1986/article/details/86027301

你可能感兴趣的:(springBoot 整合flowable-modeler)