安全管理:
认证:确认用户是否登录,对登录进行管控
授权:确定用户的权限,对用户权限进行管理
步骤:
1.添加依赖
启动项目,自定义进行安全管理(默认的安全管理模式)
2.自定义安全管理配置
创建配置类:webSecurityConfigureAdapter(去继承它)
重写这两个方法:
config(AuthenticationManagerBuilder auth):设置认证方式
config(HttpSecuritr http):设置访问控制
还有给这个类加上这个注解
@EnableWebSecurity:开启MVC Security安全支持
JDBC认证:
创建表格:
用户表:
username:值唯一
布尔类型的字段:用户是否有效
密码:必须进行加密操作
权限表:
数据要求:
ROLE_名字
用户权限关联关系表:
进行jdbc认证sql:
(1)查询username、password、validate(用户是否有效)
(2)查询username、authority(权限)
创建工具类(config层)
SecurityConfig类
package com.lxyk.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.servlet.WebSecurityEnablerConfiguration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException