2011-10-05 8 views
6

के बिना वसंत सुरक्षा को कॉन्फ़िगर करने के बाद नहीं मिला है। मैं फ़िल्टरशैनप्रोक्सी का उपयोग कर HTTP नेमस्पेस से स्प्रिंग सुरक्षा कॉन्फ़िगरेशन को सीधे कॉन्फ़िगरेशन में परिवर्तित करने का प्रयास कर रहा हूं। रूपांतरण से पहले, HTTP नामस्थान के साथ सबकुछ ठीक था। लेकिन फ़िल्टरChainProxy के साथ कई तत्वों द्वारा तत्व को प्रतिस्थापित करने के बाद, सिस्टम में लॉगिन करते समय मुझे "j_spring_security_check नहीं मिला" त्रुटि मिली। मैंने "/ j_spring_security_check" के सभी या कुछ// app_ j_spring_security_check "को बदलने की कोशिश की लेकिन अभी भी सफलतापूर्वक लॉगिन नहीं कर सका।"j_spring_security_check" सीधे http ऑटो कॉन्फ़िगरेशन

मेरे पर्यावरण: AppFuse 2.1 स्प्रिंग MVC, iBatis, स्प्रिंग सुरक्षा 3.0.7, tuckey urlrewrite 3.2.0, स्प्रिंग 3.0.6 विंडोज 7 JDK 1.5.0_17 Maven 2.2.1 अपाचे-tomcat- साथ 6.0.32

Security.xml (रूपांतरण से पहले, सब कुछ ठीक है।)

… 
<http auto-config="true" lowercase-comparisons="false"> 
    <intercept-url pattern="/images/**" filters="none"/> 
    <intercept-url pattern="/styles/**" filters="none"/> 
    <intercept-url pattern="/scripts/**" filters="none"/> 
    <intercept-url pattern="/app/admin/**" access="ROLE_ADMIN"/> 
    <intercept-url pattern="/app/passwordHint*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> 
    <intercept-url pattern="/app/signup*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> 
    <intercept-url pattern="/app/**" access="ROLE_ADMIN,ROLE_USER"/> 
    <form-login login-page="/login" authentication-failure-url="/login?error=true" 
       login-processing-url="/j_spring_security_check"/> 
    <remember-me user-service-ref="userDao" key="e37f4b31-0c45-11dd-bd0b-0800200c9a66"/> 
</http> 
<authentication-manager alias="authenticationManager"> 
    <authentication-provider user-service-ref="userDao"> 
     <password-encoder ref="passwordEncoder"/> 
    </authentication-provider> 
</authentication-manager> 
… 

Security.xml (http नाम स्थान बदलने के बाद, "j_spring_security_ जाँच "नहीं मिला)

<beans:bean id="springSecurityFilterChain" 
      class="org.springframework.security.web.FilterChainProxy"> 
    <filter-chain-map path-type="ant"> 
     <filter-chain pattern="/images/**" filters="none"/> 
     <filter-chain pattern="/styles/**" filters="none"/> 
     <filter-chain pattern="/scripts/**" filters="none"/> 
     <filter-chain pattern="/app/**" filters=" 
      securityContextPersistenceFilter, 
      authenticationProcessingFilter, 
      exceptionTranslationFilter, 
     filterSecurityInterceptor"/> 
    </filter-chain-map> 
</beans:bean> 

<beans:bean id="securityContextPersistenceFilter" 
      class="org.springframework.security.web.context.SecurityContextPersistenceFilter"> 
</beans:bean> 
<beans:bean id="authenticationProcessingFilter" 
      class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
    <beans:property name="authenticationManager" ref="authenticationManager"/> 
    <beans:property name="authenticationSuccessHandler" ref="authenticationSuccessHandler"/> 
    <beans:property name="authenticationFailureHandler" ref="authenticationFailureHandler"/> 
    <beans:property name="filterProcessesUrl" value="/j_spring_security_check"/> 
</beans:bean> 
<beans:bean id="authenticationSuccessHandler" 
      class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler"> 
    <beans:property name="defaultTargetUrl" value="/mainMenu"/> 
</beans:bean> 
<beans:bean id="authenticationFailureHandler" 
      class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
    <beans:property name="defaultFailureUrl" value="/login.jsp"/> 
</beans:bean> 
<beans:bean id="exceptionTranslationFilter" 
      class="org.springframework.security.web.access.ExceptionTranslationFilter"> 
    <beans:property name="authenticationEntryPoint" ref="authenticationEntryPoint"/> 
    <beans:property name="accessDeniedHandler" ref="accessDeniedHandler"/> 
</beans:bean> 

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

