private void loginUser(Authentication authentication) { if (authentication == null) return; if (!(authentication.getPrincipal() instanceof Person)) return; Person person = (Person) authentication.getPrincipal(); String username = person.getUsername(); String name = person.getName(); if (authentication.getDetails() instanceof WebAuthenticationDetails) { WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails(); String ip = details.getRemoteAddress(); String sessionId = details.getSessionId(); if (onLineManager.getOnlineUser(sessionId) != null) return; onLineManager.loginUser(ip, sessionId, person); logManager.log(username, name, ip, "登录系统", ""); if (logger.isDebugEnabled()) logger.debug( "用户 {}[{}] 登录系统,登录IP:{},session:{}", new Object[] {name, username, ip, sessionId}); } }
private void logoutUser(String sessionId) { OnLineInfo onlineInfo = onLineManager.getOnlineUser(sessionId); if (onlineInfo == null) return; String ip = onlineInfo.getIp(); Person person = onlineInfo.getPerson(); String username = person.getUsername(); String name = person.getName(); onLineManager.logoutUser(sessionId); logManager.log(username, name, ip, "退出登陆", ""); if (logger.isDebugEnabled()) logger.debug( "用户 {}[{}] 退出登陆,登录IP:{},session:{}", new Object[] {name, username, ip, sessionId}); }