Spring Security介绍

  一、Spring Security:

1、简介:Spring Security 是一个非常流行和成功的 Java 应用开发框架。Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性的完整解决方案。一般来说,Web 应用的安全性包括用户认证(Authentication)和用户授权(Authorization)两个部分。

(1)用户认证:指的是验证某个用户是否为系统中的合法主体,也就是说用户能否访问该系统。用户认证一般要求用户提供用户名和密码。系统通过校验用户名和密码来完成认证过程。

Spring Security 框架支持主流的认证方式,包括 HTTP 基本认证、HTTP 表单验证、HTTP 摘要认证、OpenID 和 LDAP 等。

(2)用户授权:指的是验证某个用户是否有权限执行某个操作。在一个系统中,不同用户所具有的权限是不同的。比如对一个文件来说,有的用户只能进行读取,而有的用户可以进行修改。一般来说,系统会为不同的用户分配不同的角色,而每个角色则对应一系列的权限。

Spring Security 提供了基于角色的访问控制和访问控制列表(Access Control List,ACL),可以对应用中的领域对象进行细粒度的控制。

2、结构:通过继承

org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter

实现权限配置,登录验证成功后初始化org.springframework.security.core.userdetails.UserDetails,存储当前登录用户。默认(可缺省)登录接口:/login

二、 spring security 依赖:

1、pom依赖:

	<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.14.RELEASE</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-web</artifactId></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-config</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>

2、springBoot 和 spring security 版本对应关系:

springboot 版本     spring security版本
2.3.12.RELEASE    5.3.9.RELEASE
2.3.11.RELEASE    5.3.9.RELEASE
2.3.10.RELEASE    5.3.9.RELEASE
2.3.9.RELEASE    5.3.8.RELEASE
2.3.8.RELEASE    5.3.6.RELEASE
2.3.7.RELEASE    5.3.6.RELEASE
2.3.6.RELEASE    5.3.5.RELEASE
2.3.5.RELEASE    5.3.5.RELEASE
2.3.4.RELEASE    5.3.4.RELEASE
2.3.3.RELEASE    5.3.4.RELEASE
2.3.2.RELEASE    5.3.3.RELEASE
2.3.1.RELEASE    5.3.3.RELEASE
2.3.0.RELEASE    5.3.2.RELEASE
2.2.13.RELEASE    5.2.8.RELEASE
2.2.12.RELEASE    5.2.8.RELEASE
2.2.11.RELEASE    5.2.7.RELEASE
2.2.10.RELEASE    5.2.6.RELEASE
2.2.9.RELEASE    5.2.5.RELEASE
2.2.8.RELEASE    5.2.5.RELEASE
2.2.7.RELEASE    5.2.4.RELEASE
2.2.6.RELEASE    5.2.2.RELEASE
2.2.5.RELEASE    5.2.2.RELEASE
2.2.4.RELEASE    5.2.1.RELEASE
2.2.3.RELEASE    5.2.1.RELEASE
2.2.2.RELEASE    5.2.1.RELEASE
2.2.1.RELEASE    5.2.1.RELEASE
2.2.0.RELEASE    5.2.0.RELEASE
2.1.18.RELEASE    5.1.13.RELEASE
2.1.17.RELEASE    5.1.12.RELEASE
2.1.16.RELEASE    5.1.11.RELEASE
2.1.15.RELEASE    5.1.11.RELEASE
2.1.14.RELEASE    5.1.10.RELEASE
2.1.13.RELEASE    5.1.8.RELEASE
2.1.12.RELEASE    5.1.7.RELEASE
2.1.11.RELEASE    5.1.7.RELEASE
2.1.10.RELEASE    5.1.7.RELEASE
2.1.9.RELEASE    5.1.6.RELEASE
2.1.8.RELEASE    5.1.6.RELEASE
2.1.7.RELEASE    5.1.6.RELEASE
2.1.6.RELEASE    5.1.5.RELEASE
2.1.5.RELEASE    5.1.5.RELEASE
2.1.4.RELEASE    5.1.5.RELEASE
2.1.3.RELEASE    5.1.4.RELEASE
2.1.2.RELEASE    5.1.3.RELEASE
2.1.1.RELEASE    5.1.2.RELEASE
2.1.0.RELEASE    5.1.1.RELEASE
2.0.9.RELEASE    5.0.12.RELEASE
2.0.8.RELEASE    5.0.11.RELEASE
2.0.7.RELEASE    5.0.10.RELEASE
2.0.6.RELEASE    5.0.9.RELEASE
2.0.5.RELEASE    5.0.8.RELEASE
2.0.4.RELEASE    5.0.7.RELEASE
2.0.3.RELEASE    5.0.6.RELEASE
2.0.2.RELEASE    5.0.5.RELEASE
2.0.1.RELEASE    5.0.4.RELEASE
2.0.0.RELEASE    5.0.3.RELEASE
1.5.22.RELEASE    4.2.13.RELEASE
1.5.21.RELEASE    4.2.12.RELEASE
1.5.20.RELEASE    4.2.12.RELEASE
1.5.19.RELEASE    4.2.11.RELEASE
1.5.18.RELEASE    4.2.10.RELEASE
1.5.17.RELEASE    4.2.9.RELEASE
1.5.16.RELEASE    4.2.8.RELEASE
1.5.15.RELEASE    4.2.7.RELEASE
1.5.14.RELEASE    4.2.7.RELEASE
1.5.13.RELEASE    4.2.6.RELEASE
1.5.12.RELEASE    4.2.5.RELEASE
1.5.11.RELEASE    4.2.5.RELEASE
1.5.10.RELEASE    4.2.4.RELEASE
1.5.9.RELEASE    4.2.3.RELEASE
1.5.8.RELEASE    4.2.3.RELEASE
1.5.7.RELEASE    4.2.3.RELEASE
1.5.6.RELEASE    4.2.3.RELEASE
1.5.5.RELEASE    4.2.3.RELEASE
1.5.4.RELEASE    4.2.3.RELEASE
1.5.3.RELEASE    4.2.2.RELEASE
1.5.2.RELEASE    4.2.2.RELEASE
1.5.1.RELEASE    4.2.1.RELEASE
1.5.0.RELEASE    4.2.1.RELEASE
1.4.7.RELEASE    4.1.4.RELEASE
1.4.6.RELEASE    4.1.4.RELEASE
1.4.5.RELEASE    4.1.4.RELEASE
1.4.4.RELEASE    4.1.4.RELEASE
1.4.3.RELEASE    4.1.4.RELEASE
1.4.2.RELEASE    4.1.3.RELEASE
1.4.1.RELEASE    4.1.3.RELEASE
1.4.0.RELEASE    4.1.1.RELEASE
1.3.8.RELEASE    4.0.4.RELEASE
1.3.7.RELEASE    4.0.4.RELEASE

 三、核心组件:

1、Authentication 认证:Authentication接口就是用来携带认证信息的。认证信息包括用户身份信息,密码,及权限列表等;

2、UsernamePasswordAuthenticationFilter:账号密码认证过滤器,用于认证用户信息,认证方式是由 AuthenticationManager 接口提供。

3、AuthenticationManager:认证管理器,是认证相关的核心接口,也是发起认证的出发点。实际业务中可能根据不同的信息进行认证,所以Spring推荐通过实现 AuthenticationManager 接口来自定义自己的认证方式。Spring 提供了一个默认的实现 ProviderManager。

4、ProviderManager:认证提供者管理器,该类中维护了一个认证提供者列表,只要这个列表中的任何一个认证提供者提供的认证方式认证通过,认证就结束。

5、AuthenticationProvider:认证提供者,这是一个接口,具体如何认证,就看如何实现该接口。Spring Security 提供了 DaoAuthenticationProvider 实现该接口,这个类就是使用数据库中数据进行认证。

6、UserDetailsService:根据用户名获取用户详细信息

7、UserDetails:用户的详细信息,主要用于登录认证。

8、SecurityContextHolder:是最基本的对象,它负责存储当前 SecurityContext 信息。SecurityContextHolder默认使用 ThreadLocal 来存储认证信息,意味着这是一种与线程绑定的策略。在Web场景下的使用Spring Security,在用户登录时自动绑定认证信息到当前线程,在用户退出时,自动清除当前线程的认证信息。

9、SecurityContext:负责存储认证通过的用户信息(Authentication对象),保存着当前用户是什么,是否已经通过认证,拥有哪些权限等等。

10、AuthenticationSuccessHandler:主要用于认证成功后的处理,比如返回页面或者数据。

11、AuthenticationFailureHandler:主要用于认证失败后的处理,比如返回页面或者数据。

12、AccessDecisionManager:主要用于实现权限,决定请求是否具有访问的权限。

13、AccessDeniedHandler:主要用于无权访问时的处理
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/340357.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于SpringBoot的教学管理系统

文章目录 项目介绍主要功能截图&#xff1a;部分代码展示设计总结项目获取方式 &#x1f345; 作者主页&#xff1a;超级无敌暴龙战士塔塔开 &#x1f345; 简介&#xff1a;Java领域优质创作者&#x1f3c6;、 简历模板、学习资料、面试题库【关注我&#xff0c;都给你】 &…

