springmvc+shiro认证框架配置
1,在web.xml中配置fiter,如下所示
<!-- shiro的filter -->
<!-- shiro过虑器,DelegatingFilterProxy通过代理模式将spring容器中的bean和filter关联起来 -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<!-- 设置true由servlet容器控制filter的生命周期 -->
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
<!-- 设置spring容器filter的bean id,如果不设置则找与filter-name一致的bean-->
<init-param>
<param-name>targetBeanName</param-name>
<param-value>shiroFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2,上面配置了shiroFilter,那么在spring-shiro.xml中要配置shirofilter bean
<!-- web.xml中shiro的filter对应的bean -->
<!-- Shiro 的Web过滤器 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<!-- loginUrl认证提交地址,如果没有认证将会请求此地址进行认证,请求此地址将由formAuthenticationFilter进行表单认证 -->
<property name="loginUrl" value="/login" />
<!-- 认证成功统一跳转到first.action,建议不配置,shiro认证成功自动到上一个请求路径 -->
<!--<property name="successUrl" value="/index.jsp"/>-->
<!-- 通过unauthorizedUrl指定没有权限操作时跳转页面-->
<!--<property name="unauthorizedUrl" value="/sysPer/noperm" />-->
<!--自定义filter配置 -->
<!--<property name="filters">-->
<!--<map>-->
<!-- 将自定义 的FormAuthenticationFilter注入shiroFilter中-->
<!--<entry key="authc" value-ref="formAuthenticationFilter" />-->
<!--</map>-->
<!--</property>--> <!-- 过虑器链定义,从上向下顺序执行,一般将/** 放在最下边 -->
<property name="filterChainDefinitions">
<value>
<!-- 对静态资源设置匿名访问 -->
/styles/easyui/** = anon
/scripts/easyui/** = anon
/styles/** = anon
/images/** = anon
<!-- 请求 logout地址,shiro去清除session-->
/logout = logout
<!--商品查询需要商品查询权限 ,取消url拦截配置,使用注解授权方式 -->
<!-- /items/queryItems.action = perms[item:query] -->
<!--/sysuser/deleteUser = perms[user:delete]-->
<!-- 配置记住我或认证通过可以访问的地址 -->
<!--/index.jsp = user-->
<!-- /** = authc 所有url都必须认证通过才可以访问-->
/login = anon
/** = authc
</value>
</property>
</bean>
3,在spring-shiro.xml中添加securityManager和自定义realm,ecacheManager的相关配置
<!-- securityManager安全管理器 -->
<!-- realm -->
<bean id="customRealm" class="com.unisits.zngkpt.framework.privilegeframe.CustomeRealm">
<!-- 将凭证匹配器设置到realm中,realm按照凭证匹配器的要求进行散列 -->
<property name="credentialsMatcher" ref="credentialsMatcher"/>
</bean>
<!-- 凭证匹配器 -->
<bean id="credentialsMatcher"
class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<property name="hashAlgorithmName" value="md5" />
<property name="hashIterations" value="" />
</bean> <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"></bean> <!-- 配额securityManager -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="customRealm" />
<!-- 注入缓存管理器 -->
<property name="cacheManager" ref="cacheManager"/>
</bean> <!-- 缓存管理器 -->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManagerConfigFile" value="classpath:shiro-ehcache.xml"/>
</bean>
3,在spring-shiro.xml中,开启shiro的注解支持
<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认证异常的页面
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.apache.shiro.authz.UnauthorizedException">/errorpage/refuse</prop>
</props>
</property>
</bean>
springmvc+shiro认证框架配置的更多相关文章
- 利用maven开发springMVC项目(二)——框架配置
申明:主要内容来源于大神博客(使用IntelliJ IDEA开发SpringMVC网站(二)框架配置),我只是用eclipse自己练习使用,记录下来也只是为了学习使用,没有任何的商业用途,侵权必删. ...
- Spring、SpringMVC、Mybaitis框架配置
给大家推荐2个网址,介绍的非常详细 SSM环境搭建 http://blog.csdn.net/zhshulin/article/details/37956105 SSM代码生成工具介绍 http:// ...
- SpringMVC整合Shiro权限框架
尊重原创:http://blog.csdn.net/donggua3694857/article/details/52157313 最近在学习Shiro,首先非常感谢开涛大神的<跟我学Shiro ...
- Shiro权限框架与SpringMVC集成
1.Shiro整合SpringMVC 我们学习Shiro框架肯定是要应用到Web项目上的,所以我们需要整合Shiro和SpringMVC 整合步骤: 第一步:SpringMVC框架的配置 spring ...
- SpringMVC下的Shiro权限框架的使用
SpringMVC+Shiro权限管理 博文目录 权限的简单描述 实例表结构及内容及POJO Shiro-pom.xml Shiro-web.xml Shiro-MyShiro-权限认证,登录认证层 ...
- shiro太复杂?快来试试这个轻量级权限认证框架!
前言 在java的世界里,有很多优秀的权限认证框架,如Apache Shiro.Spring Security 等等.这些框架背景强大,历史悠久,其生态也比较齐全. 但同时这些框架也并非十分完美,在前 ...
- Idea简单SpringMVC框架配置
前边已经介绍过了Struts在Idea上的配置,相对于Struts来说,我觉得SpringMVC有更多的优势,首先Struts是需要对action进行配置,页面发送不同的请求,就需要配置不同的acti ...
- springmvc(二) ssm框架整合的各种配置
ssm:springmvc.spring.mybatis这三个框架的整合,有耐心一步步走. --WH 一.SSM框架整合 1.1.整合思路 从底层整合起,也就是先整合mybatis与spring,然后 ...
- 使用IntelliJ IDEA开发SpringMVC网站(二)框架配置
原文:使用IntelliJ IDEA开发SpringMVC网站(二)框架配置 摘要 讲解如何配置SpringMVC框架xml,以及如何在Tomcat中运行 目录[-] 文章已针对IDEA 15做了一定 ...
随机推荐
- 30款超酷的HTTP 404页面未找到错误设计
访问网站过程中,我们最常看到的HTTP错误就是404页面未找到错误,很多网站都针对这个错误设计自己富有个性的页面,在今天这篇文章中我们就分 享30多款设计非常霸道的404错误页面,希望大家能够找到更多 ...
- 踩坑记:mysql timeStamp默认值0000-00-00 00:00:00 报错
报错现象: 从mysql5.5数据库导出的数据结构放到mysql5.7.10 报错create_time timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00 ...
- Inside GDALAllRegister之三: 注册指定驱动
现在来仔细分析如何注册一个驱动的代码,看下面代码: #ifdef FRMT_vrt GDALRegister_VRT(); #endif 编译时指定或者取消FRMT_vrt,可以控制这条语句是否编译到 ...
- 使用poll处理任意数目个客户的单进程程序
将http://www.cnblogs.com/nufangrensheng/p/3590002.html中的select改用poll. int main(int argc, char **argv) ...
- Unity Editor类常用方法
http://www.cnblogs.com/zhaoqingqing/p/3944718.html 一些比较常用的Editor功能我在之前的博客中也有提到过所以就不详细写啦,今天参考了一下 麒麟子( ...
- PHP-密码学算法及其应用-对称密码算法
转自:http://www.smatrix.org/bbs/simple/index.php?t5662.html ////////////////////////////////////////// ...
- fatal error LNK1123: 转换到 COFF 期间失败:文件无效或损坏
问题出现背景: 原本电脑里是装着VS2015的,其使用的是.NET 4.5,当再安装VS2010之后,不能与当前的.NET平台兼容.卸载VS2015时,不会恢复.NET 4.0. l 当VS2015安 ...
- EntityFramework~~~三种模式
1:database-first 2:model-first 3:code-only 此处的code-only也就是大家叫的code-first,但是正确的叫法应该是code-only
- Python title() 方法
描述 Python title() 方法返回"标题化"的字符串,就是说所有单词都是以大写开始,其余字母均为小写. 语法 title() 方法语法: S.title() 参数 无. ...
- PostgreSQL远端访问
PostgreSQL默认的理念是运行在本地地址且不允许外部访问的. 如果想通过Navicat for postgreSql这种优秀的第三方软件访问需要做出如下修改: 一.启动在外部可访问的地址上 编辑 ...