Example usage for javax.servlet.http HttpServletRequest getSession

List of usage examples for javax.servlet.http HttpServletRequest getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getSession.

Prototype

public HttpSession getSession();

Source Link

Document

Returns the current session associated with this request, or if the request does not have a session, creates one.

Usage

From source file:com.imaginea.mongodb.controllers.BaseController.java

/**
 * Validates connectionId with the connectionId Array present in session.
 *
 * @param connectionId Mongo Db config information provided to user at time of login.
 * @param logger       Logger to write error message to
 * @param request      Request made by client containing session attributes.
 * @return null if connectionId is valid else error object.
 *///from  w w  w  . j  a v a 2  s  .  com
protected static String validateConnectionId(String connectionId, Logger logger, HttpServletRequest request) {

    HttpSession session = request.getSession();
    Set<String> existingConnectionIdsInSession = (Set<String>) session
            .getAttribute("existingConnectionIdsInSession");
    if (existingConnectionIdsInSession == null) {
        InvalidHTTPRequestException e = new InvalidHTTPRequestException(ErrorCodes.INVALID_SESSION,
                "Invalid Session");
        return formErrorResponse(logger, e);
    }

    String response = null;
    if (connectionId == null || !existingConnectionIdsInSession.contains(connectionId)) {
        InvalidHTTPRequestException e = new InvalidHTTPRequestException(ErrorCodes.INVALID_CONNECTION,
                "Invalid Connection");
        return formErrorResponse(logger, e);
    }
    return response;
}

From source file:io.lavagna.web.security.CSFRFilter.java

private static ImmutablePair<Boolean, ImmutablePair<Integer, String>> checkCSRF(HttpServletRequest request)
        throws IOException {
    String expectedToken = (String) request.getSession().getAttribute(CSRFToken.CSRF_TOKEN);
    String token = request.getHeader(CSRF_TOKEN_HEADER);
    if (token == null) {
        token = request.getParameter(CSRF_FORM_PARAMETER);
    }// w ww.ja  va 2s  . c o  m

    if (token == null) {
        return of(false, of(HttpServletResponse.SC_FORBIDDEN, "missing token in header or parameter"));
    }
    if (expectedToken == null) {
        return of(false, of(HttpServletResponse.SC_FORBIDDEN, "missing token from session"));
    }
    if (!safeArrayEquals(token.getBytes("UTF-8"), expectedToken.getBytes("UTF-8"))) {
        return of(false, of(HttpServletResponse.SC_FORBIDDEN, "token is not equal to expected"));
    }

    return of(true, null);
}

From source file:com.benfante.taglib.frontend.utils.FlashHelper.java

public static void doSetRedirect(HttpServletRequest req, String code, String type, String attribute) {
    Map<String, String> flash = (Map<String, String>) req.getSession().getAttribute(attribute);
    if (flash == null)
        flash = new HashMap<String, String>();
    if (type == null) {
        type = DEFAULT_ERROR_TYPE;//from   w ww  .  j  a  v a2 s  .co  m
    }
    if (attribute == null) {
        attribute = DEFAULT_FLASH_ATTRIBUTE;
    }
    flash.put(type, code);
    req.getSession().setAttribute(attribute, flash);
}

From source file:cn.vlabs.duckling.vwb.ui.accclb.AttSaver.java

private static String getMimeType(HttpServletRequest req, String fileName) {
    String mimetype = null;//from   ww w  .  j a v a  2  s.c om

    if (req != null) {
        ServletContext s = req.getSession().getServletContext();

        if (s != null) {
            mimetype = s.getMimeType(fileName.toLowerCase());
        }
    }

    if (mimetype == null) {
        mimetype = "application/binary";
    }

    return mimetype;
}

From source file:io.lavagna.web.helper.UserSession.java

public static User getCurrentUser(HttpServletRequest req, UserRepository userRepository) {
    Object o = req.getSession().getAttribute(AUTH_USER_ID);
    User user = userRepository.findById((int) o);
    return user;//from w ww .j a  v  a  2 s .  c o m
}

From source file:net.duckling.ddl.util.PictureCheckCodeUtil.java

/**
 * ?request?????????/*from   w w  w  .  j ava  2 s  . co  m*/
 * @param request
 * @param code
 * @param type
 * @param reflesh true typesession??false?
 * @return
 */
public static boolean checkCode(HttpServletRequest request, String code, String type, boolean reflesh) {
    if (StringUtils.isEmpty(type) || StringUtils.isEmpty(code)) {
        return false;
    }
    String c = (String) request.getSession().getAttribute(type);
    if (!StringUtils.isEmpty(c) && c.equalsIgnoreCase(code)) {
        if (reflesh) {
            request.getSession().removeAttribute(type);
        }
        return true;
    } else {
        request.getSession().removeAttribute(type);
        return false;
    }

}

From source file:net.shibboleth.idp.oidc.util.OIDCUtils.java

/**
 * Remove session parameter./*from  ww w  .  ja  v  a 2s .  c  o  m*/
 *
 * @param request   the request
 * @param parameter the parameter
 */
public static void removeSessionAttribute(final HttpServletRequest request, final String parameter) {
    final HttpSession session = request.getSession();
    session.removeAttribute(parameter);
}

From source file:net.shibboleth.idp.oidc.util.OIDCUtils.java

/**
 * Gets session attribute.//ww  w .jav  a2s. c o m
 *
 * @param request   the request
 * @param parameter the parameter
 * @return the session attribute
 */
public static Object getSessionAttribute(final HttpServletRequest request, final String parameter) {
    final HttpSession session = request.getSession();
    return session.getAttribute(parameter);
}

From source file:org.apache.cxf.fediz.service.idp.util.WebUtils.java

public static HttpSession getHttpSession(final RequestContext context) {
    HttpServletRequest httpServletRequest = getHttpServletRequest(context);
    return httpServletRequest.getSession();
}

From source file:com.vangent.hieos.DocViewer.server.framework.ServletUtilMixin.java

/**
 * //from w ww  . jav a  2 s . co  m
 * @param request
 */
static public void invalidateSession(HttpServletRequest request) {
    // Get session and invalidate.
    HttpSession session = request.getSession();
    session.invalidate();
}