spring boot 前后端分离整合shiro(一)快速上手
前言
第一次写博客,可能有些地方表达不是很好,不对的地方欢迎大家指出。
shiro简介
shiro是apache的一个权限框架,相比spring security更简单易用。在使用shiro前一定要对它执行的一个基本流程、内部组件有一个大概的了解。
shiro中有三个重要的概念:
- Subject
主体。可以是一个程序、一个用户,用来表示当前登录的对象。我们通过subject去操作,然后subject委托给Security Manager去执行真正的操作。 - Security Manager
shiro的核心,真正执行操作的地方。 - Realm
安全数据源。指用户的认证授权信息的来源,一般是数据库。
那么一个大概流程就是这样:
快速上手
数据库设计
基于rabc设计一个简单的权限数据库:
可以看出三者都是多对多的关系,所以我们需要三个主表:用户表、角色表、权限表,以及三个关联表。
建表:
create table user_info
(
user_id int auto_increment
primary key,
user_name varchar(100) not null comment '用户名',
login_name varchar(100) not null comment '登录名',
password varchar(100) not null comment '密码',
status int default 0 null comment '状态 1为锁定 0为正常,默认为0'
)
comment '用户表';
create table role
(
role_id int auto_increment
primary key,
role_name varchar(100) not null comment '角色名称',
description varchar(100) null comment '描述'
)
comment '角色表';
create table permission
(
pms_id int auto_increment
primary key,
url varchar(100) not null comment '接口路径',
description varchar(100) not null comment '权限说明',
pms_name varchar(100) not null comment '权限名称'
)
comment '权限表';
create table user_role
(
id int auto_increment
primary key,
user_id int not null comment '用户id'