迁移到Spring5.3

fcwjkofz  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(230)

我正在将web门户迁移到Spring5.3,在迁移登录部分时遇到了一些问题。现在我能够成功地登录到应用程序,这是伟大的,但是当有不成功的尝试,应用程序显示在用户名字段中的匿名用户,而不是字符串输入,我如何才能改变,这样,而不是匿名用户,我会看到用户输入?我当前的配置如下:

  1. <security:form-login
  2. login-page="/login.htm"
  3. username-parameter="j_username"
  4. password-parameter="j_password"
  5. authentication-details-source-ref="authDetails"
  6. authentication-failure-handler-ref="customFailureHandler"
  7. authentication-success-handler-ref="customSuccessHandler"
  8. login-processing-url="/loginAction.htm" />
  9. <!-- Custom failure handler -->
  10. <bean id="customFailureHandler" class="com.security.AuthenticationFailureHandler">
  11. <property name="defaultFailureUrl" value="/login.htm" />
  12. </bean>
  13. public class AuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
  14. protected String defaultFailureUrl;
  15. @Override
  16. public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
  17. String failUrl = request.getParameter ("failUrl");
  18. if (StringUtils.isEmpty (failUrl)) {
  19. failUrl = AuthenticationProcessingEntryPoint.resolveReturnPath (request, defaultFailureUrl);
  20. }
  21. if (!StringUtils.isEmpty (failUrl)) {
  22. // Save exceptions.
  23. saveExceptionToSession (request, exception);
  24. // Forward through to the URL.
  25. if (isUseForward ()) {
  26. request.getRequestDispatcher (failUrl).forward (request, response);
  27. } else {
  28. getRedirectStrategy ().sendRedirect (request, response, failUrl);
  29. }
  30. } else {
  31. super.onAuthenticationFailure (request, response, exception);
  32. }
  33. }
  34. protected final void saveExceptionToSession(HttpServletRequest request, AuthenticationException exception) {
  35. HttpSession session = request.getSession (false);
  36. if (session != null || isAllowSessionCreation ()) {
  37. request.getSession ().setAttribute (WebAttributes.AUTHENTICATION_EXCEPTION, exception);
  38. }
  39. }
  40. @Override
  41. public void setDefaultFailureUrl(String defaultFailureUrl) {
  42. this.defaultFailureUrl = defaultFailureUrl;
  43. super.setDefaultFailureUrl (defaultFailureUrl);
  44. }
  45. }

谢谢你的意见谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题