Shiro集成Spring时Shiro配置文件中配置

前言

本篇主要讲解Shiro集成Spring时Shiro配置什么和配置的作用。

Shiro的配置文件

1、注入自定义Realm

	
	<bean id="userRealm" class="cn.wolfcode.shiro.realm.UserRealm">
		......
	bean>

2、 配置安全管理器SecurityManager


	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		......
	bean>

3、 定义ShiroFilter

   
      

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    	  
        <property name="securityManager" ref="securityManager"/>
    	 
        <property name="loginUrl" value="/login.jsp"/>
        <property name="successUrl" value="/list.jsp"/>
        <property name="unauthorizedUrl" value="/unauthorized.jsp"/>
          
          
          
          
          
       
        <property name="filterChainDefinitionMap" ref="filterChainDefinitionMap">property>
        
        
        <property name="filterChainDefinitions">
            <value>
                /login.jsp = anon
                /shiro/login = anon
                /shiro/logout = logout
                
                /user.jsp = roles[user]
                /admin.jsp = roles[admin]
                
                
                /** = authc
            value>
        property>
    bean>
    

开启扫描注解

	
	<aop:config proxy-target-class="true">aop:config>
	
	<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
		<property name="securityManager" ref="securityManager" />
	bean>

定义缓存管理器

	
	<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
		<property name="cacheManager" ref="ehCacheManager"/>
	bean>
	
		<property name="configLocation" value="classpath:shiro-ehcache.xml" />
		<property name="shared" value="true">property>
	bean>

你可能感兴趣的:(Shiro)