Spring Security安全框架

本文介绍了Spring Security安全框架的使用,包括认证和授权两大核心功能。通过添加依赖并自定义安全管理配置,如继承webSecurityConfigureAdapter,重写AuthenticationManagerBuilder和HttpSecurity的配置方法。在JDBC认证中,涉及用户表、权限表和用户权限关联关系表的设计,并提供了SQL查询示例。此外,还提到了创建工具类和控制层的方法添加。
摘要由CSDN通过智能技术生成

安全管理:

认证:确认用户是否登录,对登录进行管控

授权:确定用户的权限,对用户权限进行管理

步骤:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值