官网地址:https://spring.io/projects/spring-security#overview

Spring家族当中,一个安全管理框架
Shiro也是一个安全框架,提供了很多安全功能。Shiro比较老,旧的项目当中,可能还在使用。上手还挺简单
在新项目当中,一线互联网大型项目,都是使用SpringSecurity
一般的web项目当中,总会有登陆认证和鉴权的需求但是大家一定要区分开。
所以说,安全框架SpringSecurity 当中,必定会有认证和鉴权的两大核心功能
1、创建springboot web项目
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.6.5version>
<relativePath/>
parent>
<groupId>com.liminggroupId>
<artifactId>springsecuritydemoartifactId>
<version>0.0.1-SNAPSHOTversion>
<name>springsecuritydemoname>
<description>springsecuritydemodescription>
<properties>
<java.version>1.8java.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<optional>trueoptional>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
exclude>
excludes>
configuration>
plugin>
plugins>
build>
project>
2、创建controller
package com.liming.springsecuritydemo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author 黎明
* @date 2023/5/27 20:39
* @version 1.0
*/
@RestController
@RequestMapping("/demo")
public class SpringSecurityDemo {
@GetMapping("/hello")
public String hello(){
return "hello springsecurity";
}
}
3、启动 测试 访问 :http://localhost:8080/demo/hello

4、引入SpringSecurity
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-securityartifactId>
dependency>
5、测试:http://localhost:8080/demo/hello
SpringSecurity 自带的登陆页面

输入自带默认用户名user 和 密码(控制台)

就能访问到数据了

6、自带退出:http://localhost:8080/logout

