Example usage for javax.servlet.http HttpSession getId

List of usage examples for javax.servlet.http HttpSession getId

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getId.

Prototype

public String getId();

Source Link

Document

Returns a string containing the unique identifier assigned to this session.

Usage

From source file:apps.SimpleApplication.java

@RequestMapping("/session")
public String session(HttpSession session) {
    return session.getId();
}

From source file:com.boundlessgeo.geoserver.AppSessionDebugger.java

@Override
public void sessionCreated(HttpSessionEvent se) {
    HttpSession session = se.getSession();
    sessions.put(session.getId(), session);
}

From source file:edu.ucsb.nceas.metacat.util.RequestUtil.java

/**
 * Get the session data from a request. The Scenarios we can run across
 * here: // w ww  . j  a v a 2s. c  o  m
 * -- the session id parameter was set in the request parameters 
 * -- request.getSession returns a new session. There is a chance that the
 *    session id was set in a cookie. Check for a JSESSIONID cookie and use
 *    that id if provided. 
 * -- request.getSession returns a session that is a)
 *    preexisting or b) new but without a JSESSIONID cookie. Use the session id
 *    from this session
 * 
 * @param request
 *            the request from which to get the session data
 * @return the session data object representing the active session for this
 *         request. If there is no active session, the public session data
 *         is returned
 */
public static SessionData getSessionData(HttpServletRequest request) {
    SessionData sessionData = null;
    String sessionId = null;

    Hashtable<String, String[]> params = getParameters(request);

    if (params.containsKey("sessionid")) {
        // the session id is specified in the request parameters
        sessionId = ((String[]) params.get("sessionid"))[0];
        logMetacat.debug("session ID provided in request properties: " + sessionId);
    } else {
        HttpSession session = request.getSession(true);
        if (session.isNew()) {
            // this is a new session
            Cookie sessionCookie = RequestUtil.getCookie(request, "JSESSIONID");
            if (sessionCookie != null) {
                // and there is a JSESSIONID cookie
                sessionId = sessionCookie.getValue();
                logMetacat.debug("session ID provided in request cookie: " + sessionId);
            }
        }
        if (sessionId == null) {
            // there is an existing session (session is old)
            sessionId = session.getId();
            logMetacat.debug("session ID retrieved from request: " + sessionId);
        }
    }

    // if the session id is registered in SessionService, get the
    // SessionData for it. Otherwise, use the public session.
    if (SessionService.isSessionRegistered(sessionId)) {
        logMetacat.debug("retrieving session data from session service " + "for session id " + sessionId);
        sessionData = SessionService.getRegisteredSession(sessionId);
    } else {
        logMetacat.debug("using public session.  Given session id is " + "registered: " + sessionId);
        sessionData = SessionService.getPublicSession();
    }

    return sessionData;
}

From source file:org.itracker.web.util.LoginUtilities.java

