congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
Session.touch
Code IndexAdd Tabnine to your IDE (free)

How to use
touch
method
in
org.apache.shiro.session.Session

Best Java code snippets using org.apache.shiro.session.Session.touch (Showing top 14 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew ArrayList()
  • Codota Iconnew LinkedList()
  • Smart code suggestions by Tabnine
}
origin: apache/shiro

/**
 * Immediately delegates to the underlying proxied session.
 */
public void touch() throws InvalidSessionException {
  delegate.touch();
}
origin: apache/shiro

public void touch(SessionKey key) throws InvalidSessionException {
  Session s = lookupRequiredSession(key);
  s.touch();
  onChange(s);
}
origin: apache/shiro

/**
 * Updates any 'native'  Session's last access time that might exist to the timestamp when this method is called.
 * If native sessions are not enabled (that is, standard Servlet container sessions are being used) or there is no
 * session ({@code subject.getSession(false) == null}), this method does nothing.
 * <p/>This method implementation merely calls
 * <code>Session.{@link org.apache.shiro.session.Session#touch() touch}()</code> on the session.
 *
 * @param request  incoming request - ignored, but available to subclasses that might wish to override this method
 * @param response outgoing response - ignored, but available to subclasses that might wish to override this method
 * @since 1.0
 */
