速读摘要文章源自JAVA秀-https://www.javaxiu.com/12583.html
Shiro是一个强大且易用的Java安全框架,能够非常清晰的处理认证、授权、管理会话以及密码加密。Security在架构上将认证与授权分离,并提供了扩展点。Spring Security社区支持度更高,Spring社区的亲儿子,支持力度和更新维护上有优势,同时和Spring这一套的结合较好。Security我觉得更合适一些,他们本身就是一套东西,可能略微复杂一些,但是学会了就是自己的。文章源自JAVA秀-https://www.javaxiu.com/12583.html
原文约 4016 字 | 图片 7 张 | 建议阅读 9 分钟 | 评价反馈文章源自JAVA秀-https://www.javaxiu.com/12583.html
在 SpringBoot 项目中,Spring Security 和 Shiro 该如何选择?
点击关注 ? 芋道源码 文章源自JAVA秀-https://www.javaxiu.com/12583.html
收录于话题文章源自JAVA秀-https://www.javaxiu.com/12583.html
#芋道源码文章源自JAVA秀-https://www.javaxiu.com/12583.html
4个文章源自JAVA秀-https://www.javaxiu.com/12583.html
点击上方“芋道源码”,选择“设为星标”文章源自JAVA秀-https://www.javaxiu.com/12583.html
管她前浪,还是后浪?文章源自JAVA秀-https://www.javaxiu.com/12583.html
能浪的浪,才是好浪!文章源自JAVA秀-https://www.javaxiu.com/12583.html
每天 8:55 更新文章,每天掉亿点点头发...文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html 源码精品专栏文章源自JAVA秀-https://www.javaxiu.com/12583.html
原创 | Java 2020 超神之路,很肝~文章源自JAVA秀-https://www.javaxiu.com/12583.html
中文详细注释的开源项目文章源自JAVA秀-https://www.javaxiu.com/12583.html
RPC 框架 Dubbo 源码解析文章源自JAVA秀-https://www.javaxiu.com/12583.html
网络应用框架 Netty 源码解析文章源自JAVA秀-https://www.javaxiu.com/12583.html
消息中间件 RocketMQ 源码解析文章源自JAVA秀-https://www.javaxiu.com/12583.html
数据库中间件 Sharding-JDBC 和 MyCAT 源码解析文章源自JAVA秀-https://www.javaxiu.com/12583.html
作业调度中间件 Elastic-Job 源码解析文章源自JAVA秀-https://www.javaxiu.com/12583.html
分布式事务中间件 TCC-Transaction 源码解析文章源自JAVA秀-https://www.javaxiu.com/12583.html
Eureka 和 Hystrix 源码解析文章源自JAVA秀-https://www.javaxiu.com/12583.html
Java 并发源码文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html
Shiro文章源自JAVA秀-https://www.javaxiu.com/12583.html
Spring Security文章源自JAVA秀-https://www.javaxiu.com/12583.html
两者对比文章源自JAVA秀-https://www.javaxiu.com/12583.html
我的看法文章源自JAVA秀-https://www.javaxiu.com/12583.html
大家好,我是艿艿。文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html
在开始本文之前,我们做个问卷调查,看看胖友都在使用哪个?文章源自JAVA秀-https://www.javaxiu.com/12583.html
嘿嘿,不管胖友怎么选,艿艿各给他们肝了一篇实战文章:文章源自JAVA秀-https://www.javaxiu.com/12583.html
Spring Security:http://www.iocoder.cn/Spring-Boot/Spring-Security/?nb文章源自JAVA秀-https://www.javaxiu.com/12583.html
Shiro :http://www.iocoder.cn/Spring-Boot/Shiro/?nb文章源自JAVA秀-https://www.javaxiu.com/12583.html
OK,不哔哔了,开始~文章源自JAVA秀-https://www.javaxiu.com/12583.html
要知道Shiro和Spring Security该如何选择,首先要看看两者的区别和对比文章源自JAVA秀-https://www.javaxiu.com/12583.html
Shiro
Apache Shiro是一个强大且易用的Java安全框架,能够非常清晰的处理认证、授权、管理会话以及密码加密。使用Shiro的易于理解的API,您可以快速、轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和企业应用程序。文章源自JAVA秀-https://www.javaxiu.com/12583.html
执行流程
文章源自JAVA秀-https://www.javaxiu.com/12583.html
图片文章源自JAVA秀-https://www.javaxiu.com/12583.html
特点
易于理解的 Java Security API;文章源自JAVA秀-https://www.javaxiu.com/12583.html
简单的身份认证(登录),支持多种数据源(LDAP,JDBC,Kerberos,ActiveDirectory 等);文章源自JAVA秀-https://www.javaxiu.com/12583.html
对角色的简单的签权(访问控制),支持细粒度的签权;文章源自JAVA秀-https://www.javaxiu.com/12583.html
支持一级缓存,以提升应用程序的性能;文章源自JAVA秀-https://www.javaxiu.com/12583.html
内置的基于 POJO 企业会话管理,适用于 Web 以及非 Web 的环境;文章源自JAVA秀-https://www.javaxiu.com/12583.html
异构客户端会话访问;文章源自JAVA秀-https://www.javaxiu.com/12583.html
非常简单的加密 API;文章源自JAVA秀-https://www.javaxiu.com/12583.html
不跟任何的框架或者容器捆绑,可以独立运行。文章源自JAVA秀-https://www.javaxiu.com/12583.html
Spring Security
Spring Security 主要实现了Authentication(认证,解决who are you? ) 和 Access Control(访问控制,也就是what are you allowed to do?,也称为Authorization)。Spring Security在架构上将认证与授权分离,并提供了扩展点。它是一个轻量级的安全框架,它确保基于Spring的应用程序提供身份验证和授权支持。它与Spring MVC有很好地集成 ,并配备了流行的安全算法实现捆绑在一起。文章源自JAVA秀-https://www.javaxiu.com/12583.html
执行流程
文章源自JAVA秀-https://www.javaxiu.com/12583.html
图片文章源自JAVA秀-https://www.javaxiu.com/12583.html
客户端发起一个请求,进入 Security 过滤器链。文章源自JAVA秀-https://www.javaxiu.com/12583.html
当到 LogoutFilter 的时候判断是否是登出路径,如果是登出路径则到 logoutHandler ,如果登出成功则到 logoutSuccessHandler 登出成功处理,如果登出失败则由 ExceptionTranslationFilter ;如果不是登出路径则直接进入下一个过滤器。文章源自JAVA秀-https://www.javaxiu.com/12583.html
当到 UsernamePasswordAuthenticationFilter 的时候判断是否为登录路径,如果是,则进入该过滤器进行登录操作,如果登录失败则到 AuthenticationFailureHandler 登录失败处理器处理,如果登录成功则到 AuthenticationSuccessHandler 登录成功处理器处理,如果不是登录请求则不进入该过滤器。文章源自JAVA秀-https://www.javaxiu.com/12583.html
当到 FilterSecurityInterceptor 的时候会拿到 uri ,根据 uri 去找对应的鉴权管理器,鉴权管理器做鉴权工作,鉴权成功则到 Controller 层否则到 AccessDeniedHandler 鉴权失败处理器处理。文章源自JAVA秀-https://www.javaxiu.com/12583.html
特点
shiro能实现的,Spring Security 基本都能实现,依赖于Spring体系,但是好处是Spring全家桶的亲儿子,集成上更加契合,在使用上,比shiro略负责。文章源自JAVA秀-https://www.javaxiu.com/12583.html
两者对比
Shiro比Spring Security更容易使用,也就是实现上简单一些,同时基本的授权认证Shiro也基本够用文章源自JAVA秀-https://www.javaxiu.com/12583.html
Spring Security社区支持度更高,Spring社区的亲儿子,支持力度和更新维护上有优势,同时和Spring这一套的结合较好。文章源自JAVA秀-https://www.javaxiu.com/12583.html
Shiro 功能强大、且 简单、灵活。是Apache 下的项目比较可靠,且不跟任何的框架或者容器绑定,可以独立运行。文章源自JAVA秀-https://www.javaxiu.com/12583.html
我的看法
如果开发的项目是Spring这一套,用Spring Security我觉得更合适一些,他们本身就是一套东西,顺畅,可能略微复杂一些,但是学会了就是自己的。如果开发项目比较紧张,Shiro可能更合适,容易上手,也足够用,Spring Security中有的,Shiro也基本都有,没有的部分网上也有大批的解决方案。文章源自JAVA秀-https://www.javaxiu.com/12583.html
如果项目没有使用Spring这一套,不用考虑,直接Shiro。文章源自JAVA秀-https://www.javaxiu.com/12583.html
同时要考虑团队成员的技术栈,更加熟悉使用哪个,在选型上,也要尽量避免给同行增加不必要的学习成本!文章源自JAVA秀-https://www.javaxiu.com/12583.html
欢迎加入我的知识星球,一起探讨架构,交流源码。加入方式,长按下方二维码噢:文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html
已在知识星球更新源码解析如下:文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html
最近更新《芋道 SpringBoot 2.X 入门》系列,已经 20 余篇,覆盖了 MyBatis、Redis、MongoDB、ES、分库分表、读写分离、SpringMVC、Webflux、权限、WebSocket、Dubbo、RabbitMQ、RocketMQ、Kafka、性能测试等等内容。文章源自JAVA秀-https://www.javaxiu.com/12583.html
提供近 3W 行代码的 SpringBoot 示例,以及超 4W 行代码的电商微服务项目。文章源自JAVA秀-https://www.javaxiu.com/12583.html
获取方式:点“在看”,关注公众号并回复 666 领取,更多内容陆续奉上。文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章源自JAVA秀-https://www.javaxiu.com/12583.html
文章有帮助的话,在看,转发吧。谢谢支持哟 (*^__^*)文章源自JAVA秀-https://www.javaxiu.com/12583.html
阅读原文文章源自JAVA秀-https://www.javaxiu.com/12583.html

评论