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


排除Activiti Spring Boot Security Auto Config

@EnableAutoConfiguration(exclude = {org.activiti.spring.boot.SecurityAutoConfiguration.class})

创建一个类以扩展弹簧类“ 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。对于UseCase,我必须以这种方式排除HTTP-Options请求。只需在org.activiti.rest.conf.SecurityConfiguration.java中编辑activiti-webapp-rest2,如下所示:

@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文件,然后,应禁用基本身份验证。

07-24 09:37
查看更多