本文讲解,如何让springsecurity放行所有接口。
首先,我们需要创建一个自定义的安全配置类,用于配置 Spring Security 的行为。在该类中,我们可以覆盖默认的安全配置,并进行自定义的配置。
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/**").permitAll()
.anyRequest().authenticated()
.and().httpBasic();
}
}
在上面的代码中,我们使用 antMatchers("/**").permitAll()
方法来配置所有的接口都可以被放行,即不需要进行任何安全验证。