1,在web.xml中配置fiter,如下所示

  1. <!-- shiro的filter -->
  2. <!-- shiro过虑器,DelegatingFilterProxy通过代理模式将spring容器中的bean和filter关联起来 -->
  3. <filter>
  4. <filter-name>shiroFilter</filter-name>
  5. <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  6. <!-- 设置true由servlet容器控制filter的生命周期 -->
  7. <init-param>
  8. <param-name>targetFilterLifecycle</param-name>
  9. <param-value>true</param-value>
  10. </init-param>
  11. <!-- 设置spring容器filter的bean id,如果不设置则找与filter-name一致的bean-->
  12. <init-param>
  13. <param-name>targetBeanName</param-name>
  14. <param-value>shiroFilter</param-value>
  15. </init-param>
  16. </filter>
  17. <filter-mapping>
  18. <filter-name>shiroFilter</filter-name>
  19. <url-pattern>/*</url-pattern>
  20. </filter-mapping>

2,上面配置了shiroFilter,那么在spring-shiro.xml中要配置shirofilter bean

  1. <!-- web.xml中shiro的filter对应的bean -->
  2. <!-- Shiro 的Web过滤器 -->
  3. <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
  4. <property name="securityManager" ref="securityManager" />
  5. <!-- loginUrl认证提交地址,如果没有认证将会请求此地址进行认证,请求此地址将由formAuthenticationFilter进行表单认证 -->
  6. <property name="loginUrl" value="/login" />
  7. <!-- 认证成功统一跳转到first.action,建议不配置,shiro认证成功自动到上一个请求路径 -->
  8. <!--<property name="successUrl" value="/index.jsp"/>-->
  9. <!-- 通过unauthorizedUrl指定没有权限操作时跳转页面-->
  10. <!--<property name="unauthorizedUrl" value="/sysPer/noperm" />-->
  11. <!--自定义filter配置 -->
  12. <!--<property name="filters">-->
  13. <!--<map>-->
  14. <!-- 将自定义 的FormAuthenticationFilter注入shiroFilter中-->
  15. <!--<entry key="authc" value-ref="formAuthenticationFilter" />-->
  16. <!--</map>-->
  17. <!--</property>-->
  18.  
  19. <!-- 过虑器链定义,从上向下顺序执行,一般将/** 放在最下边 -->
  20. <property name="filterChainDefinitions">
  21. <value>
  22. <!-- 对静态资源设置匿名访问 -->
  23. /styles/easyui/** = anon
  24. /scripts/easyui/** = anon
  25. /styles/** = anon
  26. /images/** = anon
  27. <!-- 请求 logout地址,shiro去清除session-->
  28. /logout = logout
  29. <!--商品查询需要商品查询权限 ,取消url拦截配置,使用注解授权方式 -->
  30. <!-- /items/queryItems.action = perms[item:query] -->
  31. <!--/sysuser/deleteUser = perms[user:delete]-->
  32. <!-- 配置记住我或认证通过可以访问的地址 -->
  33. <!--/index.jsp = user-->
  34. <!-- /** = authc 所有url都必须认证通过才可以访问-->
  35. /login = anon
  36. /** = authc
  37. </value>
  38. </property>
  39. </bean>

3,在spring-shiro.xml中添加securityManager和自定义realm,ecacheManager的相关配置

  1. <!-- securityManager安全管理器 -->
  2. <!-- realm -->
  3. <bean id="customRealm" class="com.unisits.zngkpt.framework.privilegeframe.CustomeRealm">
  4. <!-- 将凭证匹配器设置到realm中,realm按照凭证匹配器的要求进行散列 -->
  5. <property name="credentialsMatcher" ref="credentialsMatcher"/>
  6. </bean>
  7. <!-- 凭证匹配器 -->
  8. <bean id="credentialsMatcher"
  9. class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
  10. <property name="hashAlgorithmName" value="md5" />
  11. <property name="hashIterations" value="" />
  12. </bean>
  13.  
  14. <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"></bean>
  15.  
  16. <!-- 配额securityManager -->
  17. <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
  18. <property name="realm" ref="customRealm" />
  19. <!-- 注入缓存管理器 -->
  20. <property name="cacheManager" ref="cacheManager"/>
  21. </bean>
  22.  
  23. <!-- 缓存管理器 -->
  24. <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
  25. <property name="cacheManagerConfigFile" value="classpath:shiro-ehcache.xml"/>
  26. </bean>

3,在spring-shiro.xml中,开启shiro的注解支持

  1. <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
    depends-on="lifecycleBeanPostProcessor" />
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
    <property name="securityManager" ref="securityManager" />
    </bean>

4,在spring-shiro.xml中配置shiro认证异常的页面

  1. <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
  2. <property name="exceptionMappings">
  3. <props>
  4. <prop key="org.apache.shiro.authz.UnauthorizedException">/errorpage/refuse</prop>
  5. </props>
  6. </property>
  7. </bean>

springmvc+shiro认证框架配置的更多相关文章

  1. 利用maven开发springMVC项目(二)——框架配置

    申明:主要内容来源于大神博客(使用IntelliJ IDEA开发SpringMVC网站(二)框架配置),我只是用eclipse自己练习使用,记录下来也只是为了学习使用,没有任何的商业用途,侵权必删. ...

  2. Spring、SpringMVC、Mybaitis框架配置

    给大家推荐2个网址,介绍的非常详细 SSM环境搭建 http://blog.csdn.net/zhshulin/article/details/37956105 SSM代码生成工具介绍 http:// ...

  3. SpringMVC整合Shiro权限框架

    尊重原创:http://blog.csdn.net/donggua3694857/article/details/52157313 最近在学习Shiro,首先非常感谢开涛大神的<跟我学Shiro ...

  4. Shiro权限框架与SpringMVC集成

    1.Shiro整合SpringMVC 我们学习Shiro框架肯定是要应用到Web项目上的,所以我们需要整合Shiro和SpringMVC 整合步骤: 第一步:SpringMVC框架的配置 spring ...

  5. SpringMVC下的Shiro权限框架的使用

    SpringMVC+Shiro权限管理 博文目录 权限的简单描述 实例表结构及内容及POJO Shiro-pom.xml Shiro-web.xml Shiro-MyShiro-权限认证,登录认证层 ...

  6. shiro太复杂?快来试试这个轻量级权限认证框架!

    前言 在java的世界里,有很多优秀的权限认证框架,如Apache Shiro.Spring Security 等等.这些框架背景强大,历史悠久,其生态也比较齐全. 但同时这些框架也并非十分完美,在前 ...

  7. Idea简单SpringMVC框架配置

    前边已经介绍过了Struts在Idea上的配置,相对于Struts来说,我觉得SpringMVC有更多的优势,首先Struts是需要对action进行配置,页面发送不同的请求,就需要配置不同的acti ...

  8. springmvc(二) ssm框架整合的各种配置

    ssm:springmvc.spring.mybatis这三个框架的整合,有耐心一步步走. --WH 一.SSM框架整合 1.1.整合思路 从底层整合起,也就是先整合mybatis与spring,然后 ...

  9. 使用IntelliJ IDEA开发SpringMVC网站(二)框架配置

    原文:使用IntelliJ IDEA开发SpringMVC网站(二)框架配置 摘要 讲解如何配置SpringMVC框架xml,以及如何在Tomcat中运行 目录[-] 文章已针对IDEA 15做了一定 ...

随机推荐

  1. [Grunt] Concatenating Your Javascript with grunt-contrib-concat

    Combine serval javascript files together. For angular project, make sure you add angular.min.js firs ...

  2. MFC获得主窗体和父窗体指针

    MFC编程中经常遇到子窗体向父窗体传递參数的情况,这就须要获得父窗体的指针. 例:主对话框CMyMainDlg通过buttonButtonA进入对话框CMyParentDlg.CMyParentDlg ...

  3. 【Caffe代码解析】Layer网络层

    Layer 功能: 是全部的网络层的基类,当中.定义了一些通用的接口,比方前馈.反馈.reshape,setup等. #ifndef CAFFE_LAYER_H_ #define CAFFE_LAYE ...

  4. GCC高级测试功能扩展——程序性能测试工具gprof、程序覆盖测试工具gcov

    gprof是GNU组织下的一个比较有用的性能测试功能: 主要功能:   找出应用程序中消耗CPU时间最多的函数: 产生程序运行时的函数调用关系.调用次数 基本原理:   首先用户要使用gprof工具, ...

  5. spring测试实例

    我们以前要进行单元测试,必须先得到ApplicationContext对象,再通过它得到业务对象,非常麻烦,重复代码也多.基于spring3的单元测试很好的解决了这个问题 基于spring3的单元测试 ...

  6. Unity WP8开发环境

    Unity WP8开发环境   VS2012旗舰版: 安装WP SDK8.0出错提示: 根据当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内 解决办法: 方法一:把操作系统的时间日期调整到 ...

  7. 算法笔记_039:杨辉三角形(Java)

    目录 1 问题描述 2 解决方案 1 问题描述 问题描述 杨辉三角形又称Pascal三角形,它的第i+1行是(a+b)i的展开式的系数. 它的一个重要性质是:三角形中的每个数字等于它两肩上的数字相加. ...

  8. Ubuntu14.04怎样使用root登录

    1.打开终端 2.sudo gedit /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf 3.在弹出的编辑框里输入:greeter-show-manua ...

  9. [ASP.NET]使用uploadify上传图片,并在uploadify按钮上生成预览图

    目录 需求 主要代码 总结 需求 项目中有用到uploadify上传插件,给的原型就是上传成功后替换原来的图片.没办法需求在那儿,也不能修改需求吧,只能想办法解决问题了. 主要代码 修改uploadi ...

  10. 何时应该使用Directive、Controller、Service?

    AngularJS:何时应该使用Directive.Controller.Service? 大漠穷秋 译 AngularJS是一款非常强大的前端MVC框架.同时,它也引入了相当多的概念,这些概念我们可 ...