提供一套基于Spring Boot-Shiro-Vue的权限管理思路.前后端都加以控制,做到按钮/接口级别的权限

Overview

Spring Boot-Shiro-Vue

提供一套基于SpringBoot-shiro-vue的权限管理思路.

前后端都加以控制,做到按钮/接口级别的权限

DEMO

测试地址

admin/123456 管理员身份登录,可以新增用户,角色.

角色可以分配权限

控制菜单是否显示,新增/删除按钮是否显示

设计思路

核心

每个登录用户拥有各自的N条权限,比如 文章:查看/编辑/发布/删除

后端

基于 RBAC新解 .

通常我们的权限设计都是 用户--角色--权限 ,其中角色是我们写代码的人没法控制的,它可以有多条权限,每个用户又可以设计为拥有多个角色.因此如果从角色着手进行权限验证,系统都必须根据用户的配置动起来,非常复杂.

所以我们后台设计的关键点就在于: 后台接口只验证权限,不看角色.

角色的作用其实只是用来管理分配权限的,真正的验证只验证权限 ,而不去管你是否是那种角色.体现在代码上就是接口上注解为

@RequiresPermissions("article:add")

而不是

@RequiresRoles(value = {"admin","manager","writer"}, logical = Logical.OR) 

前端

采用了vueAdmin-template , ElementUI , 权限设计思路也是参考了 vueAdmin 的动态路由的设计.

后端负责了接口的安全性,而前端之所以要做权限处理,最主要的目的就是隐藏掉不具有权限的菜单(路由)和按钮.

登录系统后,后端返回此用户的权限信息,比如

 "userPermission":{  
         "menuList":[  
            "role",
            "user",
            "article"
         ],
         "roleId":1,
         "nickname":"超级用户",
         "roleName":"管理员",
         "permissionList":[  
            "article:list",
            "article:add",
            "user:list",
         ],
         "userId":10003
      }

根据menuList判断给此用户生成哪些路由, 根据permissionList判断给用户显示哪些按钮,能请求哪些接口.

数据库

最主要的是要有一张本系统内的全部权限明细表,比如下面这样 权限表 权限数据

如果某用户拥有表格中前五条权限,就可以查出他就拥有article和user两个菜单,至于页面内是否显示(新增)(修改)按钮,就根据他的permissionList来判断.

具体实现

有了思路,就可以根据各自的业务进行实现,本项目在此进行了简单的实现,后端代码在back文件夹,前端代码在vue文件夹.前端启动只需

npm install
npm run dev

后端就是常规的shiro配置,前端代码如果看不明白,可以参考前端权限代码说明

分配权限页面效果

分配权限页面

