2011-06-21 21 views
0

私はSpring Security 3を使用してユーザーを認証しています。私はユーザーが資格情報を入力できるようにポップアップでフォームを使用しています。私はAjaxを使ってログインを処理しています。ログインのプロセスはうまくいくが、私の設定で指定された成功/失敗ハンドラにリダイレクトするSpring Securityを取得することはできない。代わりに、常にサイトのホームページ(home.do)を返します。私はSpring Securityがユーザーを正しく認証していることを知っています。なぜなら、ページをリロードすると、ユーザーが認証されていないと隠されているリンクが存在するからです。Spring Security 3 - AuthenticationSuccessHandler/FailureHandlerが動作しない

これはなぜ起こっているのですか?私の設定は以下の通りです。それ以上の情報が必要な場合は教えてください。 XHRが戻ってリダイレクトを取得し、それに従っている

認証-config.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<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.0.xsd 
       http://www.springframework.org/schema/security 
       http://www.springframework.org/schema/security/spring-security-3.0.3.xsd"> 

    <bean id="customUserDetailsService" class="com.mydomain.services.AuthenticationService"> 
     <property name="userDAO"> 
      <bean class="com.mydomain.dao.UserDAOImpl" /> 
     </property> 
    </bean> 

    <security:http auto-config='true' use-expressions="true"> 
     <security:http-basic /> 
     <security:logout logout-url="/logout" 
      logout-success-url="/home.do" /> 
     <security:session-management 
      invalid-session-url="/sessionTimeout.htm" /> 
    </security:http> 

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

    <bean id="authenticationFilter" 
     class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
     <property name="filterProcessesUrl" value="/j_spring_security_check" /> 
     <property name="authenticationManager" ref="authenticationManager" /> 
     <property name="authenticationFailureHandler" ref="failureHandler" /> 
     <property name="authenticationSuccessHandler" ref="successHandler" /> 
    </bean> 

    <bean id="successHandler" 
     class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> 
      <property name="alwaysUseDefaultTargetUrl" value="false"/> 
     <property name="defaultTargetUrl" value="/loginSuccess.do" /> 
    </bean> 

    <bean id="failureHandler" 
     class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
     <property name="defaultFailureUrl" value="/login.jsp" /> 
    </bean> 
</beans> 

web.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    version="2.5"> 
    <display-name>MyWebApp</display-name> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      classpath:services-config.xml 
      classpath:authentication-config.xml 
     </param-value> 
    </context-param> 
    <welcome-file-list> 
     <welcome-file>home.do</welcome-file> 
    </welcome-file-list> 
    <servlet> 
     <servlet-name>myServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>myServlet</servlet-name> 
     <url-pattern>*.do</url-pattern> 
    </servlet-mapping> 
    <servlet> 
     <servlet-name>Resource Servlet</servlet-name> 
     <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class> 
    </servlet> 
    <!-- Map all /resources requests to the Resource Servlet for handling --> 
    <servlet-mapping> 
     <servlet-name>Resource Servlet</servlet-name> 
     <url-pattern>/resources/*</url-pattern> 
    </servlet-mapping> 

    <!-- security configuration --> 
    <filter> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <!-- end of security configuration --> 

</web-app> 

答えて

0

次の作業の例については、this questionの回答を参照してください。

+0

ご返信ありがとうございます。私はそれが何が起こっているのか分からない。返されるデータは、home.doのテキスト全体です(私はhome.doにもいません...私は内側のページからログインしています)。また、レスポンスコードは200であり、あなたが提案した投稿に記載されているものは1つもありません。さらに、フォームのログインを試してみましたが、ログインはもう一度成功しましたが、私はちょうどhome.doに戻ってきました。ブラウザに任せてもリダイレクトは起こりません。当然、私は間違っている可能性があります...それは前に起こった! – threejeez

関連する問題