}
@Override
public void attributeAdded(HttpSessionBindingEvent se) {
if (se.getValue() instanceof SecurityContextImpl && loginMonitor) {
User user=UserHolder.getCurrentLoginUser();
if (null != user) {
String sessioId=se.getSession().getId();
LOG.info("用户 "+user.getUsername()+" 登录成功,会话ID:"+sessioId);
if(logs.get(user.getUsername())==null){
LOG.info("开始记录用户 "+user.getUsername()+" 的登录日志");
String ip=UserHolder.getCurrentUserLoginIp();
UserLogin userLogin=new UserLogin();
userLogin.setAppName(SystemListener.getContextPath());
userLogin.setLoginIP(ip);
userLogin.setUserAgent(se.getSession().getAttribute("userAgent").toString());
userLogin.setLoginTime(new Date());
try {
userLogin.setServerIP(InetAddress.getLocalHost().getHostAddress());
} catch (UnknownHostException e) {
LOG.error("记录登录日志出错",e);
}
userLogin.setUsername(user.getUsername());
//保存用户登陆日志
BufferLogCollector.collect(userLogin);
logs.put(user.getUsername(), userLogin);
}else{
LOG.info("用户 "+user.getUsername()+" 的登录日志已经被记录过,用户在未注销前又再次登录,忽略此登录");
}
}else{
LOG.info("在登录的时候获得User失败");
}
}