Spring Security是基于Spring框架,提供了一套Web应用安全性的完整解决方案。主要核心功能是:用户认证(Authentication) 和 用户授权(Authonization)。
- 用户认证:通俗理解就是登录认证
- 用户授权:用户对某个资源的是否有操作权限
Spring Security特点
- 能够和 Spring 快速整合
- 全面的权限控制
- 专门为 Web 开发而设计
Spring Security 应用入门搭建
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>
<groupId>com.example</groupId>
<artifactId>web-security</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>web-security</name>
<description>web-security</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.3.10.RELEASE</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
应用启动类
typescript
@SpringBootApplication
public class WebSecurityApplication {
public static void main(String[] args) {
SpringApplication.run(WebSecurityApplication.class, args);
}
}
http://localhost:9904/user
,输入请求链接后,会跳转到登录页面,用户名:user,密码:11371f3b-9ef4-4ab4-b3d1-a5ce76344e20。