List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:org.opencms.jsp.CmsJspLoginPersistingBean.java
/** * Logs the user out and optionally invalidates their login token.<p> * * @param invalidateToken true if the token should be invalidated * * @throws IOException if something goes wrong *//* ww w .ja v a 2 s. c o m*/ public void logout(boolean invalidateToken) throws IOException { if (isLoggedIn() && invalidateToken) { CmsUser user = getCmsObject().getRequestContext().getCurrentUser(); CmsPersistentLoginTokenHandler tokenHandler = new CmsPersistentLoginTokenHandler(); try { Cookie cookie = new Cookie(CmsPersistentLoginAuthorizationHandler.COOKIE_NAME, ""); cookie.setMaxAge(0); cookie.setPath(getCookiePath(true)); getResponse().addCookie(cookie); tokenHandler.invalidateToken(user, CmsRequestUtil.getCookieValue(getRequest().getCookies(), CmsPersistentLoginAuthorizationHandler.COOKIE_NAME)); } catch (Exception e) { LOG.error("Could not invalidate tokens for user " + user, e); } } super.logout(); }
From source file:com.laxser.blitz.web.var.FlashImpl.java
public void writeNewMessages() { if (logger.isDebugEnabled()) { logger.debug("writeNextMessages"); }/*from ww w . jav a 2 s. c o m*/ HttpServletResponse response = invocation.getResponse(); List<String> responseCookies = null; for (Map.Entry<String, String> entry : next.entrySet()) { if (responseCookies == null) { responseCookies = new ArrayList<String>(next.size()); } String cookieValue; if (entry.getValue() == null) { cookieValue = ""; } else { try { cookieValue = base64.encodeToString(entry.getValue().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new Error(e); } } Cookie cookie = new Cookie(cookiePrefix + entry.getKey(), cookieValue); cookie.setPath("/"); cookie.setMaxAge(1); response.addCookie(cookie); responseCookies.add(cookie.getName()); if (logger.isDebugEnabled()) { logger.debug("write flash cookie:" + cookie.getName() + "=" + cookie.getValue()); } } for (Map.Entry<String, String> entry : last.entrySet()) { if (responseCookies == null || !responseCookies.contains(entry.getKey())) { Cookie c = new Cookie(entry.getKey(), null); c.setMaxAge(0); c.setPath("/"); response.addCookie(c); if (logger.isDebugEnabled()) { logger.debug("delete flash cookie:" + c.getName() + "=" + c.getValue()); } } } }
From source file:com.tamnd.app.filters.CsrfHeaderFilter.java
@Override 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);/*from w ww. j a v a 2s. c o m*/ } } filterChain.doFilter(request, response); // CsrfToken token = (CsrfToken) request.getAttribute(REQUEST_ATTRIBUTE_NAME); // if (token != null) { // response.setHeader(RESPONSE_HEADER_NAME, token.getHeaderName()); // response.setHeader(RESPONSE_PARAM_NAME, token.getParameterName()); // response.setHeader(RESPONSE_TOKEN_NAME , token.getToken()); // } // filterChain.doFilter(request, response); }
From source file:org.infoscoop.web.AuthenticationServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = request.getRequestURI(); // process to logout if (url.endsWith("/logout")) { request.getSession().invalidate(); Cookie credentialCookie = new Cookie("portal-credential", ""); credentialCookie.setMaxAge(0);/*from w w w. j a v a 2s.com*/ credentialCookie.setPath("/"); response.addCookie(credentialCookie); response.sendRedirect(logoutUrl != null ? logoutUrl : "index.jsp"); return; } //doPost(request, response); response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); }
From source file:de.appsolve.padelcampus.utils.LoginUtil.java
public void updateLoginCookie(HttpServletRequest request, HttpServletResponse response) { Player player = sessionUtil.getUser(request); if (player != null) { UUID cookieUUID = UUID.randomUUID(); UUID cookieValue = UUID.randomUUID(); String cookieValueHash = BCrypt.hashpw(cookieValue.toString(), BCrypt.gensalt()); LoginCookie loginCookie = new LoginCookie(); loginCookie.setUUID(cookieUUID.toString()); loginCookie.setPlayerUUID(player.getUUID()); loginCookie.setLoginCookieHash(cookieValueHash); loginCookie.setValidUntil(new LocalDate().plusYears(1)); loginCookieDAO.saveOrUpdate(loginCookie); Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, cookieUUID.toString() + ":" + cookieValue.toString()); cookie.setDomain(request.getServerName()); cookie.setMaxAge(ONE_YEAR_SECONDS); cookie.setPath("/"); response.addCookie(cookie);/* w w w. ja v a2 s.com*/ } }
From source file:org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter.java
protected static String getSavedRequestedURL(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { String requestedPage = null;/*from ww w . j a v a 2 s .c om*/ HttpSession session = httpRequest.getSession(false); if (httpRequest.getParameter(REQUESTED_URL) != null) { String requestedUrl = httpRequest.getParameter(REQUESTED_URL); if (requestedUrl != null && !"".equals(requestedUrl)) { try { requestedPage = URLDecoder.decode(requestedUrl, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error("Unable to get the requestedUrl parameter" + e); } } } else { // retrieve from session if (session != null) { requestedPage = (String) session.getAttribute(START_PAGE_SAVE_KEY); } // retrieve from SSO cookies Cookie[] cookies = httpRequest.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (SSO_INITIAL_URL_REQUEST_KEY.equals(cookie.getName())) { requestedPage = cookie.getValue(); cookie.setPath("/"); // enforce cookie removal cookie.setMaxAge(0); httpResponse.addCookie(cookie); } } } } // clean up session if (session != null) { session.removeAttribute(START_PAGE_SAVE_KEY); } // add locale if not in the URL params String localeStr = httpRequest.getParameter(NXAuthConstants.LANGUAGE_PARAMETER); if (requestedPage != null && !"".equals(requestedPage) && localeStr != null) { Map<String, String> params = new HashMap<String, String>(); if (!URIUtils.getRequestParameters(requestedPage).containsKey(NXAuthConstants.LANGUAGE_PARAMETER)) { params.put(NXAuthConstants.LANGUAGE_PARAMETER, localeStr); } return URIUtils.addParametersToURIQuery(requestedPage, params); } return requestedPage; }
From source file:org.iwethey.forums.web.HeaderInterceptor.java
/** * Load the request attributes with the User object (if authenticated) * and start time for the page for audit purposes. * <p>/*from w w w.j a va2 s . c o m*/ * @param request The servlet request object. * @param response The servlet response object. * @param handler The request handler processing this request. */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Date now = new Date(); request.setAttribute("now", now); long start = now.getTime(); request.setAttribute("start", new Long(start)); Integer id = (Integer) WebUtils.getSessionAttribute(request, USER_ID_ATTRIBUTE); User user = null; if (id == null) { user = (User) WebUtils.getSessionAttribute(request, USER_ATTRIBUTE); if (user == null) { user = new User("Anonymous"); WebUtils.setSessionAttribute(request, USER_ATTRIBUTE, user); } } else { user = mUserManager.getUserById(id.intValue()); user.setLastPresent(new Date()); mUserManager.saveUserAttributes(user); } request.setAttribute("username", user.getNickname()); request.setAttribute(USER_ATTRIBUTE, user); System.out.println("Local Address = [" + request.getLocalAddr() + "]"); System.out.println("Local Name = [" + request.getLocalName() + "]"); System.out.println("Remote Address = [" + request.getRemoteAddr() + "]"); System.out.println("Remote Host = [" + request.getRemoteHost() + "]"); System.out.println("Remote Port = [" + request.getRemotePort() + "]"); System.out.println("Remote User = [" + request.getRemoteUser() + "]"); System.out.println("Context Path = [" + request.getContextPath() + "]"); System.out.println("===================="); Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; System.out.println("Cookie Domain = [" + cookie.getDomain() + "]"); System.out.println("Cookie Name = [" + cookie.getName() + "]"); System.out.println("Cookie Value = [" + cookie.getValue() + "]"); System.out.println("Cookie Expire = [" + cookie.getMaxAge() + "]"); System.out.println("===================="); if ("iwt_cookie".equals(cookie.getName())) { cookie.setMaxAge(1000 * 60 * 60 * 24 * 30 * 6); response.addCookie(cookie); } } } else { System.out.println("No cookies were found in the request"); } Cookie newCookie = new Cookie("iwt_cookie", "harrr2!"); newCookie.setPath(request.getContextPath()); newCookie.setDomain(request.getLocalName()); newCookie.setMaxAge(1000 * 60 * 60 * 24 * 30 * 6); response.addCookie(newCookie); request.setAttribute(HEADER_IMAGE_ATTRIBUTE, "/images/iwethey-lrpd-small.png"); return true; }
From source file:com.vmware.identity.openidconnect.server.LogoutRequestProcessor.java
private Cookie personUserCertificateLoggedOutCookie() { Cookie cookie = new Cookie(SessionManager.getPersonUserCertificateLoggedOutCookieName(this.tenant), ""); cookie.setPath("/openidconnect"); cookie.setSecure(true);/* w w w .ja v a 2 s . co m*/ cookie.setHttpOnly(true); return cookie; }
From source file:com.hypersocket.session.json.SessionUtils.java
public void setLocale(HttpServletRequest request, HttpServletResponse response, String locale) { request.getSession().setAttribute(USER_LOCALE, locale); Cookie cookie = new Cookie(HYPERSOCKET_LOCALE, locale); cookie.setMaxAge(Integer.MAX_VALUE); cookie.setPath("/"); cookie.setSecure(request.getProtocol().equalsIgnoreCase("https")); cookie.setDomain(request.getServerName()); response.addCookie(cookie);//w ww. j a v a2 s . c om }
From source file:csns.web.controller.SectionController.java
@RequestMapping("/section/taken") public String taken(@RequestParam(required = false) Quarter quarter, ModelMap models, HttpSession session, HttpServletResponse response) {/* ww w . j a v a 2s . com*/ Cookie cookie = new Cookie("default-home", "/section/taken"); cookie.setPath("/"); cookie.setMaxAge(100000000); response.addCookie(cookie); return list("taken", quarter, models, session); }