<beans:bean id="accessDeniedHandler" 
      class="org.springframework.security.web.access.AccessDeniedHandlerImpl"> 
    <beans:property name="errorPage" value="/403.jsp"/> 
</beans:bean> 


<beans:bean id="filterSecurityInterceptor" 
      class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"> 
    <beans:property name="authenticationManager" ref="authenticationManager"/> 
    <beans:property name="accessDecisionManager" ref="accessDecisionManager"/> 
    <beans:property name="securityMetadataSource"> 
     <filter-security-metadata-source> 
      <intercept-url pattern="/app/admin/**" access="ROLE_ADMIN"/> 
      <intercept-url pattern="/app/passwordHint*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> 
      <intercept-url pattern="/app/signup*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> 
      <intercept-url pattern="/app/**" access="ROLE_ADMIN,ROLE_USER"/> 
     </filter-security-metadata-source> 
    </beans:property> 
</beans:bean> 
<beans:bean id="myFilterInvocationSecurityMetadataSource" 
      class="com.tangram.ebiz.webapp.authentication.MyFilterInvocationSecurityMetadataSource"> 
</beans:bean> 


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

<authentication-manager alias="authenticationManager"> 
    <authentication-provider user-service-ref="userDao"> 
     <password-encoder ref="passwordEncoder"/> 
    </authentication-provider> 
</authentication-manager> 

Login.jsp

<form method="post" id="loginForm" action="<c:url value='/j_spring_security_check'/>" onsubmit="saveUsername(this);return validateForm(this)"> 
… 
     <li> 
      <label for="j_username" class="required desc"><fmt:message key="label.username"/> <span class="req">*</span></label> 
      <input type="text" class="text medium" name="j_username" id="j_username" tabindex="1" /> 
     </li> 
     <li> 
      <label for="j_password" class="required desc"><fmt:message key="label.password"/> <span class="req">*</span></label> 
      <input type="password" class="text medium" name="j_password" id="j_password" tabindex="2" /> 
     </li> 
… 
    </form> 

Urlrewrite.xml

<urlrewrite default-match-type="wildcard"> 
… 
<!-- Add rules here for anything that shouldn't be served up by Spring MVC. --> 
<rule> 
    <from>/</from> 
    <to type="redirect" last="true">mainMenu</to> 
</rule> 
<rule> 
    <from>/app/**</from> 
    <to last="true" type="redirect">%{context-path}/$1</to> 
</rule> 
<rule> 
    <from>/j_spring_security_check**</from> 
    <to last="true">/j_spring_security_check$1</to> 
</rule> 
… 

<!-- Spring MVC --> 
<rule> 
    <from>/**</from> 
    <to>/app/$1</to> 
</rule> 
<outbound-rule> 
    <from>/app/**</from> 
    <to>/$1</to> 
</outbound-rule> 
… 
</urlrewrite> 
+0

मेरे पर्यावरण: AppFuse 2.1 स्प्रिंग MVC, iBatis, स्प्रिंग सुरक्षा 3.0.7, tuckey urlrewrite 3.2.0, स्प्रिंग 3.0.6 विंडोज 7 के साथ जेडीके 1.5.0_17 मेवेन 2.2.1 –

उत्तर

9

अंत में मैं यह तय अपने आप को।

स्प्रिंग सुरक्षा नामस्थान के बिना SecurityContextPersistenceFilter की doFilter() विधि को डीबग करते समय, मैंने पाया कि संदर्भ पहले सेइनएक्स निष्पादन और संदर्भ के बाद निष्पादन निष्पादन शून्य था। लेकिन जब नामस्थान के साथ कार्यक्रम को डीबग करते हैं तो उनमें से दोनों का मूल्य बेनामी के बारे में कुछ था।

मैंने सुरक्षा में "IS_AUTHENTICATED_ANONYMOUSLY" पहुंच के साथ "/ j_spring_security_check" और "/ login" जोड़ा है मेटाडेटा स्रोत नीचे दिखाया गया है और समस्या हल हो गई थी।

<beans:property name="securityMetadataSource"> 
     <filter-security-metadata-source> 
      <intercept-url pattern="/j_spring_security_check" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 
      <intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 
      <intercept-url pattern="/app/admin/**" access="ROLE_ADMIN"/> 
      <intercept-url pattern="/app/passwordHint*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> 
      <intercept-url pattern="/app/signup*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> 
      <intercept-url pattern="/app/**" access="ROLE_ADMIN,ROLE_USER"/> 
     </filter-security-metadata-source> 
    </beans:property> 

इस ब्लॉग वास्तव में मुझे बहुत मदद की: http://blog.springsource.com/2010/03/06/behind-the-spring-security-namespace/

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