shiro程序小寨分布式

Shiro在前后台分离架构项目中的应用

2018-12-18  本文已影响22人  梦中一点心雨

Shiro是Apache的强大灵活的开源安全框架

能提供认证、授权、企业会话管理、安全加密、缓存等功能。

与Spring Security的比较

Apache Shiro Spring Security
简单灵活 复杂、笨重
可脱离Spring 必须依赖Spring
粒度较粗 粒度更细

Shiro的几个关键要素

Shiro内置的过滤器

过滤器简称过滤器简称 对应的java类
anon org.apache.shiro.web.filter.authc.AnonymousFilter
authc org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authcBasic org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
perms org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter
port org.apache.shiro.web.filter.authz.PortFilter
rest org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter
roles org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
ssl org.apache.shiro.web.filter.authz.SslFilter
user org.apache.shiro.web.filter.authc.UserFilter
logout org.apache.shiro.web.filter.authc.LogoutFilter

Shiro在前后台分离架构的项目中的应用

Shiro在传统web项目中的应用与前后台分离项目中的区别

传统项目中,前后台在一个工程里,页面的跳转,请求的访问,一般都是由后台来控制,中间不需要做太多的转换。

而在前后台分离项目中,前后台在不同的工程里,也在不同的服务器上,页面的跳转由前端路由来控制(其实也没啥页面的跳转,随着前端框架如雨后竹笋一般的冒出来,前端应用都往单页面应用的方向发展),后台只负责提供数据以及安全验证,对于页面的东西后台已经不做关注。在这种情况下,在使用Shiro时就需要有一些自定义的东西了。

需要关注的几个点

具体实现

作为一个SpringBoot洗脑流,不管是什么新东西,最先想到的就是通过SpringBoot来集成。这里通过SpringBoot,集成Shiro、Swagger(模拟前台通过JSON请求后台)、Redis(暂时只存储Session),使用Swagger来模拟请求,测试Shiro的权限控制。

以下的集成相关东西,都是建立于一个完整的SpringBoot Demo。

以上相关源码,请访问https://github.com/ArtIsLong/shiro-spring-boot-starter.git

上一篇 下一篇

猜你喜欢

热点阅读