Comments
  • 登录问题 org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported

    登录问题 org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported

    我将你的项目部署到idea后,前后端都可以启动,但是登录的时候后台报错了。

    org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:224) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:165) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901)

    opened by yanwencaihubei 13
  • 用户信息可以成功保存到 session,但是后面从 session 中获取不到

    用户信息可以成功保存到 session,但是后面从 session 中获取不到

    执行语句 SecurityUtils.getSubject().getSession().setAttribute(ShiroConstant.SESSION_USER_INFO, user); 后,用户信息是成功保存上了的,但是后面再通过 (User) session.getAttribute(ShiroConstant.SESSION_USER_INFO); 获取时,结果为null

    opened by guoguocai 9
  • 好,需要帮忙,我发到服务器的时候,会出现Long类型不精准,用本地的运行,Long类型会String,没此问题

    好,需要帮忙,我发到服务器的时候,会出现Long类型不精准,用本地的运行,Long类型会String,没此问题

    @Configuration public class DefaultView extends WebMvcConfigurerAdapter { @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); ObjectMapper objectMapper = new ObjectMapper(); /** * 序列换成json时,将所有的long变成string * 因为js中得数字类型不能包含所有的java long值 / SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(Long.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); objectMapper.registerModule(simpleModule); jackson2HttpMessageConverter.setObjectMapper(objectMapper); converters.add(jackson2HttpMessageConverter); } // /* // *

    Description: 解决js处理long型丢失精度问题,将long转换成long

    // * @author hanchao // * @date 2018/7/23 下午4:31 // */ // @Override // public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { // //定义Json转换器 // MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = // new MappingJackson2HttpMessageConverter(); // //定义对象映射器 // ObjectMapper objectMapper = new ObjectMapper(); // //定义对象模型 // SimpleModule simpleModule = new SimpleModule(); // //添加对长整型的转换关系 // simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance); // simpleModule.addSerializer(Long.class, ToStringSerializer.instance); // simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); // //将对象模型添加至对象映射器 // objectMapper.registerModule(simpleModule); // //将对象映射器添加至Json转换器 // jackson2HttpMessageConverter.setObjectMapper(objectMapper); // // //在转换器列表中添加自定义的Json转换器 // converters.add(jackson2HttpMessageConverter); // //添加utf-8的默认String转换器 // converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8"))); // } @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("forward:/index.html"); // registry.addViewController("/").setViewName("public/index.html"); registry.setOrder(Ordered.HIGHEST_PRECEDENCE); super.addViewControllers(registry); } }

    opened by hzhh110 8
  • 开发环境ok,部署到服务器提示“登录已过期”

    开发环境ok,部署到服务器提示“登录已过期”

    目前部署步骤: 1、按历史issues里面的做法,npm run build; 1.1 除了修改配置文件外,前端其他代码并未修改; image

    2、将dist目录下的文件,放在resources文件中,然后打war包到Tomcat部署; image

    3、访问返回如下提示: {"msg":"登陆已过期,请重新登陆","code":"20011"}

    image

    请问我哪里不对呢?非常感谢!!

    opened by WinChance 7
  • 后台运行有问题

    后台运行有问题

    2019-03-13 16:55:38.773 INFO 26640 --- [ main] com.heeexy.example.MyApplication : No active profile set, falling back to default profiles: default 2019-03-13 16:55:40.622 INFO 26640 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroConfiguration' of type [com.heeexy.example.config.shiro.ShiroConfiguration$$EnhancerBySpringCGLIB$$50c29246] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-03-13 16:55:41.143 INFO 26640 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'mybatis-org.mybatis.spring.boot.autoconfigure.MybatisProperties' of type [org.mybatis.spring.boot.autoconfigure.MybatisProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-03-13 16:55:41.148 INFO 26640 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration' of type [org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$b9ab938a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-03-13 16:55:41.149 INFO 26640 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

    后台运行后,一直报“for example: not eligible for auto-proxying”

    opened by DoubleShadowLZF 6
  • 通过案例后台整合shiro出现了问题

    通过案例后台整合shiro出现了问题

    我通过postman测试了登录后,doGetAuthorizationInfo方法一直不执行。并且无论controller上的方法有没有配置需要权限的注释,都无法执行,都直接会提醒我在AjaxPermissionsAuthorizationFilter配置的报错登录已过期,难道是因为无法通过postman进行登录状态的保持么?希望能帮帮我。

    opened by crayymumu 3
Owner
null
该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的线上博客项目/企业大型商城系统/前后端分离实践项目等,摆脱各种 hello world 入门案例的束缚,真正的掌握 Spring Boot 开发。

Spring Boot Projects 该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的前

十三 4.5k Dec 30, 2022
springboot 框架与其它组件结合如 jpa、mybatis、websocket、security、shiro、cache等

致歉 由于自己懒以及身体对issuse 解决的不及时。请大家以后提issuse 的时候写清楚 模块名 比如“springboot-SpringSecurity4” 和问题,我会抽时间抓紧解决。 springboot-SpringSecurity0 包含两部分代码: 第一是 博客 springboot

abel 5.9k Jan 5, 2023
Guns基于SpringBoot 2,致力于做更简洁的后台管理系统,完美整合springmvc + shiro + mybatis-plus + beetl!Guns项目代码简洁,注释丰富,上手容易,同时Guns包含许多基础模块(用户管理,角色管理,部门管理,字典管理等10个模块),可以直接作为一个后台管理系统的脚手架!

Guns基于Spring Boot2,致力于做更简洁的后台管理系统。包含系统管理,代码生成,多数据库适配,SSO单点登录,工作流,短信,邮件发送,OAuth2登录,任务调度,持续集成,docker部署等功。支持Spring Cloud Alibaba微服务。社区活跃,版本迭代快,加群免费技术支持。

冯硕楠 3.6k Jan 5, 2023
shiro-cve-2020-17523 漏洞的两种绕过姿势分析(带漏洞环境)

Apache Shiro 两种姿势绕过认证分析(CVE-2020-17523) 0x01 漏洞描述 Apache Shiro是一个强大且易用的Java安全框架,执行身份验证、授权、密码和会话管理。使用Shiro的易于理解的API,您可以快速、轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和

null 92 Nov 9, 2022
【多模块微服务脚手架平台——Ancba】前后端分离架构SpringBoot 2.x、SpringCloud、SpringAdmin、Spring Security、Mybatis-plus、(Shiro)、JWT、Feign、Nacos、Knif4j等。

Ancba 打造Blog.Core项目的SpringBoot微服务版,但是更强大 ?? Ancba (Another New CLI By Alacrity) 另一个全新的敏捷脚手架(单体/模块化/微服务都可支持)。 核心知识点与进度 ?? 在 ..../resources/application-

ansonzhang 35 Nov 29, 2022
ShiroExploit 是一款 Shiro 可视化利用工具,集成密钥爆破,命令回显内存马注入等功能

ShiroExploit Shiro 可视化利用工具(beta 免责声明 该项目仅供合法的渗透测试以及爱好者参考学习,请各位遵守《中华人民共和国网络安全法》以及相应地方的法律,禁止使用该项目进行违法操作,否则自行承担相关责任 目前已实现: 支持密钥爆破以及 CBC/GCM 两种加密模式 可修改特征头

天下大木头 119 Jan 25, 2022
A personal blog based on Vue+SpringBoot+MySql+Redis+Shiro+JWT

项目:Vue-SpringBoot-PersonalBlog 个人博客网址:http://www.huchao.vip/blogs CSDN:毛_三月 介绍 一个基于SpringBoot + Vue+MybatisPlus+Shiro+JWT+Redis开发的前后端分离博客项目,带有超级详细开发文档

Chao. Hu 26 Dec 20, 2022
about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。

Spring Boot 学习示例 Spring Boot 使用的各种示例,以最简单、最实用为标准,此开源项目中的每个示例都以最小依赖,最简单为标准,帮助初学者快速掌握 Spring Boot 各组件的使用。 Spring Boot 中文索引 | Spring Cloud学习示例代码 | Spring

纯洁的微笑 28.3k Jan 1, 2023
spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。另外写博客,用 OpenWrite。

推荐工具: 微信公众号 Markdown 编辑器 - OpenWrite:Markdown 微信编辑器是一款专业强大的微信公众平台在线编辑排版工具,提供手机预览功能,让用户在微信图文 、文章、内容排版、文本编辑、素材编辑上更加方便。 - 更多介绍 博客群发平台 一、支持泥瓦匠 Spring Boot

泥瓦匠BYSocket 15.2k Jan 5, 2023
Spring-Boot-Plus is a easy-to-use, high-speed, high-efficient,feature-rich, open source spring boot scaffolding

Everyone can develop projects independently, quickly and efficiently! What is spring-boot-plus? A easy-to-use, high-speed, high-efficient, feature-ric

geekidea 2.3k Dec 31, 2022
Two Spring-boot applications registering themselves to an spring-boot-admin-server application as separate clients for the purpose of monitoring and managing the clients

Spring-boot-admin implementation with 1 Server and 2 clients Creating a Server application to monitor and manage Spring boot applications (clients) un

null 6 Dec 6, 2022
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

null 58 Jan 5, 2023
The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker.

gke-springboot-sampleapp ?? The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker. Usage To be

KYEONGMIN CHO 1 Feb 1, 2022
Spring Boot Migrator (SBM) - a tool for automated code migrations to upgrade or migrate to Spring Boot

Spring Boot Migrator uses and is compatible to OpenRewrite, a powerful mass refactoring ecosystem for Java and other source code.

Spring Projects Experimental 231 Jan 2, 2023
mall-swarm是一套微服务商城系统,采用了 Spring Cloud Hoxton & Alibaba、Spring Boot 2.3、Oauth2、MyBatis、Docker、Elasticsearch、Kubernetes等核心技术,同时提供了基于Vue的管理后台方便快速搭建系统。mall-swarm在电商业务的基础集成了注册中心、配置中心、监控中心、网关等系统功能。文档齐全,附带全套Spring Cloud教程。

mall-swarm 友情提示 快速体验项目:在线访问地址。 全套学习教程:《mall学习教程》。 Spring Cloud全套教程:《SpringCloud学习教程》。 专属学习路线:学习不走弯路,整理了套非常不错的《mall专属学习路线》。 项目交流:想要加群交流项目的朋友,可以加入mall项目

macro 9.7k Jan 3, 2023
云收藏 Spring Boot 2.X 开源项目

云收藏 - 让收藏更简单 云收藏是一个使用 Spring Boot 构建的开源网站,可以让用户在线随时随地收藏的一个网站,在网站上分类整理收藏的网站或者文章,可以作为稍后阅读的一个临时存放。作为一个开放开源的软件,可以让用户从浏览器将收藏夹内容导入到云收藏,也支持随时将云收藏收集的文章导出去做备份。

null 4.7k Jan 9, 2023
芋道 mall 商城,基于微服务的思想,构建在 B2C 电商场景下的项目实战。核心技术栈,是 Spring Boot + Dubbo 。未来,会重构成 Spring Cloud Alibaba 。

[toc] 友情提示:近期在升级和优化该项目,建议先 Star 本项目。主要在做几个事情: 1、微服务技术选型以 Spring Cloud Alibaba 为中心。 2、修改项目分层,并合并部分服务,简化整体服务的复杂性。 3、将管理后台从 React 重构到 Vue 框架。 交流群:传送门 前言

芋道源码 7k Jan 6, 2023