2016-06-04 11 views
7

मेरे पास नीचे दिखाए गए कॉन्फ़िगरेशन फ़ाइलों के साथ एक वसंत अनुप्रयोग है। सभी कॉन्फ़िगरेशन सही लगते हैं लेकिन डिबगिंग करते समय मैंने पाया कि प्रारंभिक वसंत के दौरान वसंत फ़िल्टरसेक्योरिटी इंटरसेप्टर के लिए दो बीन्स बनाता है बिना किसी इंटरसेप्ट-यूआरएल नियमों और दूसरे नियमों के साथ। जब कोई अनुरोध आता है, तो यह फ़िल्टरसेक्योरिटीइंटरसेप्टर बीन का उपयोग करता है जिसमें बिना अवरोध-यूआरएल नियम होते हैं। तो मुझे निम्न लॉग दिखाई देता है:फ़िल्टर के साथ स्प्रिंग फ़िल्टरChainProxySecurityInterceptor सही ढंग से काम नहीं कर रहा है?

DEBUG FilterSecurityInterceptor:183 - Public object - authentication not attempted 

लेकिन अनुरोध यूआरएल अवरोध यूआरएल नियम के तहत आता है। मैंने डीबग किया और पाया कि ऐसा इसलिए है क्योंकि बीन का इस्तेमाल httpMethodMapDefaultFilterInvocationSecurityMetadataSource में कोई अवरोध नियम नहीं था। मुझे यकीन नहीं है कि यहां क्या गलत है।

नीचे applicationContext-security.xml है:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:security="http://www.springframework.org/schema/security" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
         http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd" 
    default-init-method="init"> 

    <security:authentication-manager alias="authenticationManager"> 
     <security:authentication-provider 
      user-service-ref="userDetailService"> 
     </security:authentication-provider> 
    </security:authentication-manager> 

    <alias name="filterChainProxy" alias="springSecurityFilterChain" /> 

    <bean id="accessDecisionManager" 
     class="org.springframework.security.access.vote.AffirmativeBased"> 
     <property name="decisionVoters"> 
      <list> 
       <bean class="org.springframework.security.access.vote.RoleVoter" /> 
       <bean class="org.springframework.security.access.vote.AuthenticatedVoter" /> 
      </list> 
     </property> 
    </bean> 

    <bean id="consoleAuthenticationSuccessHandler" 
     class="custom_class"> 
     <property name="defaultTargetUrl" value="/loginSuccess.htm" /> 
     <property name="targetUrlParameter" value="targetURL" /> 
    </bean> 

    <bean id="consoleAuthenticationFailureHandler" 
     class="custom_class"> 
     <property name="loginFailureUrl" value="/loginFailure.htm" /> 
    </bean> 

    <bean id="consoleLogoutSuccessHandler" 
     class="custom_class"> 
     <property name="logoutUrl" value="/loggedout.htm" /> 
    </bean> 

    <bean id="userDetailService" 
     class="custom_class"> 
    </bean> 

    <security:http auto-config="true" 
     security-context-repository-ref="securityContextRepository"> 
     <security:form-login authentication-failure-url="/loginFailure.htm" 
      default-target-url="/loginSuccess.htm" 
      authentication-success-handler-ref="consoleAuthenticationSuccessHandler" /> 
     <security:logout success-handler-ref="consoleLogoutSuccessHandler" /> 
     <security:anonymous enabled="false" /> 
     <security:session-management 
      session-fixation-protection="none" /> 
    </security:http> 

    <bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy"> 
     <security:filter-chain-map path-type="ant"> 
      <security:filter-chain pattern="/login.htm*" 
       filters="none" /> 
      <security:filter-chain pattern="/**" 
       filters="securityContextFilter, logoutFilter, formLoginFilter, servletApiFilter, exceptionTranslator, filterSecurityInterceptor" /> 
     </security:filter-chain-map> 
    </bean> 

    <bean id="securityContextRepository" 
     class="org.springframework.security.web.context.HttpSessionSecurityContextRepository" /> 

    <bean id="securityContextFilter" 
     class="org.springframework.security.web.context.SecurityContextPersistenceFilter"> 
     <property name="securityContextRepository" ref="securityContextRepository" /> 
    </bean> 
    <bean id="logoutFilter" 
     class="org.springframework.security.web.authentication.logout.LogoutFilter"> 
     <constructor-arg ref="consoleLogoutSuccessHandler" 
      index="0" 
      type="org.springframework.security.web.authentication.logout.LogoutSuccessHandler" /> 
     <constructor-arg> 
      <list> 
       <bean 
        class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler" /> 
      </list> 
     </constructor-arg> 
    </bean> 

    <bean id="servletApiFilter" 
     class="org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter" /> 

    <bean id="exceptionTranslator" 
     class="org.springframework.security.web.access.ExceptionTranslationFilter"> 
     <property name="authenticationEntryPoint"> 
      <bean 
       class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> 
       <property name="loginFormUrl" value="/login.jsp" /> 
      </bean> 
     </property> 
    </bean> 

    <bean id="formLoginFilter" 
     class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
     <property name="authenticationManager" ref="authenticationManager" /> 
     <property name="authenticationSuccessHandler" ref="consoleAuthenticationSuccessHandler" /> 
     <property name="authenticationFailureHandler" ref="consoleAuthenticationFailureHandler" /> 
    </bean> 

    <bean id="filterSecurityInterceptor" 
     class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"> 
     <property name="securityMetadataSource"> 
      <security:filter-security-metadata-source> 
       <security:intercept-url pattern="/login.htm*" 
        access="ROLE_ANONYMOUS" /> 
       <security:intercept-url pattern="/**" 
        access="ROLE_USER,ROLE_ADMIN" /> 
      </security:filter-security-metadata-source> 
     </property> 
     <property name="accessDecisionManager" ref="accessDecisionManager" /> 
     <property name="authenticationManager" ref="authenticationManager" /> 
    </bean> 

