List of usage examples for javax.servlet.http HttpServletResponse addCookie
public void addCookie(Cookie cookie);
From source file:fr.mby.portal.coreimpl.session.MemorySessionManager.java
@Override public void destroySessions(final HttpServletRequest request, final HttpServletResponse response) { final String portalSessionId = this.getPortalSessionId(request); if (portalSessionId != null) { final SessionBucket sessionBucket = this.sessionBucketCache.remove(portalSessionId); sessionBucket.destroy();/*from w ww .ja v a 2 s .c om*/ final Cookie portalSessionCookie = new Cookie(IPortal.PORTAL_SESSION_ID_COOKIE_NAME, "SESSION_DESTROYED"); portalSessionCookie.setPath("/"); response.addCookie(portalSessionCookie); this.generatedSessionIds.remove(portalSessionId); } }
From source file:com.nkapps.billing.services.SearchServiceImpl.java
@Override public String execSearchWithinDate(HttpServletRequest request, HttpServletResponse response) { Cookie sbtCookie = null;//from w w w .j a v a 2s . c o m String searchWithinDate = request.getParameter("searchWithinDate"); if (searchWithinDate == null) { Cookie[] requestCookies = request.getCookies(); for (Cookie c : requestCookies) { if (c.getName().equals("searchWithinDate")) { sbtCookie = c; } } if (sbtCookie != null) { searchWithinDate = sbtCookie.getValue(); } else { searchWithinDate = "true"; } } else { sbtCookie = new Cookie("searchWithinDate", searchWithinDate); sbtCookie.setPath("/"); response.addCookie(sbtCookie); } return searchWithinDate; }
From source file:eu.supersede.fe.security.SecurityConfiguration.java
private Filter csrfHeaderFilter() { return new OncePerRequestFilter() { @Override/*from w ww . j a v a 2 s . com*/ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN"); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie); } } try { filterChain.doFilter(request, response); } catch (IOException e) { if (!csrf_error) { log.warn("Unable to apply the CSRF filter. This message will not be displayed again"); } else { csrf_error = true; } } } }; }
From source file:com.nkapps.billing.services.SearchServiceImpl.java
@Override public String execSearchBy(HttpServletRequest request, HttpServletResponse response) throws Exception { Cookie sbtCookie = null;/*from w w w.jav a 2s . co m*/ String searchBy = request.getParameter("searchBy"); if (searchBy == null) { Cookie[] requestCookies = request.getCookies(); for (Cookie c : requestCookies) { if (c.getName().equals("searchBy")) { sbtCookie = c; } } if (sbtCookie != null) { searchBy = URLDecoder.decode(sbtCookie.getValue(), "UTF-8"); } else { searchBy = ""; } } else { sbtCookie = new Cookie("searchBy", URLEncoder.encode(searchBy, "UTF-8")); sbtCookie.setPath("/"); response.addCookie(sbtCookie); } return searchBy; }
From source file:seava.j4e.web.controller.ui.extjs.AbstractUiExtjsController.java
/** * Resolve the user's current language from the cookie. * /*from w w w . j av a 2s .c o m*/ * @param request * @param response * @return * @throws Exception */ private String resolveLang(HttpServletRequest request, HttpServletResponse response) throws Exception { Cookie[] cookies = request.getCookies(); Cookie c = this.getCookie(cookies, Constants.COOKIE_NAME_LANG); if (c == null) { String value = this.getSettings().getParam(SysParam.CORE_DEFAULT_LANGUAGE.name()); c = this.createCookie(Constants.COOKIE_NAME_LANG, value, 60 * 60 * 24 * 365); response.addCookie(c); } String lang = request.getParameter(Constants.REQUEST_PARAM_LANG); if (lang == null || lang.equals("")) { lang = c.getValue(); } else { c.setMaxAge(0); c = this.createCookie(Constants.COOKIE_NAME_LANG, lang, 60 * 60 * 24 * 365); response.addCookie(c); } return lang; }
From source file:io.seldon.api.controller.JsPortholeController.java
/** * * @param request .../*from w w w . j a v a2 s.c o m*/ * @param response ... * @param localId if non-null, use this local id instead of generating a {@link UUID}. * Typically this will be used to propagate client-specific cookies where browser privacy issues have * blocked the server-side setting. * @return */ private String ensureCookie(HttpServletRequest request, HttpServletResponse response, String localId) { final Cookie[] cookies = request.getCookies(); String uuid = null; if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(RL_COOKIE_ID)) { uuid = cookie.getValue(); } } } if (uuid == null) { if (localId != null) { logger.info("Using local ID for porthole session: " + localId); uuid = localId; } else { uuid = UUID.randomUUID().toString(); } final Cookie cookie = new Cookie(RL_COOKIE_ID, uuid); cookie.setMaxAge(COOKIE_MAX_AGE); response.addCookie(cookie); response.addHeader("P3P", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""); } return uuid; }
From source file:com.google.youtube.captions.AuthSubLogout.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String username = Util.getCookie(req, Util.CURRENT_USERNAME); if (!Util.isEmptyOrNull(username)) { try {//w w w .ja v a 2 s .co m String authSubCookie = Util.getCookie(req, Util.AUTH_SUB_COOKIE); JSONObject cookieAsJSON = new JSONObject(authSubCookie); if (cookieAsJSON.has(username)) { String authSubToken = cookieAsJSON.getString(username); AuthSubUtil.revokeToken(authSubToken, null); cookieAsJSON.remove(username); Cookie cookie = new Cookie(Util.AUTH_SUB_COOKIE, cookieAsJSON.toString()); cookie.setMaxAge(Util.COOKIE_LIFETIME); resp.addCookie(cookie); cookie = new Cookie(Util.CURRENT_AUTHSUB_TOKEN, ""); cookie.setMaxAge(Util.COOKIE_LIFETIME); resp.addCookie(cookie); cookie = new Cookie(Util.CURRENT_USERNAME, ""); cookie.setMaxAge(Util.COOKIE_LIFETIME); resp.addCookie(cookie); } } catch (AuthenticationException e) { LOG.log(Level.WARNING, "", e); } catch (GeneralSecurityException e) { LOG.log(Level.WARNING, "", e); } catch (JSONException e) { LOG.log(Level.WARNING, "", e); } } resp.sendRedirect("/"); }
From source file:fr.paris.lutece.plugins.mylutece.modules.openam.service.OpenamService.java
/** * set a paris connect cokkie in the HttpServletResponse * * @param strPCUID/*from w w w. jav a 2s . c o m*/ * the user PCUID * @param response * The HTTP response */ public void setConnectionCookie(String strPCUID, HttpServletResponse response) { // set a connexion cookie to let the user access other PC Services // without sign in Cookie openamCookie = new Cookie(COOKIE_OPENAM_NAME, strPCUID); openamCookie.setDomain(COOKIE_OPENAM_DOMAIN); openamCookie.setSecure(COOKIE_OPENAM_SECURE); openamCookie.setMaxAge(COOKIE_OPENAM_MAX_AGE); openamCookie.setPath(COOKIE_OPENAM_PATH); response.addCookie(openamCookie); }
From source file:io.mapzone.controller.vm.http.LoginProvision.java
protected void registerUser(String userId, @SuppressWarnings("hiding") HttpServletResponse response) { // cookie token byte[] bytes = new byte[8]; rand.nextBytes(bytes);/*from w w w .ja v a 2s .c om*/ String token = Base64.encodeBase64URLSafeString(bytes); // FIXME Leak: entries are never removed (allow just one cookie/session per user?) if (loggedIn.putIfAbsent(token, userId) != null) { throw new IllegalStateException("Token already exists: " + token); } // set cookie Cookie newCookie = new Cookie(COOKIE_NAME, token); newCookie.setHttpOnly(true); newCookie.setPath(COOKIE_PATH); newCookie.setSecure(false); // XXX newCookie.setMaxAge(COOKIE_MAX_AGE); response.addCookie(newCookie); }
From source file:seava.j4e.web.controller.ui.extjs.AbstractUiExtjsController.java
/** * Resolve the user's current theme from the cookie. * //from w w w . j a v a 2s. c om * @param request * @param response * @return * @throws Exception */ private String resolveTheme(HttpServletRequest request, HttpServletResponse response) throws Exception { Cookie[] cookies = request.getCookies(); Cookie c = this.getCookie(cookies, Constants.COOKIE_NAME_THEME); if (c == null) { String value = this.getSettings().getParam(SysParam.CORE_DEFAULT_THEME_EXTJS.name()); c = this.createCookie(Constants.COOKIE_NAME_THEME, value, 60 * 60 * 24 * 365); response.addCookie(c); } String theme = request.getParameter(Constants.REQUEST_PARAM_THEME); if (theme == null || theme.equals("")) { theme = c.getValue(); } else { c.setMaxAge(0); c = this.createCookie(Constants.COOKIE_NAME_THEME, theme, 60 * 60 * 24 * 365); response.addCookie(c); } return theme; }