2.5 安全配置
一、安全配置
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 配置真正的安全性
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf(scrf -> csrf.disable())
.httpBasic(Customizer.withDefaults())
.formLogin(form -> form.disable())
.authorizeRequests(req -> req.antMatchers("/api/**").authenticates());
}
// 指定请求不走过滤器链
@Override
protected void configure(WebSecurity web) throws Exception {
web.ignoring().mvcMatchers("/public/**");
}
}
如果不重写,则使用默认配置
默认配置中,通过and拼接多个配置
最后更新于