applicationContext-shiro.xml 2.4 KB
Newer Older
C
Calvin 已提交
1
<?xml version="1.0" encoding="UTF-8"?>
C
Calvin 已提交
2
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"
C
Calvin 已提交
4 5 6 7
	default-lazy-init="true">

	<description>Shiro安全配置</description>

8 9
	<!-- Shiro's main business-tier object for web-enabled applications -->
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager" depends-on="userJpaDao">
C
Calvin 已提交
10
		<property name="realm" ref="shiroDbRealm" />
11
		<property name="cacheManager" ref="shiroCacheManager" />
C
Calvin 已提交
12 13
	</bean>

14
	<!-- 項目自定义的Realm -->
15 16
	<bean id="shiroDbRealm" class="org.springside.examples.showcase.security.ShiroDbRealm">
		<property name="accountManager" ref="accountManager"/>
17
		<!-- 可配置cache token<->认证信息的cache,用于REST等需要频繁认证的场景 -->
18
		<property name="authorizationCachingEnabled" value="true"/>
19
	</bean>
20
	
21 22
	<!-- Shiro Filter -->
	<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
C
Calvin 已提交
23
		<property name="securityManager" ref="securityManager" />
C
Calvin 已提交
24
		<property name="loginUrl" value="/login" />
C
Calvin 已提交
25 26 27
		<property name="successUrl" value="/" />
		<property name="filterChainDefinitions">
			<value>
C
Calvin 已提交
28 29 30
				/login = authc
				/logout = logout
				/common/user/update/* = user
C
Calvin 已提交
31 32 33 34 35
				/rs/users = authcBasic
			</value>
		</property>
	</bean>

C
Calvin 已提交
36
	<!-- 用户授权/认证信息Cache, 采用EhCache RMI集群 -->
37
	<bean id="shiroCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
C
Calvin 已提交
38
		<property name="cacheManager" ref="shiroEhcacheManager"/>
39
	</bean>
C
Calvin 已提交
40 41 42
	<bean id="shiroEhcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
		<property name="configLocation" value="classpath:/security/ehcache-shiro-rmi.xml" />
	</bean>	
43 44 45 46 47
	
	<!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
	<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
	
	<!-- AOP式方法级权限检查  -->
48 49 50
	<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
		<property name="proxyTargetClass" value="true" />
	</bean>
51 52 53
	<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
    	<property name="securityManager" ref="securityManager"/>
	</bean>
C
Calvin 已提交
54
</beans>