@SuppressWarnings({"UnusedDeclaration"})
protected void updateSessionLastAccessTime(ServletRequest request, ServletResponse response) {
  if (!isHttpSessions()) { //'native' sessions
    Subject subject = SecurityUtils.getSubject();
    //Subject should never _ever_ be null, but just in case:
    if (subject != null) {
      Session session = subject.getSession(false);
      if (session != null) {
        try {
          session.touch();
        } catch (Throwable t) {
          log.error("session.touch() method invocation has failed.  Unable to update" +
              "the corresponding session's last access time based on the incoming request.", t);
        }
      }
    }
  }
}
origin: Graylog2/graylog2-server

  session.touch();
} else {
  LOG.debug("Not extending session because the request indicated not to.");
origin: Graylog2/graylog2-server

@GET
@ApiOperation(value = "Validate an existing session",
  notes = "Checks the session with the given ID: returns http status 204 (No Content) if session is valid.",
  code = 204
)
public SessionValidationResponse validateSession(@Context ContainerRequestContext requestContext) {
  try {
    this.authenticationFilter.filter(requestContext);
  } catch (NotAuthorizedException | LockedAccountException | IOException e) {
    return SessionValidationResponse.invalid();
  }
  final Subject subject = getSubject();
  if (!subject.isAuthenticated()) {
    return SessionValidationResponse.invalid();
  }
  // there's no valid session, but the authenticator would like us to create one
  if (subject.getSession(false) == null && ShiroSecurityContext.isSessionCreationRequested()) {
    final Session session = subject.getSession();
    LOG.debug("Session created {}", session.getId());
    session.touch();
    // save subject in session, otherwise we can't get the username back in subsequent requests.
    ((DefaultSecurityManager) SecurityUtils.getSecurityManager()).getSubjectDAO().save(subject);
    return SessionValidationResponse.validWithNewSession(String.valueOf(session.getId()),
                               String.valueOf(subject.getPrincipal()));
  }
  return SessionValidationResponse.valid();
}
origin: Graylog2/graylog2-server

s.touch();
origin: org.apache.shiro/shiro-core

/**
 * Immediately delegates to the underlying proxied session.
 */
public void touch() throws InvalidSessionException {
  delegate.touch();
}
origin: org.apache.shiro/shiro-core

public void touch(SessionKey key) throws InvalidSessionException {
  Session s = lookupRequiredSession(key);
  s.touch();
  onChange(s);
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

/**
 * Immediately delegates to the underlying proxied session.
 */
public void touch() throws InvalidSessionException {
  delegate.touch();
}
origin: stackoverflow.com

 if(SecurityUtils.getSubject().isAuthenticated()) {
  Session session = SecurityUtils.getSubject().getSession(false);
  try {
    session.touch();
  } catch (ExpiredSessionException e) {
    // timeout case.
  }
} else {
  // not login case.
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

public void touch(SessionKey key) throws InvalidSessionException {
  Session s = lookupRequiredSession(key);
  s.touch();
  onChange(s);
}
origin: org.graylog2/graylog2-server

  session.touch();
} else {
  LOG.debug("Not extending session because the request indicated not to.");
origin: org.graylog2/graylog2-server

@GET
@ApiOperation(value = "Validate an existing session",
  notes = "Checks the session with the given ID: returns http status 204 (No Content) if session is valid.",
  code = 204
)
public SessionValidationResponse validateSession(@Context ContainerRequestContext requestContext) {
  try {
    this.authenticationFilter.filter(requestContext);
  } catch (NotAuthorizedException | LockedAccountException | IOException e) {
    return SessionValidationResponse.invalid();
  }
  final Subject subject = getSubject();
  if (!subject.isAuthenticated()) {
    return SessionValidationResponse.invalid();
  }
  // there's no valid session, but the authenticator would like us to create one
  if (subject.getSession(false) == null && ShiroSecurityContext.isSessionCreationRequested()) {
    final Session session = subject.getSession();
    LOG.debug("Session created {}", session.getId());
    session.touch();
    // save subject in session, otherwise we can't get the username back in subsequent requests.
    ((DefaultSecurityManager) SecurityUtils.getSecurityManager()).getSubjectDAO().save(subject);
    return SessionValidationResponse.validWithNewSession(String.valueOf(session.getId()),
                               String.valueOf(subject.getPrincipal()));
  }
  return SessionValidationResponse.valid();
}
origin: org.graylog2/graylog2-server

s.touch();
org.apache.shiro.sessionSessiontouch

Javadoc

Explicitly updates the #getLastAccessTime() of this session to the current time when this method is invoked. This method can be used to ensure a session does not time out.

Most programmers won't use this method directly and will instead rely on the last access time to be updated automatically as a result of an incoming web request or remote procedure call/method invocation.

However, this method is particularly useful when supporting rich-client applications such as Java Web Start app, Java or Flash applets, etc. Although rare, it is possible in a rich-client environment that a user continuously interacts with the client-side application without a server-side method call ever being invoked. If this happens over a long enough period of time, the user's server-side session could time-out. Again, such cases are rare since most rich-clients frequently require server-side method invocations.

In this example though, the user's session might still be considered valid because the user is actively "using" the application, just not communicating with the server. But because no server-side method calls are invoked, there is no way for the server to know if the user is sitting idle or not, so it must assume so to maintain session integrity. This touch() method could be invoked by the rich-client application code during those times to ensure that the next time a server-side method is invoked, the invocation will not throw an ExpiredSessionException. In short terms, it could be used periodically to ensure a session does not time out.

How often this rich-client "maintenance" might occur is entirely dependent upon the application and would be based on variables such as session timeout configuration, usage characteristics of the client application, network utilization and application server performance.

Popular methods of Session

  • getAttribute
    Returns the object bound to this session identified by the specified key. If there is no object boun
  • setAttribute
    Binds the specified value to this session, uniquely identified by the specifed key name. If there is
  • getId
    Returns the unique identifier assigned by the system upon session creation. All return values from t
  • removeAttribute
    Removes (unbinds) the object bound to this session under the specified key name.
  • getHost
    Returns the host name or IP string of the host that originated this session, or nullif the host is u
  • getTimeout
    Returns the time in milliseconds that the session session may remain idle before expiring. * A negat
  • getLastAccessTime
    Returns the last time the application received a request or method invocation from the user associat
  • getStartTimestamp
    Returns the time the session was started; that is, the time the system created the instance.
  • setTimeout
    Sets the time in milliseconds that the session may remain idle before expiring. * A negative val
  • getAttributeKeys
    Returns the keys of all the attributes stored under this session. If there are no attributes, this r
  • stop
    Explicitly stops (invalidates) this session and releases all associated resources. If this session h
  • stop

Popular in Java

  • Reading from database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • runOnUiThread (Activity)
  • getSystemService (Context)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Table (org.hibernate.mapping)
    A relational table
  • Top 17 Plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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