shiro 결합 springMVC 설정 관련

13721 단어 자바
웹. 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 은 아직 초기 에 나 오지 않 았 습 니 다.applicationContext 에 다음 코드 를 추가 하고 다시 스 캔 해 야 합 니 다.
  <context:component-scan base-package="cn.com.sgcc.credit.core"/>

참고:http://blog.csdn.net/cenkunjj/article/details/51078101 이 작 가 는 mvc 의 프로필 을 웹. xml 에 한 번 쓰 려 고 시도 했다.원리 가 같다

좋은 웹페이지 즐겨찾기