List of usage examples for javax.servlet.http Cookie setValue
public void setValue(String newValue)
From source file:org.egov.infstr.security.spring.filter.CustomLogoutHandler.java
private void clearAllCookies(final HttpServletRequest request, final HttpServletResponse response) { final Cookie cookies[] = request.getCookies(); if (cookies == null || cookies.length < 1) return;// w ww.j a va 2 s.co m for (final Cookie cookie : cookies) { cookie.setMaxAge(0); cookie.setPath("/"); cookie.setValue(null); response.addCookie(cookie); } }
From source file:com.haulmont.cuba.web.sys.AppCookies.java
public void removeCookie(String name) { if (isCookiesEnabled()) { Cookie cookie = getCookie(name); if (cookie != null) { cookie.setValue(null); cookie.setPath(getCookiePath()); cookie.setMaxAge(0);/*from ww w. j a v a2 s . com*/ addCookie(cookie); } } }
From source file:com.zk.common.waf.request.WafRequestWrapper.java
/** * @Description Cookie/*from ww w. ja v a2 s . c o m*/ * @return */ @Override public Cookie[] getCookies() { Cookie[] existingCookies = super.getCookies(); if (existingCookies != null) { for (int i = 0; i < existingCookies.length; ++i) { Cookie cookie = existingCookies[i]; cookie.setValue(filterParamString(cookie.getValue())); } } return existingCookies; }
From source file:org.siyuyan.module.web.controller.UserController.java
@RequestMapping(value = "logout") public String logout(HttpServletRequest request, HttpServletResponse response) throws Exception { // session//from w w w .j a v a2 s .c o m request.getSession().setAttribute("userSession", null); // cookies Cookie[] cookies = request.getCookies(); for (Cookie cookie : cookies) { cookie.setValue(null); response.addCookie(cookie); } return "redirect:/"; }
From source file:com.orangeleap.webtools.controller.json.LogoutController.java
@RequestMapping("/logout.json") public void logout(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final String guid = request.getParameter("guid"); final String sessionId = request.getParameter("sessionId"); if (StringUtils.isNotBlank(sessionId)) { final Cookie sessionCookies[] = request.getCookies(); Cookie sessionCookie = null;/*w w w .jav a2s.c o m*/ for (final Cookie aCookie : sessionCookies) { if (aCookie.getName().equals("sessionId")) { aCookie.setMaxAge(0); aCookie.setValue(""); sessionCookie = aCookie; break; } } if (sessionCookie == null) { sessionCookie = new Cookie("sessionId", ""); } response.addCookie(sessionCookie); sessionCache.remove(sessionId); } final Widget widget = widgetService.getWidget(guid); final String authenticationUrl = widget.getWidgetAuthenticationURL(); response.sendRedirect(authenticationUrl); }
From source file:com.mobileman.projecth.web.util.PersistentCookieHelper.java
public void removeUser(HttpServletRequest request, HttpServletResponse response) { //remove from request Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie c : cookies) { if (COOKIE_NAME.equals(c.getName())) { c.setValue("deleted"); break; }//from w w w. j a v a 2s . com } } //remove from browser Cookie cookie = new Cookie(COOKIE_NAME, "1"); cookie.setPath(PATH); cookie.setMaxAge(0); //0 = remove cookie response.setContentType("text/html"); //else delete cookie not works response.addCookie(cookie); }
From source file:org.nuxeo.ecm.platform.ui.web.auth.token.TokenAuthenticator.java
@Override public Boolean handleLogout(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { Cookie cookie = getTokenCookie(httpRequest); if (cookie != null) { cookie.setMaxAge(0);/* ww w . j a v a2s .co m*/ cookie.setValue(""); httpResponse.addCookie(cookie); } return false; }
From source file:com.companyname.services.PlatCookieService.java
public void invalidateCookie(HttpServletRequest request, HttpServletResponse response, String _cookieName) { logger.info("cancelling cookie named: " + _cookieName); // if cookie does not exist, do nothing Cookie cookie = getCookie(request, _cookieName); if (cookie == null) { return;// w w w. ja v a 2 s. com } cookie = new Cookie(_cookieName, null); cookie.setValue(""); cookie.setMaxAge(0); cookie.setPath(getCookiePath()); cookie.setDomain(getCookieDomain()); response.addCookie(cookie); }
From source file:edu.usu.sdl.openstorefront.web.action.LoginAction.java
@HandlesEvent("Logout") public Resolution logout() { Subject currentUser = SecurityUtils.getSubject(); String userLoggedIn = SecurityUtil.getCurrentUserName(); currentUser.logout();//from w ww. j av a 2s . c o m getContext().getRequest().getSession().invalidate(); try { getContext().getRequest().logout(); } catch (ServletException ex) { throw new OpenStorefrontRuntimeException(ex); } //For now invalidate all cookies; in the future there may be some that should persist. Cookie[] cookies = getContext().getRequest().getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie cookie : cookies) { cookie.setValue("-"); cookie.setMaxAge(0); getContext().getResponse().addCookie(cookie); } } if (OpenStorefrontConstant.ANONYMOUS_USER.equals(userLoggedIn)) { log.log(Level.INFO, "User was not logged when the logut was called."); } else { log.log(Level.INFO, MessageFormat.format("Logged off user: {0}", userLoggedIn)); } String logoutUrl = PropertiesManager.getValue(PropertiesManager.KEY_LOGOUT_URL, "/login.jsp"); if (StringUtils.isBlank(logoutUrl)) { logoutUrl = "/login.jsp"; } if (logoutUrl.toLowerCase().startsWith("http")) { return new RedirectResolution(logoutUrl, false); } else { return new RedirectResolution(logoutUrl); } }
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>//ww w . jav a 2 s .co 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; }