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:de.itsvs.cwtrpc.security.AbstractRpcFailureHandler.java

protected void invalidateSession(HttpServletRequest request) {
    final HttpSession session;

    session = request.getSession(false);
    if (session != null) {
        if (log.isDebugEnabled()) {
            log.debug("Invalidating session " + session.getId());
        }//from  www  . j a v a 2s . c o m
        session.invalidate();
    }
}

From source file:com.deep.two.authority.impl.FareAbstractSessionFixationProtection.java

/**
 * Called when the session has been changed and the old attributes have been
 * migrated to the new session. Only called if a session existed to start
 * with. Allows subclasses to plug in additional behaviour. *
 * <p>//from www. ja v a2 s  .  co m
 * The default implementation of this method publishes a
 * {@link SessionFixationProtectionEvent} to notify the application that the
 * session ID has changed. If you override this method and still wish these
 * events to be published, you should call {@code super.onSessionChange()}
 * within your overriding method.
 * 
 * @param originalSessionId
 *            the original session identifier
 * @param newSession
 *            the newly created session
 * @param auth
 *            the token for the newly authenticated principal
 */
protected void onSessionChange(String originalSessionId, HttpSession newSession, Authentication auth) {
    applicationEventPublisher
            .publishEvent(new SessionFixationProtectionEvent(auth, originalSessionId, newSession.getId()));
}

From source file:jp.co.opentone.bsol.linkbinder.view.filter.LoginFilter.java

private void startNewSession(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession(false);
    String oldId = session.getId();
    Map<String, Object> attributes = collectSessionAttributes(session);
    session.invalidate();/*from ww  w  .  java2s.  co m*/
    HttpSession newSession = request.getSession(true);
    copyAttributes(newSession, attributes);

    newSession.removeAttribute(Constants.KEY_START_NEW_SESSION);

    if (log.isDebugEnabled()) {
        log.debug("session '{}' was invalidated.", oldId);
        log.debug("session '{}' was started.", newSession.getId());
    }
}

From source file:com.sun.socialsite.web.filters.SessionFilter.java

/**
 *
 *//*from www .j a va2  s  .co  m*/
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest httpReq = (HttpServletRequest) req;
    String remoteUser = httpReq.getRemoteUser();

    if (remoteUser != null) {

        HttpSession httpSession = httpReq.getSession();
        if (httpSession.getAttribute(REMOTE_USER) == null) {
            log.debug(
                    String.format("Setting REMOTE_USER=%s on Session[id=%s]", remoteUser, httpSession.getId()));
            httpSession.setAttribute(REMOTE_USER, remoteUser);
        }

        assert (httpSession.equals(SessionListener.getSession(httpSession.getId())));

    }

    chain.doFilter(req, resp);

}

From source file:cn.imethan.common.security.session.ConcurrentSessionFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    HttpSession session = request.getSession(false);

    if (session != null) {
        SessionInformation info = sessionRegistry.getSessionInformation(session.getId());

        if (info != null) {
            if (info.isExpired()) {
                // Expired - abort processing
                doLogout(request, response);

                String targetUrl = determineExpiredUrl(request, info);

                if (targetUrl != null) {
                    redirectStrategy.sendRedirect(request, response, targetUrl);

                    return;
                } else {
                    response.getWriter()
                            .print("This session has been expired (possibly due to multiple concurrent "
                                    + "logins being attempted as the same user).");
                    response.flushBuffer();
                }// ww  w.  j  a va  2s  .  com

                return;
            } else {
                // Non-expired - update last request date/time
                sessionRegistry.refreshLastRequest(info.getSessionId());
            }
        }
    }

    chain.doFilter(request, response);
}

From source file:org.guanxi.sp.engine.service.shibboleth.AuthConsumerService.java

/**
 * This initialises the threads map which will be used to hold the AA conversation
 * threads by session.//from  w ww .j  a v a 2  s  .  c  o m
 */
public void init() {
    threads = new TreeMap<HttpSession, AuthConsumerServiceThread>(new Comparator<HttpSession>() {
        public int compare(HttpSession one, HttpSession two) {
            return one.getId().compareTo(two.getId());
        }
    });
}

