shiro结合springMVC配置相关

web.xml中:

 
    <context-param>
        <param-name>contextConfigLocationparam-name>
        <param-value>
            /WEB-INF/applicationContext.xml
            /WEB-INF/shiro-conf.xml
            /WEB-INF/context-component.xml
        param-value>
    context-param>
 
    <filter>
        <filter-name>shiroFilterfilter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxyfilter-class>
        <init-param>
            
            <param-name>targetFilterLifecycleparam-name>
            <param-value>trueparam-value>
        init-param>
    filter>

    <filter-mapping>
        <filter-name>shiroFilterfilter-name>
        
        <url-pattern>/*url-pattern>
    filter-mapping>

applicationContext.xml

   
    
    
    <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>

    
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
          depends-on="lifecycleBeanPostProcessor"/>

    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

shiro-conf.xml

   <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
        <property name="loginUrl" value="/login.do"/>
        <property name="filters">
            <map>
                <entry key="authc" value-ref="authcFilter"/>
                <entry key="user" value-ref="userFilter"/>
            map>
        property>
        <property name="filterChainDefinitions">
            <value>
                /login.do = authc
                
                
                **.do = user
            value>
        property>
    bean>
    
    <bean id="authcFilter" class="cn.com.a.credit.common.security.shiro.CredirAuthenticationFilter"/>
    <bean id="userFilter" class="cn.com.a.credit.common.security.shiro.CreditUserFilter"/>

    
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realms">
            <list>
                <ref bean="shiroDbRealm"/>
            list>
        property>
        
        <property name="rememberMeManager" ref="rememberMeManager"/>
    bean>
    
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>


    
    <bean id="shiroDbRealm" class="cn.com.a.credit.common.security.shiro.ShiroDbRealm" depends-on="userDao,operationLogDao">
        <property name="credentialsDigest" ref="credentialsDigest"/>
    bean>

    
    
    
        
    
    
    <bean id="rememberMeManager"
          class="org.apache.shiro.web.mgt.CookieRememberMeManager">
        <property name="cookie" ref="rememberMeCookie"/>
    bean>
    <bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
        <constructor-arg value="rememberMeClub"/>
        <property name="httpOnly" value="true"/>
        
        <property name="maxAge" value="25920000"/>

    bean>

注意,shiro处于filter级别,过滤的时候spring-mvc.xml中配置的bean还没有被初始出来。
需要在appliactionContext中添加如下代码,再扫描一次。

  <context:component-scan base-package="cn.com.sgcc.credit.core"/>

参考:http://blog.csdn.net/cenkunjj/article/details/51078101
这位作者尝试把 mvc的配置文件写到web.xml中一次。原理一样

你可能感兴趣的:(java)