spring-boot - 如何禁用 activiti REST HTTP

标签 spring-boot basic-authentication activiti

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

  1. 排除 activiti spring boot 安全自动配置

    @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 基本身份验证吗?

最佳答案

您可以使用 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。重新部署 war 文件,之后应该禁用基本身份验证。

关于spring-boot - 如何禁用 activiti REST HTTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32171554/

相关文章:

unit-testing - 使用 Thymeleaf 模板引擎对服务进行单元测试时出现问题

php - 从 Symfony2 中的 http_basic auth 注销

laravel-4 - 无法在 Laravel 中对用户进行身份验证

java - Selenium - 通过 url 进行基本身份验证

grails - 如何在activiti中获取枚举值以及activiti中FormProperty的getType()的返回类型是什么?

android - 使用 spring security oauth 将社交登录添加到 native 应用程序

java - JPA:如何避免简单地加载对象以便将其 ID 存储在数据库中?

activiti - 是否建议在 camunda 中为 BPMN 开发自定义 UI

java - 将重命名的文件作为输入传递到出站适配器/网关

jbpm - BPM 中的中间事件或计时器