Assuming I understood correctly, you want to break the filter chain and send an HTTP response code when the authentication is successful, regardless of how the authentication occurs; that is, it can be a login form or authentication with authentication.
So, first add the following logic to CustomSavedRequestAwareAuthenticationSuccessHandler
:
// place where applicable if (authentication != null) { response.setStatus(HttpServletResponse.SC_OK); }
Secondly, define a new filter, for example:
class HttpResponseAuthenticationFilter extends RememberMeAuthenticationFilter { protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) { super.onSuccessfulAuthentication(request, response, authResult); if (authResult != null) { response.setStatus(HttpServletResponse.SC_OK); } } }
Third, define the client file in the security:http
section as:
<custom-filter position="LAST" ref="myHttpResponseAuthFilter" />
Fourth, add a link for your success handler to your form-login
as:
<form-login ... authentication-success-handler-ref="mySuccessHandler" ... />
because it is not in your form authentication.
In addition, based on Spring Security's documentation on filter positions, it is recommended that you do not use auto-config
with custom filters.
Notice, that:
- The reason you see this behavior is because when you see the login form, it doesn't apply to mem-me services. Form processing resolved the final destination URL.
- After the first time, it will be a mem-me filter that will be authenticated and must again send an HTTP response code.
I also suggest reading this answer as it gives more information about the difference between login forms, http-basic auth and recall services in Spring Security.