Search in sources :

Example 1 with UserOnline

use of io.github.tesla.authz.domain.UserOnline in project tesla by linking12.

the class SessionService method list.

public List<UserOnline> list() {
    List<UserOnline> list = new ArrayList<>();
    Collection<Session> sessions = sessionDAO.getActiveSessions();
    for (Session session : sessions) {
        UserOnline userOnline = new UserOnline();
        if (session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY) == null) {
            continue;
        } else {
            SimplePrincipalCollection principalCollection = (SimplePrincipalCollection) session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
            String userName = principalCollection.getRealmNames().iterator().next();
            userOnline.setUsername(userName);
        }
        userOnline.setId((String) session.getId());
        userOnline.setHost(session.getHost());
        userOnline.setStartTimestamp(session.getStartTimestamp());
        userOnline.setLastAccessTime(session.getLastAccessTime());
        userOnline.setTimeout(session.getTimeout());
        list.add(userOnline);
    }
    return list;
}
Also used : UserOnline(io.github.tesla.authz.domain.UserOnline) ArrayList(java.util.ArrayList) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Session(org.apache.shiro.session.Session)

Aggregations

UserOnline (io.github.tesla.authz.domain.UserOnline)1 ArrayList (java.util.ArrayList)1 Session (org.apache.shiro.session.Session)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1