@Override
  public void onAuthenticationSuccess(
      HttpServletRequest request, HttpServletResponse response, Authentication authentication)
      throws ServletException, IOException {
    SavedRequest savedRequest = requestCache.getRequest(request, response);

    if (savedRequest == null) {
      super.onAuthenticationSuccess(request, response, authentication);

      return;
    }
    String targetUrlParameter = getTargetUrlParameter();
    if (isAlwaysUseDefaultTargetUrl()
        || (targetUrlParameter != null
            && StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
      requestCache.removeRequest(request, response);
      super.onAuthenticationSuccess(request, response, authentication);

      return;
    }

    clearAuthenticationAttributes(request);

    // Use the DefaultSavedRequest URL
    String targetUrl = savedRequest.getRedirectUrl();
    logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
    getRedirectStrategy().sendRedirect(request, response, targetUrl);
  }
  @Override
  public void initializeFromConfig(SecurityNamedServiceConfig config) throws IOException {
    super.initializeFromConfig(config);

    pathInfos = GeoServerSecurityFilterChain.FORM_LOGIN_CHAIN.split(",");

    UsernamePasswordAuthenticationFilterConfig upConfig =
        (UsernamePasswordAuthenticationFilterConfig) config;

    aep = new LoginUrlAuthenticationEntryPoint(URL_LOGIN_FORM);
    aep.setForceHttps(false);
    try {
      aep.afterPropertiesSet();
    } catch (Exception e2) {
      throw new IOException(e2);
    }

    RememberMeServices rms = securityManager.getRememberMeService();

    // add login filter
    UsernamePasswordAuthenticationFilter filter =
        new UsernamePasswordAuthenticationFilter() {
          @Override
          protected boolean requiresAuthentication(
              HttpServletRequest request, HttpServletResponse response) {

            for (String pathInfo : pathInfos) {
              if (getRequestPath(request).startsWith(pathInfo)) return true;
            }
            return false;
          }
        };

    filter.setPasswordParameter(upConfig.getPasswordParameterName());
    filter.setUsernameParameter(upConfig.getUsernameParameterName());
    filter.setAuthenticationManager(getSecurityManager());

    filter.setRememberMeServices(rms);
    GeoServerWebAuthenticationDetailsSource s = new GeoServerWebAuthenticationDetailsSource();
    filter.setAuthenticationDetailsSource(s);

    filter.setAllowSessionCreation(false);
    // filter.setFilterProcessesUrl(URL_FOR_LOGIN);

    SimpleUrlAuthenticationSuccessHandler successHandler =
        new SimpleUrlAuthenticationSuccessHandler();
    successHandler.setDefaultTargetUrl(URL_LOGIN_SUCCCESS);
    filter.setAuthenticationSuccessHandler(successHandler);

    SimpleUrlAuthenticationFailureHandler failureHandler =
        new SimpleUrlAuthenticationFailureHandler();
    // TODO, check this when using encrypting of URL parameters
    failureHandler.setDefaultFailureUrl(URL_LOGIN_FAILURE);
    filter.setAuthenticationFailureHandler(failureHandler);

    // filter.afterPropertiesSet();
    getNestedFilters().add(filter);
  }
 @Override
 public void onAuthenticationSuccess(
     HttpServletRequest request, HttpServletResponse response, Authentication authentication)
     throws IOException, ServletException {
   UserRepository repository = (UserRepository) ctx.getBean("UserRepository");
   repository.updateLastAccessed(authentication.getName());
   if (SysUtil.isAjax(request)) {
     response.setContentType("application/json;charset=UTF-8");
     response.setHeader("Cache-Control", "no-cache");
     this.objectMapper.writeValue(response.getWriter(), authentication.getPrincipal());
     super.clearAuthenticationAttributes(request);
   } else {
     super.onAuthenticationSuccess(request, response, authentication);
   }
 }
 @Override
 public void onAuthenticationSuccess(
     HttpServletRequest request, HttpServletResponse response, Authentication auth)
     throws IOException, ServletException {
   if ("application/json".equals(request.getHeader("Content-Type"))) {
     response.getWriter().print("{\"responseCode\":\"SUCCESS\"}");
     response.getWriter().flush();
   } else {
     super.onAuthenticationSuccess(request, response, auth);
   }
 }
  @Override
  public void onAuthenticationSuccess(
      HttpServletRequest request, HttpServletResponse response, Authentication auth)
      throws IOException, ServletException {

    Usuario usuario = usuarioDAO.findByLogin(auth.getName());

    request.getSession().setAttribute("USUARIO_AUTENTICADO", usuario);

    this.setDefaultTargetUrl("/com/atencion");

    super.onAuthenticationSuccess(request, response, auth);
  }
  @Override
  @Transactional
  public void onAuthenticationSuccess(
      HttpServletRequest request, HttpServletResponse response, Authentication authentication)
      throws IOException, ServletException {
    // 登录成功:记录登录IP, 日期, 清除登录失败次数
    String loginIp = ((WebAuthenticationDetails) authentication.getDetails()).getRemoteAddress();
    User user = (User) authentication.getPrincipal();
    user.setLoginIp(loginIp);
    user.setLoginDate(new Date());
    user.setLoginFailureCount(0);
    userService.update(user);

    super.onAuthenticationSuccess(
        request,
        response,
        authentication); // To change body of overridden methods use File | Settings | File
                         // Templates.
  }