kaldırılmış sabiti dokümantasyonu yapmanız gereken de söyler: Böyle
/**
* @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";
şey:
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);
}
}
}
güvenlik konfigürasyonunda:
<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>
Giriş bilginiz olarak .jsp:
Grayl Spring güvenliğinde bu soruna neden olan biri buraya gelirse
<%@ 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}"/>"/>
Çok teşekkür ederim! Gerektiği gibi çalışıyor! – droidpl
Sorun değil. Bazı noktalarda iyileştirme alanı olduğunu unutmayın. Örneğin. oturum özniteliğinin ismini .jsp'de kodlamak zarif değildir. İdeal olarak, "KullanıcıAdıKeklemeAuthenticationFailureHandler" içinde tanımlanan sabite başvurmalıdır. (Bu yüklemeyi nasıl yapacağımı bilmiyorum.) – zagyi
Bunun başarılacağını bilmiyordum! Ama şimdilik tek ihtiyacım olan bu güvenlik değil, kullanıcı hayatını daha iyi hale getirmek için küçük bir hile! Her yerde böyle basit bir çözüm bulamadığım için inanılmaz! ;) – droidpl