पदावनत निरंतर के प्रलेखन वास्तव में आपको बताता है कि क्या करना चाहिए:
/**
* @deprecated If you want to retain the username, cache it in a customized {@code AuthenticationFailureHandler}
*/
@Deprecated
public static final String SPRING_SECURITY_LAST_USERNAME_KEY =
"SPRING_SECURITY_LAST_USERNAME";
कुछ इस तरह:
public class UserNameCachingAuthenticationFailureHandler
extends SimpleUrlAuthenticationFailureHandler {
public static final String LAST_USERNAME_KEY = "LAST_USERNAME";
@Autowired
private UsernamePasswordAuthenticationFilter usernamePasswordAuthenticationFilter;
@Override
public void onAuthenticationFailure(
HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception)
throws IOException, ServletException {
super.onAuthenticationFailure(request, response, exception);
String usernameParameter =
usernamePasswordAuthenticationFilter.getUsernameParameter();
String lastUserName = request.getParameter(usernameParameter);
HttpSession session = request.getSession(false);
if (session != null || isAllowSessionCreation()) {
request.getSession().setAttribute(LAST_USERNAME_KEY, lastUserName);
}
}
}
अपनी सुरक्षा config में:
<security:http ...>
...
<security:form-login
authentication-failure-handler-ref="userNameCachingAuthenticationFailureHandler"
...
/>
</security:http>
<bean
id="userNameCachingAuthenticationFailureHandler"
class="so.UserNameCachingAuthenticationFailureHandler">
<property name="defaultFailureUrl" value="/url/to/login?error=true"/>
</bean>
अपनी प्रवेश में .jsp:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="true" %>
...
<%--in the login form definition--%>
<input id="j_username" name="j_username" type="text"
value="<c:out value="${sessionScope.LAST_USERNAME}"/>"/>
आपको बहुत बहुत धन्यवाद! यह आवश्यक की तरह काम करता है! – droidpl
कोई समस्या नहीं है। ध्यान दें कि कुछ बिंदुओं पर सुधार के लिए जगह है। जैसे .jsp में सत्र विशेषता का नाम हार्ड कोडिंग सुरुचिपूर्ण नहीं है। आदर्श रूप से इसे 'UserNameCachingAuthenticationFailureHandler' में निरंतर परिभाषित किया जाना चाहिए। (मुझे यह स्वीकार करना है कि मुझे नहीं पता कि इस संकेत को कैसे प्राप्त किया जाए।) – zagyi
मुझे नहीं पता था कि यह हासिल किया जा सकता है! लेकिन अभी के लिए मुझे बस इतना ही चाहिए, यह सुरक्षा ठीक से नहीं बल्कि उपयोगकर्ता के जीवन को बेहतर बनाने के लिए एक छोटी सी चाल है! यह अविश्वसनीय है कि मुझे इस तरह कहीं और आसान समाधान नहीं मिला! ;) – droidpl