文章目录
- 一、快速上手Spring Security
- 1、创建Maven工程 ,添加相关依赖
- 2、创建Controller
- 3、创建HTML
- 4、创建application.yml
- 5、启动项目,查看效果
- 6、设置自定义密码
- 二、权限管理
- 7、创建SecurityConfig类
- 8、修改Controller
- 9、创建自定义登陆页面
- 10、index.html
- 11、admin.html
- 12、效果
Spring Security
是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架。它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC,DI(控制反转Inversion of Control ,DI:Dependency Injection 依赖注入)和AOP(面向切面编程)功能,为应用系统提供声明式的安全访问控制功能,减少了为企业系统安全控制编写大量重复代码的工作。
一、快速上手Spring Security
1、创建Maven工程 ,添加相关依赖
创建Spring boot
项目,添加Spring Security
依赖和thymeleaf
依赖:
添加依赖后,pom.xml
文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<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.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.3.3</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com</groupId><artifactId>security</artifactId><version>0.0.1-SNAPSHOT</version><name>security</name><description>security</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>22</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- thymeleaf --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!-- security --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency></dependencies><build><plugins>