Hi,
I am using Spring security in a relatively simple web application. On unsuccessful authentication, I'd like to pre-populate the username field.
I'm able to achieve this is if I allow session creation, however I'd like to do it without creating extra sessions. I'm able to show the SPRING_SECURITY_LAST_EXCEPTION without creating a session, but SPRING_SECURITY_LAST_USERNAME is only stored in the session scope.
Here is my authentication handler:
Is there any particular reason that the SPRING_SECURITY_LAST_USERNAME is only stored in session scope? The SPRING_SECURITY_LAST_EXCEPTION is stored in session or request scope depending on the useForward property, i.e. from SimpleUrlAuthenticationFailureHandler:Code:<beans:bean id="failureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> <beans:property name="allowSessionCreation" value="false"/> <beans:property name="defaultFailureUrl" value="/index.html?login_error"/> <beans:property name="useForward" value="true"/> </beans:bean>
Obviously I can extend SimpleUrlAuthenticationFailureHandler myself, I was just wondering why this isn't done automatically by spring security?Code:protected final void saveException(HttpServletRequest request, AuthenticationException exception) { if (forwardToDestination) { request.setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, exception); } else { HttpSession session = request.getSession(false); if (session != null || allowSessionCreation) { request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, exception); } } }
Thanks!


Reply With Quote