@Override
 public void onApplicationEvent(final AuthenticationSuccessEvent e) {
   final WebAuthenticationDetails auth =
       (WebAuthenticationDetails) e.getAuthentication().getDetails();
   if (auth != null) {
     loginAttemptService.loginSucceeded(auth.getRemoteAddress());
   }
 }
  @Override
  public void onApplicationEvent(AuthenticationSuccessEvent event) {
    Authentication authentication = event.getAuthentication();
    Object principal = authentication.getPrincipal();
    if (principal instanceof CustomUserDetails) {
      Serializable id = ((CustomUserDetails<?, ?>) principal).getId();
      User user = userService.findOne((Long) id);
      user.setLastLoginDate(new Date());

      WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails();
      user.setLastLoginIp(details.getRemoteAddress());
      userService.update(user);
    }
  }
  @Override
  public void onApplicationEvent(AuthenticationSuccessEvent event) {
    Authentication authentication = event.getAuthentication();
    Object principal = authentication.getPrincipal();
    if (principal instanceof CustomUserDetails) {
      @SuppressWarnings("unchecked")
      UserEntity userEntity = ((CustomUserDetails<?, UserEntity>) principal).getCustomUser();
      userEntity.setLastLoginDate(new Date());

      WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails();
      userEntity.setLastLoginIp(details.getRemoteAddress());
      userEntityService.save(userEntity);
    }
  }
  public void onApplicationEvent(ApplicationEvent e) {
    if (e instanceof AuthenticationSuccessEvent) {
      // 登录成功后的事件处理
      AuthenticationSuccessEvent event = (AuthenticationSuccessEvent) e;
      Authentication authentication = event.getAuthentication();

      loginUser(authentication);
    } else if (e instanceof HttpSessionCreatedEvent) {
      HttpSession session = ((HttpSessionCreatedEvent) e).getSession();

      OnLineInfo onlineInfo = onLineManager.getOnlineUser(session.getId());
      if (onlineInfo == null) return;

      Person person = onlineInfo.getPerson();
      String username = person.getUsername();
      //
      //			//把当前登录用户的CSS主题写入Session中
      //			String cssTheme = settingManager.getPersonSettingValue(username, MyConstants.CSS_THEME);
      //			if (cssTheme == null)
      //				cssTheme = "";
      //
      //			session.setAttribute(MyConstants.CSS_THEME, cssTheme);
      //
      //			//把当前登录用户的在线消息定时接收时间间隔写入Session中
      //			int messageCheckInterval = settingManager.getPersonSettingIntValue(username,
      // MyConstants.MESSAGE_CHECK_INTERVAL);
      //			session.setAttribute(MyConstants.MESSAGE_CHECK_INTERVAL, messageCheckInterval);
      //
      //			//把当前登录用户的电子邮件定时接收时间间隔写入Session中
      //			int mailCheckInterval = settingManager.getPersonSettingIntValue(username,
      // MyConstants.MAIL_CHECK_INTERVAL);
      //			session.setAttribute(MyConstants.MAIL_CHECK_INTERVAL, mailCheckInterval);
    } else if (e instanceof HttpSessionDestroyedEvent) {
      SecurityContext securityContext = ((HttpSessionDestroyedEvent) e).getSecurityContext();
      if (securityContext == null) return;

      Authentication authentication = securityContext.getAuthentication();
      if (authentication == null) return;

      if (authentication.getDetails() instanceof WebAuthenticationDetails) {
        WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails();
        String sessionId = details.getSessionId();

        logoutUser(sessionId);
      }
    }
  }