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(boolean create);

Source Link

Document

Returns the current <code>HttpSession</code> associated with this request or, if there is no current session and <code>create</code> is true, returns a new session.

Usage

From source file:nl.conspect.legacy.user.web.LogoutController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    HttpSession session = request.getSession(false);
    if (session != null) {
        session.invalidate();/*from ww w.  j av a  2 s.c  om*/
    }
    return new ModelAndView("redirect:/app/index", Collections.singletonMap("msg", "Logout successful."));
}

From source file:org.lightadmin.core.web.security.LightAdminRequestCache.java

@Override
public SavedRequest getRequest(HttpServletRequest currentRequest, HttpServletResponse response) {
    HttpSession session = currentRequest.getSession(false);
    if (session != null) {
        return (DefaultSavedRequest) session.getAttribute(savedRequestKey);
    }/*  w ww .  j  a v  a  2 s.com*/
    return null;
}

From source file:org.lightadmin.core.web.security.LightAdminRequestCache.java

@Override
public void removeRequest(HttpServletRequest currentRequest, HttpServletResponse response) {
    HttpSession session = currentRequest.getSession(false);
    if (session != null) {
        logger.debug("Removing DefaultSavedRequest from session if present");
        session.removeAttribute(savedRequestKey);
    }// ww w.  jav  a 2  s. c  o  m
}

From source file:edu.zipcloud.cloudstreetmarket.api.controllers.SessionController.java

@RequestMapping(value = "/current", method = GET)
@ApiOperation(value = "Get the session Id of the current user")
public String getCurrent(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session != null) {
        return session.getId();
    }//from   w ww.  j a  v a2  s.com
    return "";
}

From source file:com.liferay.portal.util.PortalUtil.java

public static String getUserId(HttpServletRequest req) {
    return getUserId(req.getSession(false));
}

From source file:edu.mum.waa.webstore.controller.CartRestController.java

@RequestMapping(value = "/add/{productId}", method = RequestMethod.PUT)
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void addIItem(@PathVariable String productId, HttpServletRequest request) {
    String sessionId = request.getSession(true).getId();
    Cart cart = cartService.read(sessionId);
    if (cart == null) {
        cart = cartService.create(new Cart(sessionId));
    }//from   w  w w.j a  v a  2  s .c om

    Product product = productService.getProductById(productId);
    if (product == null) {
        throw new IllegalArgumentException(String.format("Product with id (%) not found", productId));
    }

    cart.addCartItem(new CartItem(product));
    cartService.update(sessionId, cart);
}

From source file:com.ec2box.common.interceptor.CSRFInterceptor.java

@Override
protected String handleToken(ActionInvocation invocation) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession(true);
    synchronized (session) {
        String sessionToken = (String) session.getAttribute(AuthUtil.CSRF_TOKEN_NM);
        String token = request.getParameter(AuthUtil.CSRF_TOKEN_NM);
        if (StringUtils.isEmpty(token) || StringUtils.isEmpty(sessionToken) || !token.equals(sessionToken)) {
            AuthUtil.deleteAllSession(session);
            return this.handleInvalidToken(invocation);
        }//ww w .j  av a 2 s. c om

        //generate new token upon post
        if ("POST".equals(request.getMethod()) && !request.getContentType().contains("multipart/form-data")) {
            AuthUtil.generateCSRFToken(session);
        }
    }

    return this.handleValidToken(invocation);
}

From source file:edu.mum.waa.webstore.controller.CartRestController.java

@RequestMapping(value = "/remove/{productId}", method = RequestMethod.PUT)
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void removeItem(@PathVariable String productId, HttpServletRequest request) {
    String sessionId = request.getSession(true).getId();
    Cart cart = cartService.read(sessionId);

    if (cart == null) {
        cartService.create(new Cart(sessionId));
    }//from   ww  w  .j  a  v  a  2s .c om

    Product product = productService.getProductById(productId);
    if (product == null) {
        throw new IllegalArgumentException(String.format("Product with id (%) not found", productId));
    }

    cart.removeCartItem(new CartItem(product));
    cartService.update(sessionId, cart);
}

From source file:com.exilant.exility.core.HttpRequestHandler.java

/**
 * populate data with global/session variables, if this is an authenticated
 * session. Caller can have the CommonFieldNames.CSRF_HEADER token either in
 * the header, or a field already extracted into inData
 * /* w w  w.  j a  v a 2  s.co m*/
 * @param req
 * @param inData
 *            into which session fields need to be extracted
 * @return true if this is an authenticated session, false otherwise
 */
public static boolean extractSessionFields(HttpServletRequest req, ServiceData inData) {
    String token = req.getHeader(CommonFieldNames.CSRF_HEADER);
    if (token == null) {
        token = inData.getValue(CommonFieldNames.CSRF_HEADER);
    }

    if (token == null || token.length() == 0) {
        return false;
    }

    HttpSession session = req.getSession(false);
    if (session == null) {
        return false;
    }

    Object obj = session.getAttribute(token);
    if (obj == null) {
        return false;
    }

    if (obj instanceof SessionData == false) {
        return false;
    }
    ((SessionData) obj).extractAll(inData);
    return true;
}

From source file:com.inkubator.sms.gateway.util.SpringSecurityContextListenerFix.java

@Override
public void requestInitialized(ServletRequestEvent requestEvent) {
    super.requestInitialized(requestEvent);
    HttpServletRequest request = (HttpServletRequest) requestEvent.getServletRequest();
    HttpSession sesion = request.getSession(false);
    Locale idioma;/*from  w  ww. ja  v a2 s.  c  om*/
    if (sesion != null) {
        //            System.out.println(sesion.getAttribute(HRMConstant.BAHASA_ACTIVE).toString());
        if (sesion.getAttribute(SMSGATEWAY.BAHASA_ACTIVE) != null) {
            idioma = new Locale(sesion.getAttribute(SMSGATEWAY.BAHASA_ACTIVE).toString());
        } else {
            idioma = new Locale("in");
        }
        LocaleContextHolder.setLocale(idioma);
    } else {
        idioma = new Locale("in");
        LocaleContextHolder.setLocale(idioma);
    }
}