# edits-shiro-spring-boot-starter **Repository Path**: asddddd/edits-shiro-spring-boot-starter ## Basic Information - **Project Name**: edits-shiro-spring-boot-starter - **Description**: 参考 https://gitee.com/liselotte/spring-boot-shiro-demo 进行修改,简单的封装一个基于shiro的单点登录jar - **Primary Language**: Unknown - **License**: AFL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2020-11-05 - **Last Updated**: 2022-05-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 参考 https://gitee.com/liselotte/spring-boot-shiro-demo 进行修改,简单的封装一个基于shiro的单点登录starter 一:使用须知: 1、配置项目数据源 2、配置项目redis 二:简述说明: 1、引入此依赖会自动创建数据库表,建表SQL如下: ``` create table if not exists sys_menu( menu_id bigint auto_increment comment '权限ID' primary key, parent_id bigint null comment '父级菜单ID', name varchar(50) null comment '权限名称', perms varchar(500) null comment '权限标识', url varchar(256) not null comment 'url地址', create_time datetime default CURRENT_TIMESTAMP null comment '创建时间', icon varchar(256) null comment '图标' ) comment '权限表' charset = utf8; create table if not exists sys_role ( role_id bigint auto_increment comment '角色ID' primary key, role_name varchar(50) not null comment '角色名称', remark varchar(256) null comment '备注信息', create_time datetime default CURRENT_TIMESTAMP null comment '创建时间' ) comment '角色表' charset = utf8; create table if not exists sys_role_menu ( id bigint auto_increment comment 'ID' primary key, role_id bigint null comment '角色ID', menu_id bigint null comment '权限ID' ) comment '角色与权限关系表' charset = utf8; create table if not exists sys_user ( user_id bigint auto_increment comment '用户ID' primary key, username varchar(50) not null comment '用户名', password varchar(100) null comment '密码', salt varchar(50) null comment '盐值', status varchar(50) null comment '状态:NORMAL正常 PROHIBIT禁用', create_time datetime default CURRENT_TIMESTAMP null comment '创建时间', create_user varchar(256) null comment '创建该账号的操作者', modify_time datetime default CURRENT_TIMESTAMP null comment '修改时间', modify_user varchar(256) null comment '修改该账户的操作者', remark varchar(256) null comment '备注信息' ) comment '系统用户表' charset = utf8; create table if not exists sys_user_role ( id bigint auto_increment comment 'ID' primary key, user_id bigint null comment '用户ID', role_id bigint null comment '角色ID' ) comment '用户与角色关系表' charset = utf8; ``` 2、实现org.edith.shiro.need.implement.UrlFilterInterface接口,重构方法,方法返回值可选,并添加@Service注解 ``` /** * 需要配置的过滤器URL信息 */ public interface UrlFilterInterface { /** * 允许匿名访问URL集合,比如css等 * @return */ Set getAnonUrlSet(); /** * 需要鉴权操作的URL集合 * @return */ Set getAuthcUrlSet(); /** * 自定义的鉴权过滤器 * @return */ Set getAuthcFilters(); /** * 自定义的匿名访问过滤器 * @return */ Set getAnonFilters(); } ``` 3、鉴权操作,在controller的@RequestMapping 方法标注上 添加@RequiresPermissions("此处值对应sys_menu表的perms字段值") 四:注意事项: ``` 1、为了安全起见,starter中没有预留各个数据表的insert接口,仅留有login/logout接口 2、如果需要更改sys_user表,建议先引入该starter,启动一次项目,start会自动创建数据库表,而后在进行修改数据库表即可 3、可以扩展自己的用户业务数据,将自己用户表与sys_user表做一个关联关系即可 4、sys_user表保存数据时,需要添加盐值,可使用org.edith.shiro.util.UserPasswordUtils工具进行添加,盐值位20长度的随机字符串 5、sys_user表中,用户状态值有两个分别是 NORMAL(正常)、PROHIBIT(禁止) ``` 五:接口文档: 基础返回值格式: ``` { "success":true/false, "code":"错误码", "message":"相关文本信息", "data":"返回值具体数据内容JSON格式" } ``` 1、登录接口: ``` 请求方式:POST url:/user/login contentType:application/json import:{"username":"登录用户名","password":"登录用户密码"} output:{ "success":true, "code":"SUCCESS", "message":"操作成功", "data":null } ``` 2、注销接口: ``` 请求方式:POST url:/user/logout contentType:application/json import:{无任何参数} output:{ "success":true, "code":"SUCCESS", "message":"操作成功", data":{"token":"token值"} } ``` 六:返回值枚举信息 枚举类:org.edith.shiro.enums.ResponseEnum {"code":"SUCCESS","message":"操作成功"} {"code":"FAILURE","message":"操作失败"} {"code":"INCORRECT_USERNAME_OR_PASSWORD","message":"用户名或密码输入错误"} {"code":"NO_ACCESS","message":"无访问权限"} {"code":"NO_LOGIN","message":"用户未登录"} {"code":"ACCOUNT_LOCKED","message":"账户被锁定"} {"code":"SYS_ERROR","message":"系统内部错误"} 七:请求头设置 key:Authorization value:token值