SpringSecurity之HttpBasic登录验证

本文介绍了SpringSecurity中HttpBasic登录验证的需求分析、环境搭建步骤,详细讲解了如何添加HttpBasic认证,包括默认行为的探讨,如登录、资源放行和退出功能。
摘要由CSDN通过智能技术生成

目录

 

一、需求分析

二、环境搭建

三、添加HttpBasic登录认证

四、HttpBasic登录认证的默认行为


一、需求分析

1.1、客户端发送请求,请求会被SpringSecurity的过滤器链拦截,判断请求是否经过了认证和授权 ? 

1.2、如果请求没有被认证,则跳转到登录页面,进行登录后放行之前的请求

1.3、如果请求已经被认证,则请求服务器中的资源都会放行

1.4、完成退出功能。退出后跳转到登录页面

二、环境搭建

2.1、创建 SpringBoot 项目,引入 web 、test 和 thymeleaf 依赖

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.16.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>	

	    <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

2.2 创建如下文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值