基于 Spring Security 的前后端分离的权限控制系统
话不多说,入正题。一个简单的权限控制系统需要考虑的问题如下:
- 权限如何加载
- 权限匹配规则
- 登录
1. 引入maven依赖
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.5.1</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.example</groupId> 12 <artifactId>demo5</artifactId> 13 <version>0.0.1-SNAPSHOT</version> 14 <name>demo5</name> 15 16 <properties> 17 <java.version>1.8</java.version> 18 </properties> 19 20 <dependencies> 21 <dependency> 22 <groupId>org.springframework.boot</groupId> 23 <artifactId>spring-boot-starter-data-jpa</artifactId> 24 </dependency> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter-data-redis</artifactId> 28 </dependency> 29 <dependency> 30 <groupId>org.springframework.boot</groupId> 31 <artifactId>spring-boot-starter-security</artifactId> 32 </dependency> 33 <dependency> 34 <groupId>org.springframework.boot</groupId> 35 <artifactId>spring-boot-starter-web</artifactId> 36 </dependency> 37 38 <dependency> 39 <groupId>io.jsonwebtoken</groupId> 40 <artifactId>jjwt</artifactId> 41 <version>0.9.1</version> 42 </dependency> 43 44 <dependency> 45 <groupId>com.alibaba</groupId> 46 <artifactId>fastjson</artifactId> 47 <version>1.2.76</version> 48 </dependency> 49 <dependency> 50 <groupId>org.apache.commons</groupId> 51 <artifactId>commons-lang3</artifactId> 52 <version>3.12.0</version> 53 </dependency> 54 <dependency> 55 <groupId>commons-codec</groupId> 56 <artifactId>commons-codec</artifactId> 57 <version>1.15</version> 58 </dependency> 59 60 <dependency> 61 <groupId>mysql</groupId> 62 <artifactId>mysql-connector-java</artifactId> 63 <scope>runtime</scope> 64 </dependency> 65 <dependency> 66 <groupId>org.projectlombok</groupId> 67 <artifactId>lombok</artifactId> 68 <optional>true</optional> 69 </dependency> 70 </dependencies> 71 72 <build> 73 <plugins> 74 <plugin> 75 <groupId>org.springframework.boot</groupId> 76 <artifactId>spring-boot-maven-plugin</artifactId> 77 <configuration> 78 <excludes> 79 <exclude> 80 <groupId>org.projectlombok</groupId> 81 <artifactId>lombok</artifactId> 82 </exclude> 83 </excludes> 84 </configuration> 85 </plugin> 86 </plugins> 87 </build> 88 89 </project>