spring-shrio.xml spring集成shiro配置文件(全)

<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
			http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

	<!-- 自定義Realm -->
	<bean id="userRealm" class="cn.wolfcode.shiro.realm.UserRealm">
        <property name="credentialsMatcher" ref="credentialsMatcher"></property>
		<property name="userDAO" ref="userDAOImpl"></property>
        <property name="roleDAO" ref="roleDAOImpl"></property>
        <property name="permissionDAO" ref="permissionDAOImpl"></property>
	</bean>

	<!-- 配置shiro安全管理器 -->
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<property name="realm" ref="userRealm"></property>
        <property name="cacheManager" ref="cacheManager"></property>
	</bean>
	<!-- shiro工廠bean配置 -->
	<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
		<!-- shiro的核心安全接口 -->
		<property name="securityManager" ref="securityManager"/>
		<!-- 要求登錄時的連接 -->
		<property name="loginUrl" value="/login"></property>
		<!-- 登錄成功後要跳轉的連接(此處已經在登錄中處理了) -->
		<!-- <property name="successUrl" value="/index.jsp"></property> -->
		<!-- 訪問未對其授權的資源時,要跳轉的連接-->
        <property name="unauthorizedUrl" value="/nopermission,jsp"></property>
		<!-- shiro連接約束配置 -->
		<property name="filterChainDefinitions">
			<value>
				<!-- 對靜態資源設置允許匿名訪問 -->
				/images/** = anon
				/js/** = anon
				/css/** = anon
				/static/** = anon
				/bootstrap/** = anon
				/jquery/** = anon
				<!-- 可匿名訪問路徑,例如:驗證碼、登錄連接、退出連接等 -->
				/login.do = anon
				<!-- 退出 -->
				/logout.do = logout  <!-- 會調用Subject的logout方法,此方法會將session清空 -->
				<!-- 剩餘其他路徑,必須認證通過纔可以訪問 -->
				/** = authc
			</value>
		</property>
	</bean>


    <!--開啓aop-->
    <aop:config proxy-target-class="true"></aop:config>
    <!--開啓shiro註解支持-->
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager"></property>
    </bean>


    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="org.apache.shiro.authz.UnauthorizedException">redirect:/nopermission.jsp</prop>
            </props>
        </property>
    </bean>




    <!--緩存管理器-->
    <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <property name="cacheManager" ref="ehCacheManager"></property>
    </bean>
    <bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:shiro-ehcache.xml"></property>
        <property name="shared" value="true"></property>
    </bean>


    <!--加密器-->
    <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
        <!--加密算法-->
        <property name="hashAlgorithmName" value="md5"></property>
        <property name="hashIterations" value="3"></property>
    </bean>
</beans>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章