From source file:com.dreambox.web.logger.LoggingFilter.java

@Override
protected void logRequest(HttpServletRequest request) {
    String uri = request.getRequestURI();
    if (isIgnoreUri(uri)) {
        return;/*from   www.  j a  v a2 s.co  m*/
    }
    request.setAttribute(REQUEST_START_TIME, System.currentTimeMillis());
    HttpSession session = request.getSession(false);
    String id = "";
    if (session != null) {
        id = session.getId();
    } else {
        id = UUID.randomUUID().toString();
    }
    request.setAttribute(REQUEST_ID_ATTR, id);
    String method = request.getMethod();
    String queryStr = request.getQueryString();
    String parameter = getRequestParams(request);
    String ip = IPUtil.getClientIP(request);
    Map<String, String> commonPara = new HashMap<String, String>();
    commonPara.put("ip", ip);
    commonPara.put("method", method);
    commonPara.put("queryStr", queryStr);
    commonPara.put("parameter", parameter);
    threadLocalMap.set(commonPara);
    // log all request
    l4jlogger.info(String.format(REQUEST_LOG_FORMAT, now(), id, ip, method, uri, queryStr, parameter));
}

From source file:nl.strohalm.cyclos.http.LifecycleListener.java

/**
 * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
 *//*  w ww  .  j a  va  2  s  .  c om*/
@Override
public void sessionDestroyed(final HttpSessionEvent event) {
    final HttpSession session = event.getSession();
    final String sessionId = session == null ? null : session.getId();
    if (sessionId == null) {
        return;
    }

    // If there is an active transaction, use an transaction end listener to actually logout
    if (transactionHelper.hasActiveTransaction()) {
        CurrentTransactionData.addTransactionEndListener(new TransactionEndListener() {
            @Override
            protected void onTransactionEnd(final boolean commit) {
                doLogout(sessionId);
            }
        });
    } else {
        // Logout directly (this is in another TX)
        doLogout(sessionId);
    }
}

From source file:com.twinsoft.convertigo.engine.requesters.WebClippingServletRequester.java

@Override
public Context getContext() throws Exception {
    HttpServletRequest request = (HttpServletRequest) inputData;

    initInternalVariables();//from  w w  w  .  j a v  a 2s.  c om

    HttpSession httpSession = request.getSession();
    String sessionID = httpSession.getId();

    context = Engine.isEngineMode()
            ? Engine.theApp.contextManager.get(this, contextName, sessionID, poolName, projectName,
                    connectorName, sequenceName)
            : Engine.theApp.contextManager.get(this, connectorName, sessionID, poolName, projectName,
                    connectorName, sequenceName);

    return context;
}

From source file:nz.co.fortytwo.signalk.processor.LoggerProcessor.java

@Override
public void process(Exchange exchange) throws Exception {

    logger.debug("LoggerProcessor starts");
    HttpServletRequest request = exchange.getIn(HttpMessage.class).getRequest();
    logger.debug("Session = " + request.getSession().getId());
    HttpSession session = request.getSession();
    if (logger.isDebugEnabled()) {

        logger.debug("Request = " + exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST).getClass());
        logger.debug("Session = " + session.getId());
    }//from  w  w w  .  jav  a 2  s  . c om

    if (session.getId() != null) {

        String remoteAddress = request.getRemoteAddr();
        String localAddress = request.getLocalAddr();
        if (Util.sameNetwork(localAddress, remoteAddress)) {
            exchange.getIn().setHeader(SignalKConstants.MSG_TYPE, SignalKConstants.INTERNAL_IP);
        } else {
            exchange.getIn().setHeader(SignalKConstants.MSG_TYPE, SignalKConstants.EXTERNAL_IP);
        }

        if (exchange.getIn().getHeader(Exchange.HTTP_METHOD).equals("GET")) {
            processGet(exchange);
        }
        if (exchange.getIn().getHeader(Exchange.HTTP_METHOD).equals("POST")) {
            processPost(exchange);
        }
    } else {
        exchange.getIn().setHeader("Location", SignalKConstants.SIGNALK_AUTH);
        exchange.getIn().setBody("Authentication Required");
    }
}