Search in sources :

Example 6 with UserOnlineDo

use of com.albedo.java.modules.sys.domain.UserOnlineDo in project albedo by somowhere.

the class SysUserOnlineListener method saveSysUserOnlineRefreshLastRequestEvent.

@Async
@Order
@EventListener(SysUserOnlineRefreshLastRequestEvent.class)
public void saveSysUserOnlineRefreshLastRequestEvent(SysUserOnlineRefreshLastRequestEvent event) {
    SessionInformation sessionInformation = (SessionInformation) event.getSource();
    UserOnlineDo userOnlineDo = userOnlineService.getById(sessionInformation.getSessionId());
    if (userOnlineDo != null) {
        userOnlineDo.setLastAccessTime(LocalDateTimeUtil.of(sessionInformation.getLastRequest()));
        userOnlineService.updateById(userOnlineDo);
    } else {
        log.debug("sessionInformation sessionId " + sessionInformation.getSessionId() + ", onlineUser is null");
    }
}
Also used : SessionInformation(org.springframework.security.core.session.SessionInformation) UserOnlineDo(com.albedo.java.modules.sys.domain.UserOnlineDo) Order(org.springframework.core.annotation.Order) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Example 7 with UserOnlineDo

use of com.albedo.java.modules.sys.domain.UserOnlineDo 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("登录成功"));
}
Also used : SysUserOnlineEvent(com.albedo.java.common.security.event.SysUserOnlineEvent) LogLoginDo(com.albedo.java.modules.sys.domain.LogLoginDo) UserOnlineDo(com.albedo.java.modules.sys.domain.UserOnlineDo)

Example 8 with UserOnlineDo

use of com.albedo.java.modules.sys.domain.UserOnlineDo in project albedo by somowhere.

the class UserOnlineResource method remove.

@PreAuthorize("@pms.hasPermission('sys_userOnline_del')")
@LogOperate(value = "在线用户删除")
@DeleteMapping
public Result remove(@RequestBody Set<String> ids, HttpServletRequest request) {
    for (String id : ids) {
        UserOnlineDo online = userOnlineService.getById(id);
        if (online == null) {
            return Result.buildFail("用户已下线");
        }
        try {
            SessionInformation sessionInformation = sessionRegistry.getSessionInformation(online.getSessionId());
            if (sessionInformation != null) {
                if (sessionInformation.getSessionId().equals(request.getSession(false).getId())) {
                    return Result.buildFail("当前登陆用户无法删除");
                }
                sessionInformation.expireNow();
                redisTemplate.boundHashOps(RedisSessionRegistry.SESSIONIDS).put(online.getSessionId(), sessionInformation);
            }
        } catch (Exception e) {
        }
        sessionRegistry.removeSessionInformation(online.getSessionId());
        userOnlineService.removeById(online);
    }
    return Result.buildOk("操作成功");
}
Also used : SessionInformation(org.springframework.security.core.session.SessionInformation) UserOnlineDo(com.albedo.java.modules.sys.domain.UserOnlineDo) LogOperate(com.albedo.java.common.log.annotation.LogOperate) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

UserOnlineDo (com.albedo.java.modules.sys.domain.UserOnlineDo)8 SessionInformation (org.springframework.security.core.session.SessionInformation)4 LogOperate (com.albedo.java.common.log.annotation.LogOperate)2 SysUserOnlineEvent (com.albedo.java.common.security.event.SysUserOnlineEvent)2 UserDetail (com.albedo.java.common.security.service.UserDetail)2 EventListener (org.springframework.context.event.EventListener)2 Order (org.springframework.core.annotation.Order)2 Async (org.springframework.scheduling.annotation.Async)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 UserAgent (cn.hutool.http.useragent.UserAgent)1 LogLoginDo (com.albedo.java.modules.sys.domain.LogLoginDo)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 Authentication (org.springframework.security.core.Authentication)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1