List of usage examples for javax.servlet.http Cookie setValue
public void setValue(String newValue)
From source file:TDS.Shared.Security.TDSIdentity.java
public static TDSIdentity getCurrentTDSIdentity() { TDSIdentity identity = HttpContext.getCurrentContext().getIdentity(); if (identity == null) { // First get the auth cookie. MultiValueCookie cookie = HttpContext.getCurrentContext().getCookies() .findCookie(FormsAuthentication.getAuthCookieName()); if (cookie != null && !StringUtils.isEmpty(cookie.getValue())) { String decryptedCookieValue = FormsAuthentication.decrypt(cookie.getValue()); // replace the value in the underlying single value cookie and use that // to // create a new multi value cookie. Cookie underLyingCookie = cookie.getUnderlyingWebCookie(); underLyingCookie.setValue(decryptedCookieValue); identity = new TDSIdentity(new FormsAuthenticationTicket(new MultiValueCookie(underLyingCookie))); } else {//from w w w. j a v a2s . c om // so we do not have a AUTH cookie: our user is not authenticated. // create a new FormsAuthenticationTicket and mark the user as not // authenticated. cookie = new MultiValueCookie(FormsAuthentication.getAuthCookieName()); identity = new TDSIdentity(new FormsAuthenticationTicket(cookie)); identity.setAuthenticated(false); // even though we are doing a save, the application may clear the // cookies on first entering login page. identity.saveAuthCookie(); } HttpContext.getCurrentContext().setIdentity(identity); } return identity; }
From source file:com.netsteadfast.greenstep.base.sys.UserCurrentCookie.java
public static void setCurrentId(HttpServletResponse response, String currentId, String sessionId, String account, String language) { try {/*from w ww .j a va 2 s . c om*/ String value = currentId + Constants.ID_DELIMITER + sessionId + Constants.ID_DELIMITER + account + Constants.ID_DELIMITER + language; String encValue = EncryptorUtils.encrypt(Constants.getEncryptorKey1(), Constants.getEncryptorKey2(), value); encValue = SimpleUtils.toHex(encValue); Cookie cookie = new Cookie(Constants.APP_SITE_CURRENTID_COOKIE_NAME, encValue); cookie.setPath("/"); cookie.setValue(encValue); cookie.setMaxAge(60 * 60 * 24); // 1-day cookie.setHttpOnly(true); response.addCookie(cookie); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.cxf.fediz.service.idp.util.WebUtils.java
public static void removeCookie(final RequestContext context, final String cookieName) { HttpServletResponse httpServletResponse = getHttpServletResponse(context); Cookie cookie = readCookie(context, cookieName); if (cookie != null) { cookie.setMaxAge(0);//w w w . ja v a2s. c om cookie.setValue(""); httpServletResponse.addCookie(cookie); } }
From source file:architecture.ee.web.util.CookieUtils.java
public static void deleteCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie) { if (cookie != null) { String path = request.getContextPath() != null ? request.getContextPath() : "/"; if ("".equals(path)) path = "/"; cookie.setPath(path);/* w ww . j ava2 s. c o m*/ cookie.setValue(""); cookie.setMaxAge(0); response.addCookie(cookie); } }
From source file:io.lavagna.web.helper.UserSession.java
public static void invalidate(HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) { req.getSession().invalidate();//from w w w . j a v a 2 s . c o m Cookie c = getCookie(req, "LAVAGNA_REMEMBER_ME"); if (c != null) { deleteTokenIfExist(c.getValue(), userRepository); c.setMaxAge(0); c.setValue(null); resp.addCookie(c); } }
From source file:com.adobe.acs.commons.util.CookieUtil.java
/** * Internal method used for dropping cookies * * @param response//w w w.j ava 2s .co m * @param cookies * @param cookiePath * @return */ private static int dropCookies(final HttpServletResponse response, final Cookie[] cookies, final String cookiePath) { int count = 0; for (final Cookie cookie : cookies) { if (cookie == null) { continue; } final Cookie responseCookie = (Cookie) cookie.clone(); responseCookie.setMaxAge(0); responseCookie.setPath(cookiePath); responseCookie.setValue(""); addCookie(responseCookie, response); count++; } return count; }
From source file:org.projectforge.web.LoginPage.java
public static void logout(final MySession mySession, final HttpServletRequest request, final HttpServletResponse response, final UserXmlPreferencesCache userXmlPreferencesCache, final MenuBuilder menuBuilder) { final PFUserDO user = mySession.getUser(); if (user != null) { userXmlPreferencesCache.flushToDB(user.getId()); userXmlPreferencesCache.clear(user.getId()); if (menuBuilder != null) { menuBuilder.expireMenu(user.getId()); }//from w w w.j a v a 2 s . c o m } mySession.logout(); final Cookie stayLoggedInCookie = UserFilter.getStayLoggedInCookie(request); if (stayLoggedInCookie != null) { stayLoggedInCookie.setMaxAge(0); stayLoggedInCookie.setValue(null); stayLoggedInCookie.setPath("/"); response.addCookie(stayLoggedInCookie); } }
From source file:com.ax.utils.CookieUtils.java
/** * Deletes the specified cookie./*from ww w . j a v a 2s .c o m*/ * * @param request * the servlet request. * @param response * the servlet response. * @param cookie * the cookie object to be deleted. * @param path * the path. */ public static void deleteCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie, String path) { if (cookie != null) { // Invalidate the cookie if (StringUtils.isEmpty(path)) { path = "/"; } cookie.setPath(path); cookie.setValue(""); cookie.setMaxAge(0); response.addCookie(cookie); } }
From source file:com.sniper.springmvc.utils.CookieUtils.java
/** * Cookie/*from w w w . j ava 2s . c o m*/ * * @param name * ?? * @param value * * @param maxAge * ?? */ public static void setCookie(HttpServletResponse response, String name, String value, int maxAge) { Cookie cookie = new Cookie(name, null); if (StringUtils.isNotBlank(SpringContextHolder.getApplicationContext().getApplicationName())) { cookie.setPath(SpringContextHolder.getApplicationContext().getApplicationName()); } else { cookie.setPath("/"); } cookie.setMaxAge(maxAge); try { cookie.setValue(URLEncoder.encode(value, "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } response.addCookie(cookie); }
From source file:org.projectforge.web.LoginPage.java
public static void logout(final MySession mySession, final WebRequest request, final WebResponse response, final UserXmlPreferencesCache userXmlPreferencesCache, final MenuBuilder menuBuilder) { final PFUserDO user = mySession.getUser(); if (user != null) { userXmlPreferencesCache.flushToDB(user.getId()); userXmlPreferencesCache.clear(user.getId()); if (menuBuilder != null) { menuBuilder.expireMenu(user.getId()); }/*from w w w .j a v a 2s . c om*/ } mySession.logout(); final Cookie stayLoggedInCookie = UserFilter .getStayLoggedInCookie(WicketUtils.getHttpServletRequest(request)); if (stayLoggedInCookie != null) { stayLoggedInCookie.setMaxAge(0); stayLoggedInCookie.setValue(null); stayLoggedInCookie.setPath("/"); response.addCookie(stayLoggedInCookie); } }