这篇文章主要介绍了Apache Shrio安全框架实现原理及实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
一、Shiro整体概述
1.简介
Apache Shiro是Java的一个安全框架,功能强大,使用简单,Shiro为开发人员提供了一个直观而全面的认证(登录),授权(判断是否含有权限),加密(密码加密)及会话管理(Shiro内置Session)的解决方案.
2.Shiro组件
3.Shiro架构
3.1 外部架构(以应用程序角度)
3.2 内部架构
4. 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.Rol来源gao@daima#com搞(%代@#码@网esAuthorizationFilter |
ssl |
org.apache.shiro.web.filter.authz.SslFilter |
user |
org.apache.shiro.web.filter.authc.UserFilter |
logout |
org.apache.shiro.web.filter.authc.LogoutFilter |
挑几个重要的说明一下:
anon:匿名过滤器,不登录也可以访问的资源使用,比如首页,一些静态资源等
authc:认证过滤器,登录成功后才能访问的资源使用
perms:授权过滤器,必须具备某种权限才能访问
roles:角色过滤器,必须具备某种角色才能访问
注意:这么多过滤器,使用起来肯定不方便,Shiro框架也考虑到了这一点,所以有一个过滤器,一个顶十个,即DelegatingFilterProxy.
5. Shiro与Spring整合
5.1 pom.xml
<!--shiro和spring整合--> org.apache.shiroshiro-spring1.3.2
5.2 web.xml
shiroFilterorg.springframework.web.filter.DelegatingFilterProxy targetFilterLifecycletrue shiroFilter/*
5.3applicationContext-shiro.xml
/system/module/list.do = perms["模块管理"] /index.jsp* = an以上就是Apache Shrio安全框架实现原理及实例详解的详细内容,更多请关注gaodaima搞代码网其它相关文章!