List of usage examples for javax.servlet.http Cookie getName
public String getName()
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); }//from w w w .java2 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)) { 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.ctc.storefront.filters.CartRestorationFilter.java
protected void processRestoration(final HttpServletRequest request) { String cartGuid = null;//from w ww . j ava 2s. c o m 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) { if (LOG.isDebugEnabled()) { LOG.debug(e); } getSessionService().setAttribute(WebConstants.CART_RESTORATION_ERROR_STATUS, WebConstants.CART_RESTORATION_ERROR_STATUS); } } }
From source file:AIR.Common.Web.Session.MultiValueCookie.java
public MultiValueCookie(Cookie cookie) { this._name = cookie.getName(); //Shiva: we can limit the code to the else part rather than have //the "if" part as well. The if part is there just for safety. if (StringUtils.isEmpty(cookie.getPath())) this._path = Server.getContextPath(); else//from w w w .j a v a 2 s.c om this._path = cookie.getPath(); this._comment = cookie.getComment(); this._domain = cookie.getDomain(); this._isSecure = cookie.getSecure(); this._encodedValue = cookie.getValue(); this._cookie = cookie; deserializeCookieValue(); }
From source file:de.appsolve.padelcampus.filter.LoginFilter.java
/** * @param request// w ww . j av a2s .c om * @param response * @param chain * @throws java.io.IOException * @throws javax.servlet.ServletException * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String requestURI = httpRequest.getRequestURI(); for (Pattern pattern : NO_FILTER_LIST) { if (pattern.matcher(requestURI).matches()) { sessionUtil.setCustomer(httpRequest, null); chain.doFilter(request, response); return; } } CustomerI customer = sessionUtil.getCustomer(httpRequest); if (customer == null) { String hostHeader = httpRequest.getHeader("host"); if (!StringUtils.isEmpty(hostHeader)) { String[] hostHeaderSplit = hostHeader.split(":"); customer = customerDAO.findByDomainName(hostHeaderSplit[0]); } if (customer == null) { String url = ""; String serverName = httpRequest.getServerName(); if (!StringUtils.isEmpty(serverName)) { String[] domainParts = serverName.split("\\."); if (domainParts.length > 2) { url = httpRequest.getScheme() + "://" + domainParts[domainParts.length - 2] + "." + domainParts[domainParts.length - 1]; if (httpRequest.getScheme().equals("http") && httpRequest.getServerPort() != 80) { url += ":" + httpRequest.getServerPort(); } } } url += PATH_START_PAGE; httpResponse.setStatus(HttpStatus.PERMANENT_REDIRECT.value()); httpResponse.sendRedirect(url); return; } sessionUtil.setCustomer(httpRequest, customer); } //login user in case of valid login cookie Player user = sessionUtil.getUser(httpRequest); if (user == null) { Cookie[] cookies = httpRequest.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName() != null && cookie.getName().equals(COOKIE_LOGIN_TOKEN)) { String cookieValue = cookie.getValue(); if (StringUtils.isEmpty(cookieValue)) { loginUtil.deleteLoginCookie(httpRequest, httpResponse); } else { String[] cookieValueSplit = cookieValue.split(":"); if (cookieValueSplit.length != 2) { loginUtil.deleteLoginCookie(httpRequest, httpResponse); } else { String uuid = cookieValueSplit[0]; String loginCookieRandomValue = cookieValueSplit[1]; LoginCookie loginCookie = loginUtil.isValidLoginCookie(uuid, loginCookieRandomValue); if (loginCookie == null) { loginUtil.deleteLoginCookie(httpRequest, httpResponse); } else { Player player = playerDAO.findByUUID(loginCookie.getPlayerUUID()); if (player == null) { loginUtil.deleteLoginCookie(httpRequest, httpResponse); } else { //log user in sessionUtil.setUser(httpRequest, player); //update loginCookieHash loginUtil.updateLoginCookie(httpRequest, httpResponse); } } break; } } } } } } moduleUtil.initModules(httpRequest); } chain.doFilter(request, response); }
From source file:org.dspace.webmvc.theme.ThemeChangeInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request); if (themeResolver == null) { throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?"); }/*from w w w . ja va 2 s . c o m*/ String newTheme = request.getParameter(this.paramName); if (newTheme != null) { themeResolver.setThemeName(request, response, newTheme); response.addCookie(new Cookie("themeName", newTheme)); } else { ThemeMapEntry bestMatch = null; for (ThemeMapEntry entry : themeMappings) { if (entry.mapType == MapType.VIEW || entry.mapType == MapType.ANY) { if (modelAndView != null && pathMatcher.match(entry.path, modelAndView.getViewName())) { if (entry.isBestMatch(bestMatch)) { bestMatch = entry; } } } if (entry.mapType == MapType.URL || entry.mapType == MapType.ANY) { String path = urlPathHelper.getLookupPathForRequest(request); if (pathMatcher.match(entry.path, path)) { if (entry.isBestMatch(bestMatch)) { bestMatch = entry; } } } if (entry.mapType == MapType.CONTROLLER || entry.mapType == MapType.ANY) { } } if (bestMatch != null) { themeResolver.setThemeName(request, response, bestMatch.themeName); } else if (request.getCookies() != null) { for (Cookie cookie : request.getCookies()) { if ("themeName".equals(cookie.getName())) { themeResolver.setThemeName(request, response, cookie.getValue()); } } } } super.postHandle(request, response, handler, modelAndView); }
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); }/* w w w .j a v a2s. com*/ } } } } 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); }//from w w w . 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: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 va2 s . co m 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.mitre.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 w w w. j ava 2s . co m*/ } } } } if (redirect) { final String ajaxHeader = request.getHeader(ajaxRequestHeaderKey); LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie") + ", redirecting"); if (ajaxRequestHeaderValue.equals(ajaxHeader)) { response.addHeader("redirectUrl", request.getContextPath() + getRedirectUrl(request)); response.sendError(Integer.parseInt(ajaxRedirectErrorCode)); } else { getRedirectStrategy().sendRedirect(request, response, getRedirectUrl(request)); } return false; } } } return true; }
From source file:jp.co.opentone.bsol.linkbinder.view.filter.LoginFilter.java
private boolean hasJsessionId(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie c : cookies) { if (c.getName() != null && c.getName().equals(JSESSIONID)) { return true; }/*from w ww.j a v a2s. c o m*/ } } return false; }