网站优化简历模板软文发布的平台与板块
spring security自定义登录页面
文档
- 00 - spring security框架使用
使用浏览器自带的登录页面
添加一个配置类WebSecurityConfig.java
,后续内容也会在此类中进行配置
package xin.yangshuai.springsecurity03.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;@Configuration
// @EnableWebSecurity
public class WebSecurityConfig {@Beanpublic SecurityFilterChain filterChain(HttpSecurity http) throws Exception {// 开启授权保护http.authorizeRequests(expressionInterceptUrlRegistry -> expressionInterceptUrlRegistry// 对所有请求开启授权保护.anyRequest()// 已经认证的请求会被自动授权.authenticated());// 使用基本授权方式(浏览器自带的登录页面,无默认登出页)http.httpBasic(Customizer.withDefaults());return http.build();}
}
- 此方式由浏览器弹出默认登录页面进行登录认证
@EnableWebSecurity
此处不用开启,依赖时已经自动开启