热点报告 | “尔滨”火出东北,本期热点带你盘活冬季营销

您是否曾有以下困惑&#xff1f;打开小红书首页推荐&#xff0c;似乎已经被算法教育成了成熟的信息茧房&#xff0c;想要找到下一个热点&#xff0c;又忧虑一叶以障目&#xff1b;看着搜索框热词&#xff0c;又担心无法掌握热词背后的话题命脉&#xff0c;难以在浮光掠影中寻找…

基于OpenMV与STM32的数据通信项目(代码开源)

前言&#xff1a;本文为手把手教学 OpenMV 与 STM32 的数据通信项目教程&#xff0c;本教程使用 STM32F103C8T6 与 OpenMV 进行操作。 OpenMV 是非常强大的计算机视觉实现工具&#xff0c;自身提供了非常多的视觉项目案例&#xff0c;编程与使用门槛极低。为了进一步增强作品的…

模型的可解释性

一、PI&#xff1a;Permutaion Importance — 排列重要性 作用&#xff1a;衡量特征重要性方法 原理&#xff1a; 代码示例&#xff1a;基于模型用球队的统计数据预测一个足球队会不会出现“全场最佳球员” import numpy as np import pandas as pd from sklearn.model_sele…

Scrapy框架自学

配置国内镜像源 # pip设置配置 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple pip config set trusted-host pypi.tuna.tsinghua.edu.cn创建虚拟环境 # 使用conda创建虚拟环境&#xff08;具体内容请参考课件&#xff09; conda create -n py_s…

Deep Reinforment Learning Note 1

文章目录 Terminology Terminology st : stateot : observationat : action π θ ( a t ∣ o t ) \pi_\theta (a_t | o_t) πθ​(at​∣ot​) : policy π θ ( a t ∣ s t ) \pi_\theta (a_t | s_t) πθ​(at​∣st​) : policy (fully observed) Observation result from…

基础篇_快速入门(Java简介,安装JDK,cmd命令行运行Java文件产生乱码问题的解决方式,IDE工具,实用工具)

文章目录 一. Java 简介1. JVM2. JRE3. JDK 二. 安装 JDK1. 下载和安装2. 配置 Path3. 配置 JAVA_HOME&#xff08;选讲&#xff09;优化 三. 入门案例1. 第一行代码1) jshell2) 代码解读总结 3) 为何要分成对象与方法 2. 第一份源码1) 源码结构2) 编写 java 源代码3) 编译 jav…

JWT---JSON Web Token

JSON Web Token是什么 JSON Web Token (JWT)是一个开放标准(RFC 7519)&#xff0c;它定义了一种紧凑的、自包含的方式&#xff0c;用于作为JSON对象在各方之间安全地传输信息。该信息可以被验证和信任&#xff0c;因为它是数字签名的。 JSON Web Token的结构是什么样的 JSON…

Java的Netty

1.基本概念介绍 有了Netty&#xff0c;你可以实现自己的HTTP服务器&#xff0c;FTP服务器&#xff0c;UDP服务器&#xff0c;RPC服务器&#xff0c;WebSocket服务器&#xff0c;Redis的Proxy服务器&#xff0c;MySQL的Proxy服务器等等。 Netty 是一个基于 Java 的高性能网络应…

Win系统搭建Elasticsearch实现公网远程访问本地服务

文章目录 系统环境1. Windows 安装Elasticsearch2. 本地访问Elasticsearch3. Windows 安装 Cpolar4. 创建Elasticsearch公网访问地址5. 远程访问Elasticsearch6. 设置固定二级子域名 Elasticsearch是一个基于Lucene库的分布式搜索和分析引擎&#xff0c;它提供了一个分布式、多…

docker/华为云cce 部署nacos 2.3.0 集群模式

镜像地址 https://hub.docker.com/r/nacos/nacos-server 版本 nacos/nacos-server:v2.3.0-slim 关键环境变量 使用mysql数据源 变量值备注MODEcluster启用集群模式MYSQL_SERVICE_DB_NAME数据库名MYSQL_SERVICE_USER数据库用户名MYSQL_SERVICE_PASSWORD数据库密码SPRING_D…

static

static static是表示静态&#xff0c;是java里面的一个修饰符&#xff0c;可以修饰成员方法&#xff0c;成员变量 静态变量 被static修饰的变量&#xff0c;叫静态变量&#xff0c; 特点&#xff1a; 1.被该类所有的对象共享 &#xff0c; 2.不属于对象&#xff0c;属于类 3…