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;
}
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;
}
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);
}
Aggregations