use of com.albedo.java.common.security.event.SysUserOnlineEvent in project albedo by somowhere.
the class RedisSessionRegistry method registerNewSession.
@Override
public void registerNewSession(String sessionId, Object principal) {
ArgumentAssert.notEmpty(sessionId, "SessionId required as per interface contract");
ArgumentAssert.notNull(principal, "Principal required as per interface contract");
ArgumentAssert.isTrue(principal instanceof UserDetail, "Principal required as UserDetail");
if (log.isDebugEnabled()) {
log.debug("Registering session " + sessionId + ", for principal " + principal);
}
UserDetail userDetail = (UserDetail) principal;
if (getSessionInformation(sessionId) != null) {
removeSessionInformation(sessionId);
}
SessionInformation sessionInformation = new CustomSessionInformation(userDetail.getId(), sessionId, new Date());
redisTemplate.boundHashOps(getSessionIdsKey()).put(sessionId, sessionInformation);
Set<String> sessionsUsedByPrincipal = getPrincipals(userDetail.getId());
if (sessionsUsedByPrincipal == null) {
sessionsUsedByPrincipal = new CopyOnWriteArraySet();
Set<String> prevSessionsUsedByPrincipal = this.putIfAbsentPrincipals(userDetail.getId(), sessionsUsedByPrincipal);
if (prevSessionsUsedByPrincipal != null) {
sessionsUsedByPrincipal = prevSessionsUsedByPrincipal;
}
}
sessionsUsedByPrincipal.add(sessionId);
if (log.isTraceEnabled()) {
log.trace("Sessions used by '" + principal + "' : " + sessionsUsedByPrincipal);
}
Authentication authentication = SecurityUtil.getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
UserOnlineDo userOnlineDo = userOnlineService.getById(sessionId);
if (userOnlineDo == null) {
userOnlineDo = LoginUtil.getUserOnline(authentication);
SpringContextHolder.publishEvent(new SysUserOnlineEvent(userOnlineDo));
}
}
}
use of com.albedo.java.common.security.event.SysUserOnlineEvent in project albedo by somowhere.
the class AjaxAuthenticationSuccessHandler method onAuthenticationSuccess.
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
response.setStatus(HttpServletResponse.SC_OK);
String useruame = request.getParameter("username");
LoginUtil.isValidateCodeLogin(useruame, false, true);
UserOnlineDo userOnlineDo = LoginUtil.getUserOnline(authentication);
SpringContextHolder.publishEvent(new SysUserOnlineEvent(userOnlineDo));
LogLoginDo logLoginDo = SysLogUtils.getSysLogLogin();
logLoginDo.setParams(HttpUtil.toParams(request.getParameterMap()));
logLoginDo.setUsername(useruame);
logLoginDo.setTitle("用户登录");
AsyncUtil.recordLogLogin(logLoginDo);
WebUtil.renderJson(response, Result.buildOk("登录成功"));
}
Aggregations