</beans> 

यहाँ किसी भी मदद की सराहना।

उत्तर

6

आपके पास कॉन्फ़िगरेशन में <security:http> तत्व है।

38.1.2 <http>
प्रत्येक <http> नाम स्थान ब्लॉक हमेशा बनाता है एक SecurityContextPersistenceFilter, एक ExceptionTranslationFilter और एक FilterSecurityInterceptor: प्रलेखन से। ये तय हैं और विकल्पों के साथ प्रतिस्थापित नहीं किया जा सकता है।

तो आपके <bean id="filterSecurityInterceptor"> को अनदेखा किया गया है।

<bean id="filterSecurityInterceptor" 
    class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"> 
    <property name="securityMetadataSource"> 
     <security:filter-security-metadata-source> 
      <security:intercept-url pattern="/login.htm*" 
       access="ROLE_ANONYMOUS" /> 
      <security:intercept-url pattern="/**" 
       access="ROLE_USER,ROLE_ADMIN" /> 
     </security:filter-security-metadata-source> 
    </property> 
    <property name="accessDecisionManager" ref="accessDecisionManager" /> 
    <property name="authenticationManager" ref="authenticationManager" /> 
</bean> 

के बजाय आप <security:http> बदलना चाहिए की तरह

<security:http ... 
     authentication-manager-ref="authenticationManager"> 
    ... 
    <security:intercept-url pattern="/login.htm*" 
     access="ROLE_ANONYMOUS" /> 
    <security:intercept-url pattern="/**" 
     access="ROLE_USER,ROLE_ADMIN" /> 
</security:http> 

कुछ आप <bean id="accessDecisionManager"> जरूरत नहीं है, क्योंकि (docs से उद्धरण) "डिफ़ॉल्ट एक AffirmativeBased कार्यान्वयन एक RoleVoter साथ के लिए प्रयोग किया जाता है से शामिल करने के लिए और एक AuthenticatedVoter ", जो वास्तव में आप परिभाषित करते हैं।

इसके अलावा आपके <bean id="securityContextFilter"> को अनदेखा किया गया है, इसके बजाय आपको security-context-repository-ref="securityContextRepository" विशेषता http तत्व में जोड़नी चाहिए।
और आपके <bean id="exceptionTranslator"> को अनदेखा किया गया है, मुझे यकीन नहीं है कि इसे ठीक से कैसे बदला जाए।

और आप मैन्युअल रूप से org.springframework.security बीन्स को परिभाषित करते हैं। मुझे संदेह है कि उनमें से अधिकतर अनावश्यक (डिफ़ॉल्ट रूप से परिभाषित) हैं, या कच्चे वसंत bean एस के बजाय security: नामस्थान के विशेष तत्वों का उपयोग करके परिभाषित किया जाना चाहिए।

संबंधित मुद्दे