【问题标题】:How to disable activiti REST HTTP如何禁用activiti REST HTTP
【发布时间】:2015-08-23 21:08:01
【问题描述】:

我们使用的是 activiti v5.18 和 spring boot。要调用 activiti REST API,我们必须创建一个 activiti 用户以通过基本身份验证。据我所知,activiti security是基于spring boot security的,我们尝试了两种方法。

  1. 排除activiti spring boot security auto config

    @EnableAutoConfiguration(exclude = {org.activiti.spring.boot.SecurityAutoConfiguration.class})
    
  2. 创建一个类来扩展spring类'WebSecurityConfigurerAdapter),并在application.properties中设置'security.basic.enabled=false'

    @Configuration
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
    
    // @formatter:off
    http
    .authorizeRequests()
    .antMatchers(HttpMethod.GET, "/","/static/**", "/resources/**","/resources/public/**").permitAll()
    .anyRequest().authenticated()
    .and()
    .formLogin()
    .and()
    .httpBasic().disable()
    .requiresChannel().anyRequest().requiresSecure();
    // @formatter:on
    }
    }
    

不幸的是,他们都没有禁用基本身份验证,当我转到页面'http://localhost:8080/repository/deployments'时,浏览器会弹出用户登录窗口。并在页面上显示错误信息

此应用程序没有显式映射 /error,因此您将其视为后备。

出现意外错误(类型=未授权,状态=401)。 访问此资源需要完全身份验证

另外,我们有自己的REST服务,当客户端调用我们的REST服务时,浏览器也会要求输入activiti REST用户/密码。

有什么方法可以禁用activiti REST HTTP 基本认证?

【问题讨论】:

    标签: spring-boot basic-authentication activiti


    【解决方案1】:

    您可以使用 antMatchers 为某些类型的请求禁用身份验证,例如 HTTP-GET 或 / 和 HTTP-POST 请求,如下所示:

    .antMatchers(HttpMethod.GET, "/**").permitAll()
    

    使用他的命令,所有 HTTP-GET 方法都不会命中 BasicAuthenticationFilter。对于我的用例,我必须以这种方式排除 HTTP 选项请求。只需编辑activiti-webapp-rest2 中的org.activiti.rest.conf.SecurityConfiguration.java 如下:

    @Override
      protected void configure(HttpSecurity http) throws Exception {
         http
         .authenticationProvider(authenticationProvider())
         .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
         .csrf().disable()
         .authorizeRequests()
         .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
         .antMatchers(HttpMethod.GET, "/**").permitAll()
         .antMatchers(HttpMethod.POST, "/**").permitAll()
         .antMatchers(HttpMethod.PUT, "/**").permitAll()
         .antMatchers(HttpMethod.DELETE, "/**").permitAll()
           .anyRequest().authenticated()
           .and()
         .httpBasic();
      }
    

    之后,您必须重建 Activiti-Project。重新部署战争文件,然后,基本身份验证应该被禁用。

    【讨论】:

    • 你好,我想用waffle和自定义身份验证impl,而不是activiti中的基本身份验证,所以我需要做你写的,然后我在哪里进行自己的身份验证并回复一个 TRUE 的验证功能?我应该把断点放在代码的哪里?
    • 对于自定义身份验证,实现自定义身份验证过滤器 public class CustomAuthenticationFilter extends AbstractAuthenticationProcessingFilter。在此过滤器中,您进行身份验证。在 Spring Java 配置中,将您的过滤器声明为 bean: \@Bean public CustomAuthenticationFilter customTokenAuthenticationFilter(){ return new CustomAuthenticationFilter ("/**");}; \@Autowired CustomAuthenticationFilter customTokenAuthenticationFilter;并使用 .addFilterBefore(customTokenAuthenticationFilter, BasicAuthenticationFilter.class).httpBasic();将您的过滤器添加到链中。
    • 嗨,spring conf 文件在哪里?什么时候托管在 activiti rest 中?
    • activiti-webapp-rest2下 --> org.activiti.rest.conf.SecurityConfiguration.java
    • @Ben 我有同样的问题,但没有解决。请帮我。谢谢。
    【解决方案2】:

    这对于 OP 来说可能会迟到,但这项工作可能仍然会帮助其他人。

    @EnableAutoConfiguration(exclude = {
    org.activiti.spring.boot.RestApiAutoConfiguration.class,
    org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class,
    org.activiti.spring.boot.SecurityAutoConfiguration.class,
    org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration.class
    })  
    
    【解决方案3】:

    你可以使用这个类来配置@Benidea:

    @Configuration
    @EnableWebSecurity
    @EnableWebMvcSecurity
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public class CustomSecurityConfiguration extends WebSecurityConfigurerAdapter {
    
        @Bean
        @ConditionalOnMissingBean
        public AuthenticationProvider authenticationProvider() {
            return new BasicAuthenticationProvider();
        }
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .authenticationProvider(authenticationProvider())
                    .csrf().disable()
                    .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                    .authorizeRequests()
                    .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
                    .antMatchers(HttpMethod.GET, "/**").permitAll()
                    .antMatchers(HttpMethod.POST, "/**").permitAll()
                    .antMatchers(HttpMethod.PUT, "/**").permitAll()
                    .antMatchers(HttpMethod.DELETE, "/**").permitAll()
                    .anyRequest().authenticated()
                    .and()
                    .httpBasic();
        }
    }
    

    【讨论】:

      【解决方案4】:

      最近我也遇到了这个问题。我尝试了几个建议并花了很多时间,但我无法成功。但是有很容易的出路。如果在将 Activiti-rest 与自己的应用程序集成时不需要使用它,那么只需获取依赖项

      <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring-boot-starter-rest-api</artifactId>
      <version>${activiti.version}</version>
      </dependency>
      

      出来。 希望它会帮助某人。我找不到任何文档提到这一点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-18
        • 1970-01-01
        • 1970-01-01
        • 2021-06-02
        相关资源
        最近更新 更多