与spring整合shiro框架

本文介绍了一种基于Spring框架的Shiro权限管理系统配置方法。通过自定义Realm、配置过滤器和使用EhCache进行缓存管理,实现了灵活的权限控制方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.0.xsd">
    <description>Shiro 配置</description>
    
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!--设置自定义realm -->
<property name="realm" ref="monitorRealm" />

   <!-- 需要使用cache的话加上这句 -->
    <property name="cacheManager" ref="shiroEhcacheManager" />

</bean>


<!--自定义Realm 继承自AuthorizingRealm -->
<bean id="monitorRealm" class="org.seven.MonitorRealm.MonitorRealm"></bean>

<!-- Shiro主过滤器本身功能十分强大,其强大之处就在于它支持任何基于URL路径表达式的、自定义的过滤器的执行 --> 
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- Shiro的核心安全接口,这个属性是必须的 -->  
<property name="securityManager" ref="securityManager" />
<!-- 要求登录时的链接,非必须的属性,默认会自动寻找Web工程根目录下的"/login.jsp"页面 -->  
<property name="loginUrl" value="/" />
<!-- 用户访问未对其授权的资源时,所显示的连接 -->
<property name="unauthorizedUrl" value="/error/error.jsp" />
<property name="filterChainDefinitions">
<value>
<!-- 
Anon:不指定过滤器 
Authc:验证,这些页面必须验证后才能访问,也就是我们说的登录后才能访问。
-->
/login.action=anon
/seven/** = authc, perms[seven:select]
/list*=anon
/**=authc
</value>
</property>
</bean>


<!-- shiro的缓存管理器,然后需要将缓存管理器注入到安全管理其中  -->  
<bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">  
       <!--classpath是缓存属性的配置文件  -->  
       <property name="cacheManagerConfigFile" value="classpath:ehcache .xml" />  


</bean>


</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值