#java #authentication #spring-security #migration
Вопрос:
Я переношу веб-портал в spring 5.3, и у меня возникает несколько проблем, когда дело доходит до переноса части входа в систему. Теперь я могу успешно войти в приложение, что замечательно, однако при неудачной попытке приложение отображается в поле имени пользователя AnonymousUser вместо введенной строки. Как я могу изменить это, чтобы вместо AnonymousUser я видел ввод пользователя? Моя текущая конфигурация выглядит так:
<security:form-login
login-page="/login.htm"
username-parameter="j_username"
password-parameter="j_password"
authentication-details-source-ref="authDetails"
authentication-failure-handler-ref="customFailureHandler"
authentication-success-handler-ref="customSuccessHandler"
login-processing-url="/loginAction.htm" />
<!-- Custom failure handler -->
<bean id="customFailureHandler" class="com.security.AuthenticationFailureHandler">
<property name="defaultFailureUrl" value="/login.htm" />
</bean>
public class AuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
protected String defaultFailureUrl;
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
String failUrl = request.getParameter ("failUrl");
if (StringUtils.isEmpty (failUrl)) {
failUrl = AuthenticationProcessingEntryPoint.resolveReturnPath (request, defaultFailureUrl);
}
if (!StringUtils.isEmpty (failUrl)) {
// Save exceptions.
saveExceptionToSession (request, exception);
// Forward through to the URL.
if (isUseForward ()) {
request.getRequestDispatcher (failUrl).forward (request, response);
} else {
getRedirectStrategy ().sendRedirect (request, response, failUrl);
}
} else {
super.onAuthenticationFailure (request, response, exception);
}
}
protected final void saveExceptionToSession(HttpServletRequest request, AuthenticationException exception) {
HttpSession session = request.getSession (false);
if (session != null || isAllowSessionCreation ()) {
request.getSession ().setAttribute (WebAttributes.AUTHENTICATION_EXCEPTION, exception);
}
}
@Override
public void setDefaultFailureUrl(String defaultFailureUrl) {
this.defaultFailureUrl = defaultFailureUrl;
super.setDefaultFailureUrl (defaultFailureUrl);
}
}
ценю любой вклад, спасибо