Tabnine Logo
SessionDAO.getActiveSessions
Code IndexAdd Tabnine to your IDE (free)

How to use
getActiveSessions
method
in
org.apache.shiro.session.mgt.eis.SessionDAO

Best Java code snippets using org.apache.shiro.session.mgt.eis.SessionDAO.getActiveSessions (Showing top 4 results out of 315)

origin: apache/shiro

protected Collection<Session> getActiveSessions() {
  Collection<Session> active = sessionDAO.getActiveSessions();
  return active != null ? active : Collections.<Session>emptySet();
}
origin: org.apache.shiro/shiro-core

protected Collection<Session> getActiveSessions() {
  Collection<Session> active = sessionDAO.getActiveSessions();
  return active != null ? active : Collections.<Session>emptySet();
}
origin: wuyouzhuguli/FEBS-Shiro

@Override
public List<UserOnline> list() {
  List<UserOnline> list = new ArrayList<>();
  Collection<Session> sessions = sessionDAO.getActiveSessions();
  for (Session session : sessions) {
    UserOnline userOnline = new UserOnline();
    User user;
    SimplePrincipalCollection principalCollection;
    if (session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY) == null) {
      continue;
    } else {
      principalCollection = (SimplePrincipalCollection) session
          .getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
      user = (User) principalCollection.getPrimaryPrincipal();
      userOnline.setUsername(user.getUsername());
      userOnline.setUserId(user.getUserId().toString());
    }
    userOnline.setId((String) session.getId());
    userOnline.setHost(session.getHost());
    userOnline.setStartTimestamp(session.getStartTimestamp());
    userOnline.setLastAccessTime(session.getLastAccessTime());
    long timeout = session.getTimeout();
    userOnline.setStatus(timeout == 0L ? "0" : "1");
    String address = AddressUtils.getCityInfo(userOnline.getHost());
    userOnline.setLocation(address);
    userOnline.setTimeout(timeout);
    list.add(userOnline);
  }
  return list;
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

protected Collection<Session> getActiveSessions() {
  Collection<Session> active = sessionDAO.getActiveSessions();
  return active != null ? active : Collections.<Session>emptySet();
}
org.apache.shiro.session.mgt.eisSessionDAOgetActiveSessions

Javadoc

Returns all sessions in the EIS that are considered active, meaning all sessions that haven't been stopped/expired. This is primarily used to validate potential orphans.

If there are no active sessions in the EIS, this method may return an empty collection or null.

Performance

This method should be as efficient as possible, especially in larger systems where there might be thousands of active sessions. Large scale/high performance implementations will often return a subset of the total active sessions and perform validation a little more frequently, rather than return a massive set and validate infrequently. If efficient and possible, it would make sense to return the oldest unstopped sessions available, ordered by org.apache.shiro.session.Session#getLastAccessTime().

Smart Results

Ideally this method would only return active sessions that the EIS was certain should be invalided. Typically that is any session that is not stopped and where its lastAccessTimestamp is older than the session timeout.

For example, if sessions were backed by a relational database or SQL-92 'query-able' enterprise cache, you might return something similar to the results returned by this query (assuming org.apache.shiro.session.mgt.SimpleSessions were being stored):

 
select * from sessions s where s.lastAccessTimestamp < ? and s.stopTimestamp is null 
where the ? parameter is a date instance equal to 'now' minus the session timeout (e.g. now - 30 minutes).

Popular methods of SessionDAO

  • readSession
    Retrieves the session from the EIS uniquely identified by the specified sessionId.
  • delete
    Deletes the associated EIS record of the specified session. If there never existed a session EIS rec
  • update
    Updates (persists) data from a previously created Session instance in the EIS identified by {@link S
  • create
    Inserts a new Session record into the underling EIS (e.g. Relational database, file system, persiste

Popular in Java

  • Updating database using SQL prepared statement
  • getContentResolver (Context)
  • getSharedPreferences (Context)
  • findViewById (Activity)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now