01 - spring security自定义登录页面

spring security自定义登录页面

文档

  1. 00 - spring security框架使用

使用浏览器自带的登录页面

添加一个配置类WebSecurityConfig.java,后续内容也会在此类中进行配置

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 {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

        // 开启授权保护
        http.authorizeRequests(expressionInterceptUrlRegistry -> expressionInterceptUrlRegistry
                // 对所有请求开启授权保护
                .anyRequest()
                // 已经认证的请求会被自动授权
                .authenticated());

        // 使用基本授权方式(浏览器自带的登录页面,无默认登出页)
        http.httpBasic(Customizer.withDefaults());

        return http.build();
    }
}
  • 此方式由浏览器弹出默认登录页面进行登录认证
  • @EnableWebSecurity此处不用开启,依赖时已经自动开启
相关推荐
夕除4 分钟前
js--7
java
布谷歌9 分钟前
面试题整理
java·开发语言
爬山算法16 分钟前
Hibernate(74)如何在CQRS架构中使用Hibernate?
java·架构·hibernate
jjjava2.025 分钟前
深入解析Set与Map的奥秘
java·开发语言
白宇横流学长30 分钟前
基于Java的火车票订票系统的设计与开发
java·开发语言
黎雁·泠崖31 分钟前
Java核心基础API学习总结:从Object到包装类的核心知识体系
java·开发语言·学习
Yvonne爱编码33 分钟前
JAVA数据结构 DAY1-集合和时空复杂度
java·数据结构·python
win x1 小时前
JavaSE(基础)高频面试点及 知识点
java·面试·职场和发展
Terio_my1 小时前
简要 Java 面试题学习
java·开发语言·学习
好好研究1 小时前
Spring Boot - Thymeleaf模板引擎
java·spring boot·后端·thymeleaf