public static User setupSession(User user, String encPassword, HttpServletRequest request,
        HttpServletResponse response) {/*  w w w .j  ava  2s .c  om*/
    if (user == null) {
        logger.warn("setupSession: null user", (logger.isDebugEnabled() ? new RuntimeException() : null));
        throw new IllegalArgumentException("null user");
    }

    UserService userService = ServletContextUtils.getItrackerServices().getUserService();

    if (logger.isDebugEnabled()) {
        logger.debug("Creating new session");
    }
    HttpSession session = request.getSession(true);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting session timeout to " + getConfiguredSessionTimeout() + " minutes");
    }
    session.setMaxInactiveInterval(getConfiguredSessionTimeout() * 60);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting session tracker");
    }
    session.setAttribute(Constants.SESSION_TRACKER_KEY, new SessionTracker(user.getLogin(), session.getId()));

    if (logger.isDebugEnabled()) {
        logger.debug("Setting user information");
    }
    session.setAttribute(Constants.USER_KEY, user);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting preferences for user " + user.getLogin());
    }
    UserPreferences userPrefs = user.getPreferences();
    // TODO : this is a hack, remove when possible
    if (userPrefs == null) {
        logger.warn("setupSession: got user with no preferences!: " + user + " (prefs: " + user.getPreferences()
                + ")");
        userPrefs = new UserPreferences();
    }
    session.setAttribute(Constants.PREFERENCES_KEY, userPrefs);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting user " + user + " locale to "
                + ITrackerResources.getLocale(userPrefs.getUserLocale()));
    }
    session.setAttribute(Constants.LOCALE_KEY, ITrackerResources.getLocale(userPrefs.getUserLocale()));

    // TODO: cookie could be removed
    Cookie cookie = new Cookie(Constants.COOKIE_NAME, "");
    cookie.setPath(request.getContextPath());

    cookie.setValue("");
    cookie.setMaxAge(0);

    response.addCookie(cookie);

    if (logger.isDebugEnabled()) {
        logger.debug("Setting permissions for user " + user.getLogin());
    }
    Map<Integer, Set<PermissionType>> usersMapOfProjectIdsAndSetOfPermissionTypes = userService
            .getUsersMapOfProjectIdsAndSetOfPermissionTypes(user, AuthenticationConstants.REQ_SOURCE_WEB);
    session.setAttribute(Constants.PERMISSIONS_KEY, usersMapOfProjectIdsAndSetOfPermissionTypes);

    // Reset some session forms
    session.setAttribute(Constants.SEARCH_QUERY_KEY, null);

    SessionManager.clearSessionNeedsReset(user.getLogin());
    if (logger.isDebugEnabled()) {
        logger.debug("User session data updated.");
    }
    return user;
}

From source file:be.fedict.eid.applet.beta.webapp.SessionContextListener.java

public void sessionDestroyed(HttpSessionEvent event) {
    HttpSession session = event.getSession();
    String sessionId = session.getId();
    LOG.debug("session destroyed: " + sessionId);
    this.sessionContextManager.deactivateSessionContext(sessionId);
}

From source file:SessionBindListen.java

public void valueBound(HttpSessionBindingEvent be) {

    HttpSession session = be.getSession();
    String id = session.getId();
    String name = be.getName();/*w w w.j  av a2 s .co  m*/
    Object value = be.getValue();
    String source = be.getSource().getClass().getName();
    String message = new StringBuffer("Attribute bound to session in ").append(source)
            .append("\nThe attribute name: ").append(name).append("\n").append("The attribute value: ")
            .append(value).append("\n").append("The session id: ").append(id).toString();

    System.out.println(message);
}

From source file:be.fedict.eid.applet.beta.webapp.SessionContextListener.java

public void sessionCreated(HttpSessionEvent event) {
    HttpSession session = event.getSession();
    String sessionId = session.getId();
    LOG.debug("session created: " + sessionId);
    int contextId = this.sessionContextManager.getSessionContextId(sessionId);
    LOG.debug("context Id: " + contextId);
}

From source file:SessionBindListen.java

public void valueUnbound(HttpSessionBindingEvent be) {

    HttpSession session = be.getSession();
    String id = session.getId();
    String name = be.getName();//from   ww w .  jav  a  2 s.c om
    if (name == null)
        name = "Unknown";
    String source = be.getSource().getClass().getName();
    String message = new StringBuffer("Attribute unbound from session in ").append(source)
            .append("\nThe attribute name: ").append(name).append("\n").append("The session id: ").append(id)
            .toString();
    //clear Map; send message
    info.clear();
    System.out.println(message + "\nThe size of the HashMap is: " + info.size());
}

From source file:com.liferay.portal.events.LogSessionIdAction.java

public void run(HttpServletRequest req, HttpServletResponse res) throws ActionException {

    HttpSession ses = req.getSession();

    _log.debug("Session id " + ses.getId() + " is " + (!ses.isNew() ? "not " : "") + "new");
}

From source file:th.co.geniustree.osgi.prototype.authen.impl.AuthenStoreImpl.java

private HttpSession validateSession(HttpSession session) {
    String sessionId = session.getId();
    try {/*from  ww  w  .jav a2  s . c o m*/
        session.getCreationTime();
    } catch (IllegalStateException ex) {
        // it's invalid
        store.removeSession(sessionId);
        session = null;
        ex.printStackTrace();
    }

    return session;
}