List of usage examples for javax.servlet.http HttpServletRequest getCookies
public Cookie[] getCookies();
Cookie
objects the client sent with this request. 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];//from w w w .ja v a 2s. c om if ("lightlink.debug".equalsIgnoreCase(cookie.getName())) debugMethods = cookie.getValue(); } 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:org.apache.atlas.web.filters.AtlasKnoxSSOAuthenticationFilter.java
/** * Encapsulate the acquisition of the JWT token from HTTP cookies within the * request.// www . ja v a 2 s . c o m * * @param req servlet request to get the JWT token from * @return serialized JWT token */ protected String getJWTFromCookie(HttpServletRequest req) { String serializedJWT = null; Cookie[] cookies = req.getCookies(); if (cookieName != null && cookies != null) { for (Cookie cookie : cookies) { if (cookieName.equals(cookie.getName())) { if (LOG.isDebugEnabled()) { LOG.debug("{} cookie has been found and is being processed", cookieName); } serializedJWT = cookie.getValue(); break; } } } return serializedJWT; }
From source file:com.epam.training.storefront.interceptors.beforecontroller.SecureRequestCookieCheckBeforeControllerHandler.java
@Override public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response) throws Exception //NOPMD { final String path = getUrlPathHelper().getServletPath(request); if (request.isSecure() && !getExcludeUrls().contains(path)) { boolean redirect = true; final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY); 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())) { redirect = false; break; } else { LOG.info("Found secure cookie with invalid value. expected [" + guid + "] actual [" + cookie.getValue() + "]. removing."); getCookieGenerator().removeCookie(response); }/*from ww w.j a va 2 s . c om*/ } } } } if (redirect) { LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie") + ", redirecting"); getRedirectStrategy().sendRedirect(request, response, getLoginUrl()); return false; } } return true; }
From source file:com.epam.cme.storefront.interceptors.beforecontroller.SecureRequestCookieCheckBeforeControllerHandler.java
@Override public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response) throws Exception // NOPMD { final String path = getUrlPathHelper().getServletPath(request); if (request.isSecure() && !getExcludeUrls().contains(path)) { boolean redirect = true; final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY); 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())) { 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 av a2 s . c om } } } } if (redirect) { LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie") + ", redirecting"); getRedirectStrategy().sendRedirect(request, response, getLoginUrl()); return false; } } return true; }
From source file:controllers.UrlController.java
@RequestMapping(value = "/logout", method = RequestMethod.GET) public String logout(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies2 = request.getCookies(); user_detail = null;// w w w .j a va2 s . co m if (cookies2 != null) { for (Cookie cookie : cookies2) { cookie.setValue(null); cookie.setMaxAge(0); response.addCookie(cookie); } } return "index"; }
From source file:hudson.plugins.timestamper.TimestampFormatterTest.java
private MarkupText markup(MarkupText markupText) { HttpServletRequest request = mock(HttpServletRequest.class); Cookie[] cookies = null;/*from w w w .j a va2 s . c om*/ if (cookieValues != null) { cookies = new Cookie[cookieValues.size()]; for (int i = 0; i < cookieValues.size(); i++) { cookies[i] = new Cookie("jenkins-timestamper", cookieValues.get(i)); } } when(request.getCookies()).thenReturn(cookies); TimestampFormatter formatter = new TimestampFormatter("HH:mm:ss ", "ss.S ", request); if (serialize) { formatter = (TimestampFormatter) SerializationUtils.clone(formatter); } formatter.markup(markupText, new Timestamp(123, 42000)); return markupText; }
From source file:org.akaza.openclinica.control.MainMenuServlet.java
public String getQueryStrCookie(HttpServletRequest request, HttpServletResponse response) { String queryStr = ""; Cookie[] cookies = request.getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equalsIgnoreCase("queryStr")) { try { queryStr = URLDecoder.decode(cookie.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("Error decoding redirect URL from queryStr cookie:" + e.getMessage()); }//from ww w . j a va2 s . com cookie.setValue(null); cookie.setMaxAge(0); cookie.setPath("/"); if (response != null) response.addCookie(cookie); break; } } return queryStr; }
From source file:com.google.gsa.valve.modules.noauth.HTTPNoAuthenticationProcess.java
/** * This method simulates the authentication process against a content * source, so that every document is consider here as public. * <p>//from w ww . ja v a 2 s .c o m * Creates the authentication cookie and always return 200, unless there is * any problem processing the request. * * @param request HTTP request * @param response HTTP response * @param authCookies vector that contains the authentication cookies * @param url the document url * @param creds an array of credentials for all external sources * @param id the default credential id to be retrieved from creds * @return the HTTP error code * @throws HttpException * @throws IOException */ public int authenticate(HttpServletRequest request, HttpServletResponse response, Vector<Cookie> authCookies, String url, Credentials creds, String id) throws HttpException, IOException { Cookie[] cookies = null; // Initialize status code int statusCode = HttpServletResponse.SC_UNAUTHORIZED; // Read cookies cookies = request.getCookies(); // Debug logger.debug("HTTP No authentication start"); // // Launch the authentication process // // Protection try { Cookie extAuthCookie = null; extAuthCookie = new Cookie("gsa_basic_noauth", ""); extAuthCookie.setValue("true"); String authCookieDomain = null; String authCookiePath = null; int authMaxAge = -1; // Cache cookie properties authCookieDomain = (request.getAttribute("authCookieDomain")).toString(); authCookiePath = (request.getAttribute("authCookiePath")).toString(); //authMaxAge try { authMaxAge = Integer.parseInt(valveConf.getAuthMaxAge()); } catch (NumberFormatException nfe) { logger.error( "Configuration error: chack the configuration file as the number set for authMaxAge is not OK:"); } // Set extra cookie parameters extAuthCookie.setDomain(authCookieDomain); extAuthCookie.setPath(authCookiePath); extAuthCookie.setMaxAge(authMaxAge); // Log info if (logger.isDebugEnabled()) logger.debug("Adding gsa_basic_noauth cookie: " + extAuthCookie.getName() + ":" + extAuthCookie.getValue() + ":" + extAuthCookie.getPath() + ":" + extAuthCookie.getDomain() + ":" + extAuthCookie.getSecure()); //add sendCookies support boolean isSessionEnabled = new Boolean(valveConf.getSessionConfig().isSessionEnabled()).booleanValue(); boolean sendCookies = false; if (isSessionEnabled) { sendCookies = new Boolean(valveConf.getSessionConfig().getSendCookies()).booleanValue(); } if ((!isSessionEnabled) || ((isSessionEnabled) && (sendCookies))) { response.addCookie(extAuthCookie); } //add cookie to the array authCookies.add(extAuthCookie); statusCode = HttpServletResponse.SC_OK; } catch (Exception e) { // Log error logger.error("HTTP Basic authentication failure: " + e.getMessage(), e); // Update status code statusCode = HttpServletResponse.SC_UNAUTHORIZED; } // End of the authentication process logger.debug("HTTP No Authentication completed (" + statusCode + ")"); // Return status code return statusCode; }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * ?cookie// w w w . j a v a 2 s . c o m * * @param req * * @param names * cookie?? */ public static void purgeCookies(HttpServletRequest req, HttpServletResponse resp, String... names) { Set<String> nameSet = ValidationUtils.isEmpty(names) ? null : new HashSet<String>(Arrays.asList(names)); boolean removeAll = ValidationUtils.isEmpty(nameSet); for (Cookie cookie : req.getCookies()) { if (removeAll || nameSet.contains(cookie.getName())) { cookie.setMaxAge(0); cookie.setValue(null); resp.addCookie(cookie); if (!removeAll) nameSet.remove(cookie.getName()); ; } } }
From source file:com.hangum.tadpole.login.core.dialog.LoginDialog.java
/** * initialize cookie data// w w w . ja va 2s . c o m */ private void initCookieData() { HttpServletRequest request = RWT.getRequest(); Cookie[] cookies = request.getCookies(); if (cookies != null) { int intCount = 0; for (Cookie cookie : cookies) { if (PublicTadpoleDefine.TDB_COOKIE_USER_ID.equals(cookie.getName())) { textEMail.setText(cookie.getValue()); intCount++; } else if (PublicTadpoleDefine.TDB_COOKIE_USER_SAVE_CKECK.equals(cookie.getName())) { btnCheckButton.setSelection(Boolean.parseBoolean(cookie.getValue())); intCount++; } else if (PublicTadpoleDefine.TDB_COOKIE_USER_LANGUAGE.equals(cookie.getName())) { Locale locale = Locale.forLanguageTag(cookie.getValue()); comboLanguage.setText(locale.getDisplayLanguage(locale)); changeUILocale(comboLanguage.getText()); intCount++; } if (intCount == 3) return; } } // ? ? . comboLanguage.select(0); changeUILocale(comboLanguage.getText()); }