迁移到Spring5.3

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

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

<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);
    }

}

谢谢你的意见谢谢

暂无答案!

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

相关问题