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:com.amalto.webapp.core.bean.Configuration.java

private static Configuration loadFromSession() {
    HttpSession session = SessionContextHolder.currentSession();
    if (session != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Getting registered configuration from session " + session.getId()); //$NON-NLS-1$
        }// w  w  w  . j a v  a 2  s  .com
        return (Configuration) session.getAttribute(MDM_CONFIGURATION_ATTRIBUTE);
    }
    return null;
}

From source file:de.metas.ui.web.login.LoginRestController.java

private static MSession createMSession(final Login loginService) {
    final HttpServletRequest httpRequest = ((ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes()).getRequest();
    final HttpSession httpSess = httpRequest.getSession();
    final String webSessionId = httpSess.getId();
    ///* w w w .  j  a  v  a  2  s  .  co m*/
    // final WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    String remoteAddr = httpRequest.getRemoteAddr();
    String remoteHost = httpRequest.getRemoteHost();

    //
    // Check if we are behind proxy and if yes, get the actual client IP address
    // NOTE: when configuring apache, don't forget to activate reverse-proxy mode
    // see http://www.xinotes.org/notes/note/770/
    final String forwardedFor = httpRequest.getHeader("X-Forwarded-For");
    if (!Check.isEmpty(forwardedFor)) {
        remoteAddr = forwardedFor;
        remoteHost = forwardedFor;
    }

    final LoginContext ctx = loginService.getCtx();
    final MSession sessionPO = MSession.get(ctx.getSessionContext(), remoteAddr, remoteHost, webSessionId);

    // Set HostKey
    // FIXME: commented out because this one is not working when running over websockets (i.e. HttpServletResponse does not exists)
    // see https://dev.vaadin.com/ticket/11808
    // @formatter:off
    //      final I_AD_Session session = InterfaceWrapperHelper.create(sessionPO, I_AD_Session.class);
    //      HttpCookieHostKeyStorage.createUpdateHostKey();
    //      final String hostKey = hostKeyBL.getHostKey();
    //      session.setHostKey(hostKey);
    //      InterfaceWrapperHelper.save(session);
    // @formatter:on

    // Update Login helper
    loginService.setRemoteAddr(remoteAddr);
    loginService.setRemoteHost(remoteHost);
    loginService.setWebSession(webSessionId);

    return sessionPO;
}

From source file:org.sloth.util.ControllerUtils.java

/**
 * Authorizes the {@code HttpSession} with the specified {@code User}.
 * //from   ww w.j a v a  2  s  .  c  o m
 * @param s
 *            the {@code HttpSession}
 * @param u
 *            the {@code User}
 */
public static void auth(HttpSession s, User u) {
    if (u == null) {
        throw new NullPointerException("User must not be null.");
    }
    logger.info("Authorizing Session {} by User {}", s.getId(), u.getId());
    s.setAttribute(SESSION_ATTRIBUTE, u);
}

From source file:com.evolveum.midpoint.security.api.SecurityUtil.java

/**
 * Returns current connection information, as derived from HTTP request stored in current thread.
 * May be null if the thread is not associated with any HTTP request (e.g. task threads, operations invoked from GUI but executing in background).
 *//* w  w  w  .  ja  va2s.c  o m*/
public static HttpConnectionInformation getCurrentConnectionInformation() {
    RequestAttributes attr = RequestContextHolder.getRequestAttributes();
    if (!(attr instanceof ServletRequestAttributes)) {
        return null;
    }
    ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) attr;
    HttpServletRequest request = servletRequestAttributes.getRequest();
    if (request == null) {
        return null;
    }
    HttpConnectionInformation rv = new HttpConnectionInformation();
    HttpSession session = request.getSession(false);
    if (session != null) {
        rv.setSessionId(session.getId());
    }
    rv.setLocalHostName(request.getLocalName());
    rv.setRemoteHostAddress(getRemoteHostAddress(request));
    return rv;
}

From source file:com.gdo.project.model.SessionStcl.java

/**
 * Creates and store the session stencil in HTTP session.
 * /* ww w .jav a2s. c  o  m*/
 * The session is stored as a stencil and not as a plugged stencil as it
 * implements the HttpSessionBindingListener interface.
 * 
 * @param stclContext
 *            the stencil context.
 */
