前言
最近使用acitiviti模型设计器整合到Spring boot原工程中时需要排除security安全验证,按照原来的教程和网站的解决方案都没有成功,启动项目后访问所有界面都被拦截到登录界面,security排除失败,所以在这里记录一下。
一、 环境
使用的Springboot版本为2.1.3 Release,activiti版本为5.22.0,JDK1.8。
没有排除security安全验证出现错误如下
Caused by: java.io.FileNotFoundException: class path
resource [org/springframework/security/config/annotation/authentication
/configurers/GlobalAuthenticationConfigurerAdapter.class]
cannot be opened because it does not exist
解决办法在Application启动类修改注解,排除 org.activiti.spring.boot.SecurityAutoConfiguration.class自动注解类
@SpringBootApplication(exclude ={
org.activiti.spring.boot.SecurityAutoConfiguration.class,
})
错误没有了,但是还是出现出现下面情况,还是显示登陆界面:
解决办法一:继续修改这个注解如下:
@SpringBootApplication(exclude ={
org.activiti.spring.boot.SecurityAutoConfiguration.class,
SecurityAutoConfiguration.class,
ManagementWebSecurityAutoConfiguration.class
})
security登录界面去除了,问题解决了。
解决办法二:去除所有拦截允许访问
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.anyRequest().permitAll()
.and().logout().permitAll();
}
}
感觉第一个方法更好点。
二、Security 的禁用问题
Spring Boot 2.x和Spring Security 5.x前禁用认证可以通过配置文件进行禁用security
在application.yml或application.properties中加入即可
security.basic.enabled=false
management.security.enabled=false
Spring Boot 2.x和Spring Security 5.x后spring boot禁用认证
以下方法被废弃
security.basic.authorize-mode
security.basic.enabled
security.basic.path
security.basic.realm
security.enable-csrf
security.headers.cache
security.headers.content-security-policy
security.headers.content-security-policy-mode
security.headers.content-type
security.headers.frame
security.headers.hsts
security.headers.xss
security.ignored
security.require-ssl
security.sessions
所以解决办法就是在启动类前的@SpringBootApplication
注解中加入exclude
属性SecurityAutoConfiguration
和ManagementWebSecurityAutoConfiguration
,以排除安全认证