Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did something similar (thanks axtavt): </p> <pre><code>public class AjaxAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication auth) throws IOException, ServletException { if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) { response.getWriter().print( "{success:true, targetUrl : \'" + this.getTargetUrlParameter() + "\'}"); response.getWriter().flush(); } else { super.onAuthenticationSuccess(request, response, auth); } }} </code></pre> <p>I chose to extend the simple success handler for the default behavior on non-Ajax requests. Here's the XML to make it work:</p> <pre><code>&lt;http auto-config="false" use-expressions="true" entry-point-ref="authenticationProcessingFilterEntryPoint"&gt; &lt;custom-filter position="FORM_LOGIN_FILTER" ref="authenticationFilter" /&gt; ... ... &lt;/http&gt; &lt;beans:bean id="authenticationProcessingFilterEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"&gt; &lt;beans:property name="loginFormUrl" value="/index.do" /&gt; &lt;beans:property name="forceHttps" value="false" /&gt; &lt;/beans:bean&gt; &lt;beans:bean id="authenticationFilter" class= "org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"&gt; &lt;beans:property name="authenticationManager" ref="authenticationManager"/&gt; &lt;beans:property name="filterProcessesUrl" value="/j_spring_security_check"/&gt; &lt;beans:property name="sessionAuthenticationStrategy" ref="sas" /&gt; &lt;beans:property name="authenticationFailureHandler" ref="failureHandler"/&gt; &lt;beans:property name="authenticationSuccessHandler" ref="successHandler"/&gt; &lt;/beans:bean&gt; &lt;beans:bean id="successHandler" class="foo.AjaxAuthenticationSuccessHandler"&gt; &lt;beans:property name="defaultTargetUrl" value="/login.html"/&gt; &lt;/beans:bean&gt; &lt;beans:bean id="failureHandler" class="foo.AjaxAuthenticationFailureHandler" /&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload