Search in sources :

Example 1 with AgileOnlineUser

use of com.jeeagile.core.security.user.AgileOnlineUser in project jeeagile by jeeagile.

the class AgileShiroSecurity method getOnlineUserList.

@Override
public List<AgileOnlineUser> getOnlineUserList() {
    List<AgileOnlineUser> onlineUserList = new ArrayList<>();
    Collection<Session> sessionCollection = sessionDAO.getActiveSessions();
    for (Session session : sessionCollection) {
        Object pc = session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
        if (pc instanceof PrincipalCollection) {
            AgileBaseUser userData = (AgileBaseUser) ((PrincipalCollection) pc).getPrimaryPrincipal();
            if (userData == null || AgileStringUtil.isEmpty(userData.getUserName())) {
                continue;
            }
            AgileOnlineUser agileOnlineUser = new AgileOnlineUser();
            BeanUtils.copyProperties(userData, agileOnlineUser);
            agileOnlineUser.setStartAccessTime(session.getStartTimestamp());
            agileOnlineUser.setLastAccessTime(session.getLastAccessTime());
            onlineUserList.add(agileOnlineUser);
        }
    }
    return onlineUserList;
}
Also used : ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) AgileOnlineUser(com.jeeagile.core.security.user.AgileOnlineUser) AgileBaseUser(com.jeeagile.core.security.user.AgileBaseUser) Session(org.apache.shiro.session.Session)

Example 2 with AgileOnlineUser

use of com.jeeagile.core.security.user.AgileOnlineUser in project jeeagile by jeeagile.

the class AgileSpringSecurity method getOnlineUserList.

@Override
public List<AgileOnlineUser> getOnlineUserList() {
    List<AgileOnlineUser> onlineUserList = new ArrayList<>();
    List<Object> sessionIdList = sessionRegistry.getAllPrincipals();
    for (Object sessionId : sessionIdList) {
        AgileUserDetails agileUserDetails = (AgileUserDetails) AgileCacheUtil.get(AgileCacheConstants.AGILE_CACHE_SESSION_NAME, sessionId.toString());
        if (agileUserDetails == null || AgileStringUtil.isEmpty(agileUserDetails.getUsername())) {
            sessionRegistry.removeSessionInformation(sessionId.toString());
            continue;
        }
        SessionInformation sessionInformation = sessionRegistry.getSessionInformation(sessionId.toString());
        if (sessionInformation == null) {
            sessionRegistry.removeSessionInformation(sessionId.toString());
            continue;
        }
        AgileOnlineUser agileOnlineUser = new AgileOnlineUser();
        BeanUtils.copyProperties(agileUserDetails.getUserData(), agileOnlineUser);
        agileOnlineUser.setStartAccessTime(agileUserDetails.getUserData().getLoginTime());
        agileOnlineUser.setLastAccessTime(sessionInformation.getLastRequest());
        onlineUserList.add(agileOnlineUser);
    }
    return onlineUserList;
}
Also used : AgileUserDetails(com.jeeagile.springsecurity.userdetails.AgileUserDetails) SessionInformation(org.springframework.security.core.session.SessionInformation) ArrayList(java.util.ArrayList) AgileOnlineUser(com.jeeagile.core.security.user.AgileOnlineUser)

Example 3 with AgileOnlineUser

use of com.jeeagile.core.security.user.AgileOnlineUser in project jeeagile by jeeagile.

the class AgileOnlineController method getOnlineUserList.

/**
 * 获取在线用户
 */
private AgilePage getOnlineUserList(AgilePageable<Map> agilePageable) {
    String loginIp = "";
    String userName = "";
    if (agilePageable.getQueryCond() != null) {
        loginIp = (String) agilePageable.getQueryCond().get("ipAddr");
        userName = (String) agilePageable.getQueryCond().get("userName");
    }
    List<AgileOnlineUser> onlineUserAllList = AgileSecurityUtil.getOnlineUserList();
    List<AgileOnlineUser> onlineUserList = new ArrayList<>();
    for (AgileOnlineUser agileOnlineUser : onlineUserAllList) {
        if (AgileStringUtil.isEmpty(agileOnlineUser.getUserToken()) || agileOnlineUser.getUserToken().equals(AgileSecurityContext.getCurrentUserToken())) {
            agileOnlineUser.setUserName(agileOnlineUser.getUserName() + "(当前用户)");
        }
        if (AgileStringUtil.isNotEmpty(loginIp) && AgileStringUtil.isNotEmpty(userName)) {
            if (loginIp.equals(agileOnlineUser.getLoginIp()) && userName.equals(agileOnlineUser.getUserName())) {
                onlineUserList.add(agileOnlineUser);
            }
        } else if (AgileStringUtil.isNotEmpty(loginIp)) {
            if (loginIp.equals(agileOnlineUser.getLoginIp())) {
                onlineUserList.add(agileOnlineUser);
            }
        } else if (AgileStringUtil.isNotEmpty(userName)) {
            if (userName.equals(agileOnlineUser.getUserName())) {
                onlineUserList.add(agileOnlineUser);
            }
        } else {
            onlineUserList.add(agileOnlineUser);
        }
    }
    return AgilePageUtil.startPage(onlineUserList, agilePageable);
}
Also used : ArrayList(java.util.ArrayList) AgileOnlineUser(com.jeeagile.core.security.user.AgileOnlineUser)

Aggregations

AgileOnlineUser (com.jeeagile.core.security.user.AgileOnlineUser)3 ArrayList (java.util.ArrayList)3 AgileBaseUser (com.jeeagile.core.security.user.AgileBaseUser)1 AgileUserDetails (com.jeeagile.springsecurity.userdetails.AgileUserDetails)1 Session (org.apache.shiro.session.Session)1 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)1 SessionInformation (org.springframework.security.core.session.SessionInformation)1