List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:com.exxonmobile.ace.hybris.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java
@Override public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response, final HandlerMethod handler) throws Exception { // We only care if the request is secure if (request.isSecure()) { // Check if the handler has our annotation final RequireHardLogIn annotation = findAnnotation(handler, RequireHardLogIn.class); if (annotation != null) { boolean redirect = true; final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY); final boolean anonymousUser = getUserService().isAnonymousUser(getUserService().getCurrentUser()); if (!anonymousUser && guid != null && request.getCookies() != null) { final String guidCookieName = getCookieGenerator().getCookieName(); if (guidCookieName != null) { for (final Cookie cookie : request.getCookies()) { if (guidCookieName.equals(cookie.getName())) { if (guid.equals(cookie.getValue())) { redirect = false; break; } else { LOG.info("Found secure cookie with invalid value. expected [" + guid + "] actual [" + cookie.getValue() + "]. removing."); getCookieGenerator().removeCookie(response); }/*from ww w .ja va 2 s . co m*/ } } } } if (redirect) { LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie") + ", redirecting"); getRedirectStrategy().sendRedirect(request, response, getRedirectUrl(request)); return false; } } } return true; }
From source file:com.redhat.rhn.frontend.servlets.test.PxtSessionDelegateImplTest.java
private Cookie getPxtCookieWithInvalidSessionKey() { Cookie pxtCookie = getPxtCookie(); String key = pxtCookie.getValue(); key = key.replace('x', ':'); pxtCookie.setValue(key);/*from ww w . j a v a2 s .c om*/ return pxtCookie; }
From source file:nl.surfnet.coin.teams.interceptor.LoginInterceptor.java
private String getTeamsCookie(HttpServletRequest request) { String result = ""; Cookie[] cookies = request.getCookies(); if (null != cookies) { for (Cookie current : cookies) { if (current.getName().equals(TEAMS_COOKIE)) { result = current.getValue(); break; }//from w w w.ja v a 2s. c om } } return result; }
From source file:io.lightlink.servlet.JsMethodsDefinitionServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/javascript"); resp.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); resp.setHeader("Pragma", "no-cache"); resp.setDateHeader("Expires", 0); Cookie[] cookies = req.getCookies(); String debugMethods = ""; for (int i = 0; cookies != null && i < cookies.length; i++) { Cookie cookie = cookies[i]; if ("lightlink.debug".equalsIgnoreCase(cookie.getName())) debugMethods = cookie.getValue(); }/*from w w w .ja v a 2s . c om*/ PrintWriter writer = resp.getWriter(); writer.print(getDeclarationScript(debugMethods, req)); if (StringUtils.isNotEmpty(debugMethods) && ConfigManager.isInDebugMode()) { writer.print("\n// DEBUG PART \n"); writer.print("\n\n /***** io/lightlink/core/sqlFunctions.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/sqlFunctions.js")); writer.print("\n\n /***** io/lightlink/core/debugProxy.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/debugProxy.js")); writer.print("\n\n /***** io/lightlink/core/LightLinkDebugSession.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/LightLinkDebugSession.js")); } if (ConfigManager.isInDebugMode()) { writer.print("\n\n /***** io/lightlink/core/IDDQD.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/IDDQD.js")); } writer.print("\n" + "LL.JsApi.CSRF_Token = '" + CSRFTokensContainer.getInstance(req.getSession()).createNewToken() + "'\n"); writer.close(); resp.flushBuffer(); }
From source file:com.acc.storefront.filters.CartRestorationFilter.java
@Override public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws IOException, ServletException { if (getUserService().isAnonymousUser(getUserService().getCurrentUser())) { if (getCartFacade().hasSessionCart() && getBaseSiteService().getCurrentBaseSite() .equals(getBaseSiteService().getBaseSiteForUID(getCartFacade().getSessionCart().getSite()))) { final String guid = getCartFacade().getSessionCart().getGuid(); if (!StringUtils.isEmpty(guid)) { getCartRestoreCookieGenerator().addCookie(response, guid); }/* w w w.j a v a 2s . c o m*/ } else if (request.getSession().isNew() || (getCartFacade().hasSessionCart() && !getBaseSiteService().getCurrentBaseSite().equals( getBaseSiteService().getBaseSiteForUID(getCartFacade().getSessionCart().getSite())))) { String cartGuid = null; if (request.getCookies() != null) { final String anonymousCartCookieName = getCartRestoreCookieGenerator().getCookieName(); for (final Cookie cookie : request.getCookies()) { if (anonymousCartCookieName.equals(cookie.getName())) { cartGuid = cookie.getValue(); break; } } } if (!StringUtils.isEmpty(cartGuid)) { try { getSessionService().setAttribute(WebConstants.CART_RESTORATION, getCartFacade().restoreSavedCart(cartGuid)); } catch (final CommerceCartRestorationException e) { getSessionService().setAttribute(WebConstants.CART_RESTORATION, "basket.restoration.errorMsg"); } } } } else { if ((!getCartFacade().hasSessionCart() && getSessionService().getAttribute(WebConstants.CART_RESTORATION) == null) || (getCartFacade().hasSessionCart() && !getBaseSiteService().getCurrentBaseSite().equals( getBaseSiteService().getBaseSiteForUID(getCartFacade().getSessionCart().getSite())))) { try { getSessionService().setAttribute(WebConstants.CART_RESTORATION, getCartFacade().restoreSavedCart(null)); } catch (final CommerceCartRestorationException e) { getSessionService().setAttribute(WebConstants.CART_RESTORATION, "basket.restoration.errorMsg"); } } } filterChain.doFilter(request, response); }
From source file:com.hypersocket.session.json.SessionUtils.java
public Locale getLocale(HttpServletRequest request) { if (request.getSession().getAttribute(USER_LOCALE) == null) { Cookie[] cookies = request.getCookies(); for (Cookie c : cookies) { if (c.getName().equals(HYPERSOCKET_LOCALE)) { return new Locale(c.getValue()); }/* w w w . ja v a2 s .c om*/ } return configurationService.getDefaultLocale(); } else { return new Locale((String) request.getSession().getAttribute(USER_LOCALE)); } }
From source file:controllers.Parent_Controller.java
public int checkSetCookie(HttpServletRequest request) { cookies = request.getCookies();/*from w w w . jav a 2 s. c om*/ int countcookies = 0; for (Cookie cookie1 : cookies) { switch (cookie1.getName()) { case "handle": System.out.println("Got Handle cookie"); handle = cookie1.getValue(); countcookies++; break; case "uid": System.out.println("Got uid cookie"); uid = Integer.parseInt(cookie1.getValue()); countcookies++; break; } } if (countcookies == 0) { return 0; } else { cookiesSet = true; return 2; } }
From source file:com.acc.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java
protected boolean checkForGUIDCookie(final HttpServletRequest request, final HttpServletResponse response, final String guid) { if (guid != null && request.getCookies() != null) { final String guidCookieName = getCookieGenerator().getCookieName(); if (guidCookieName != null) { for (final Cookie cookie : request.getCookies()) { if (guidCookieName.equals(cookie.getName())) { if (guid.equals(cookie.getValue())) { return true; } else { LOG.info("Found secure cookie with invalid value. expected [" + guid + "] actual [" + cookie.getValue() + "]. removing."); getCookieGenerator().removeCookie(response); }/*from w w w .j a v a 2 s .c o m*/ } } } } return false; }
From source file:de.hybris.alantrails.storefront.filters.CartRestorationFilter.java
@Override public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws IOException, ServletException { if (getUserService().isAnonymousUser(getUserService().getCurrentUser())) { if (getCartFacade().hasSessionCart() && getBaseSiteService().getCurrentBaseSite() .equals(getBaseSiteService().getBaseSiteForUID(getCartFacade().getSessionCart().getSite()))) { final String guid = getCartFacade().getSessionCart().getGuid(); if (!StringUtils.isEmpty(guid)) { getCartRestoreCookieGenerator().addCookie(response, guid); }/*w ww . j a v a 2 s .c o m*/ } else if (request.getSession().isNew() || (getCartFacade().hasSessionCart() && !getBaseSiteService().getCurrentBaseSite().equals( getBaseSiteService().getBaseSiteForUID(getCartFacade().getSessionCart().getSite())))) { String cartGuid = null; if (request.getCookies() != null) { final String anonymousCartCookieName = getCartRestoreCookieGenerator().getCookieName(); for (final Cookie cookie : request.getCookies()) { if (anonymousCartCookieName.equals(cookie.getName())) { cartGuid = cookie.getValue(); break; } } } if (!StringUtils.isEmpty(cartGuid)) { getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE); try { getSessionService().setAttribute(WebConstants.CART_RESTORATION, getCartFacade().restoreSavedCart(cartGuid)); } catch (final CommerceCartRestorationException e) { getSessionService().setAttribute(WebConstants.CART_RESTORATION_ERROR_STATUS, WebConstants.CART_RESTORATION_ERROR_STATUS); } } } } else { if ((!getCartFacade().hasSessionCart() && getSessionService().getAttribute(WebConstants.CART_RESTORATION) == null) || (getCartFacade().hasSessionCart() && !getBaseSiteService().getCurrentBaseSite().equals( getBaseSiteService().getBaseSiteForUID(getCartFacade().getSessionCart().getSite())))) { getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE); try { getSessionService().setAttribute(WebConstants.CART_RESTORATION, getCartFacade().restoreSavedCart(null)); } catch (final CommerceCartRestorationException e) { getSessionService().setAttribute(WebConstants.CART_RESTORATION, WebConstants.CART_RESTORATION_ERROR_STATUS); } } } filterChain.doFilter(request, response); }
From source file:com.ctc.storefront.filters.CustomerLocationRestorationFilter.java
protected void setUserLocationDataFromCookies(final Cookie[] cookies) { for (final Cookie cookie : cookies) { if (getCustomerLocationCookieGenerator().getCookieName().equals(cookie.getName())) { final UserLocationData cookieUserLocationData = decipherUserLocationData( StringUtils.remove(cookie.getValue(), "\"")); getCustomerLocationFacade().setUserLocationData(cookieUserLocationData); break; }/*from w w w . jav a2 s . c o m*/ } }