我们使用的是 activiti v5.18 和 spring boot。要调用 activiti REST API,我们必须创建一个 activiti 用户来通过基本身份验证。据我所知,activiti安全性是基于spring boot安全性的,我们尝试了两种方法。
排除 activiti spring boot 安全自动配置
@EnableAutoConfiguration(exclude = {org.activiti.spring.boot.SecurityAutoConfiguration.class})
创建一个类来扩展 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/