public static void createSessionStcl(StclContext stclContext) {
    HttpSession session = stclContext.getSession();
    HttpServletRequest request = stclContext.getRequest();

    // checks another one wasn't created before
    Stcl sessionStcl = getSessionStcl(stclContext);
    if (sessionStcl != null) {
        logError("A session stencil (%s) already exists in session %s (ip %s)", sessionStcl, session.getId(),
                request.getRemoteAddr());
    } else {
        StclFactory factory = (StclFactory) stclContext.getStencilFactory();
        sessionStcl = factory.createStencil(stclContext, SessionStcl.class);
    }

    // bounds it to the session
    ((SessionStcl) sessionStcl).createListener(stclContext, session);
}

From source file:com.huateng.ebank.business.common.GlobalInfo.java

public static void setGlobalInfo2HttpSession(HttpSession httpSession, GlobalInfo globalInfo) {
    httpSession.setAttribute(GlobalInfo.KEY_GLOBAL_INFO, globalInfo);
    globalInfo.setSessionId(httpSession.getId());
}

From source file:org.frat.common.security.BaseSecurityContext.java

/**
 * .//w w w. j  a  v a 2s.com
 * 
 * @param username
 */
public static void kickOutUser(String username) {
    try {
        // applicationHashSet?session
        @SuppressWarnings("unchecked")
        HashSet<HttpSession> sessions = (HashSet<HttpSession>) WebUtil.getServletContext()
                .getAttribute("loginSessions");
        List<HttpSession> sessionList = new ArrayList<HttpSession>();
        for (HttpSession session : sessions) {
            if (null != session && StringUtil.isEqualObj(
                    String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)),
                    username)) {
                // session
                if (!StringUtil.isEqualObj(session.getId(), WebUtil.getSessionId())) {
                    sessionList.add(session);
                }
            }
        }
        for (HttpSession session : sessionList) {
            session.invalidate();
            LOGGER.info("success kick out session [" + session.getId() + "]");
            LOGGER.info("success kick out user [" + username + "]");
        }
    } catch (Exception e) {
        LOGGER.error("");
        LOGGER.error(StackTraceUtil.getStackTrace(e));
    }
}

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Determine the session id of the given request, if any.
 * @param request current HTTP request/* ww  w.j a  v a 2 s .  co  m*/
 * @return the session id, or {@code null} if none
 */
public static String getSessionId(HttpServletRequest request) {
    Assert.notNull(request, "Request must not be null");
    HttpSession session = request.getSession(false);
    return (session != null ? session.getId() : null);
}

From source file:com.huateng.ebank.business.common.GlobalInfo.java

public static GlobalInfo getFromRequest2(HttpServletRequest request) throws CommonException {
    HttpSession httpSession = request.getSession();
    GlobalInfo globalInfo = (GlobalInfo) httpSession.getAttribute(GlobalInfo.KEY_GLOBAL_INFO);

    if (log.isDebugEnabled()) {
        log.debug("session id = " + httpSession.getId());
    }//w  w  w  . jav a  2 s.  c o  m

    if (null != globalInfo) {
        setCurrentInstance(globalInfo);
        String sessionId = httpSession.getId();
        globalInfo.setSessionId(sessionId);
    }
    return globalInfo;
}

From source file:com.huateng.ebank.business.common.GlobalInfo.java

public static GlobalInfo getFromRequest(HttpServletRequest request) throws CommonException {
    HttpSession httpSession = request.getSession();
    GlobalInfo globalInfo = (GlobalInfo) httpSession.getAttribute(GlobalInfo.KEY_GLOBAL_INFO);

    if (log.isDebugEnabled()) {
        log.debug("session id = " + httpSession.getId());
    }//from   ww  w  .j a  v  a 2s .  c  o m

    if (null != globalInfo) {
        setCurrentInstance(globalInfo);
        String oldSessionId = globalInfo.getSessionId();
        String sessionId = httpSession.getId();
        if (!sessionId.equals(oldSessionId)) {
            ExceptionUtil.throwCommonException("???, ?.",
                    ErrorCode.ERROR_CODE_TLRNO_SESSION_BINDED);
        }
        globalInfo.setSessionId(sessionId);
    }
    return globalInfo;
}