一、概念
什么是安全框架? 解决系统安全问题的框架。如果没有安全框架,我们需要手动处 理每个资源的访问控制,非常麻烦。使用安全框架,我们可以通过配置的方式实现对资 源的访问限制。(之前用session来认证很麻烦的)
二、快速入门
需求:实现简单的登陆,当用户没有登陆访问主页执行拦截跳转到登陆,登陆后跳转到 主页。实现退出登陆的功能,退出后再次访问主页仍然拦截。用户名和密码不连接数据 库,直接在配置文件中配置。
(1)新建war工程(无骨架maven工程),pom文件引入依赖:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itheima</groupId>
<artifactId>SpingSecurityDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- spring-security依赖 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>