List of usage examples for javax.servlet.http Cookie setValue
public void setValue(String newValue)
From source file:com.persistent.cloudninja.controller.AuthFilterUtils.java
/** * // w w w . j a va2 s . co m * @param preExistentCookie * , cloudNinjaUser */ public static Cookie updateExistingCookie(Cookie preExistentCookie, CloudNinjaUser cloudNinjaUser) { String cookieValue = createNewCookieForACSAuthenticatedUser(cloudNinjaUser, preExistentCookie.getName()) .getValue(); preExistentCookie.setValue(cookieValue); return preExistentCookie; }
From source file:com.tc.utils.XSPUtils.java
public static void logout(String url) { HttpSession httpSession = XSPUtils.getHttpSession(); if (httpSession == null) { return;//from w w w .j a va 2 s .com } String sessionId = XSPUtils.getHttpSession().getId(); XSPUtils.getRequest().getSession(false).invalidate(); //wipe out the cookies for (Cookie cookie : getCookies()) { cookie.setValue(StringCache.EMPTY); cookie.setPath("/"); cookie.setMaxAge(0); XSPUtils.getResponse().addCookie(cookie); } try { NotesContext notesContext = NotesContext.getCurrent(); notesContext.getModule().removeSession(sessionId); XSPUtils.externalContext().redirect(url); } catch (IOException e) { logger.log(Level.SEVERE, null, e); } }
From source file:com.tc.utils.XSPUtils.java
public static void logout() { HttpSession httpSession = XSPUtils.getHttpSession(); if (httpSession == null) { return;//from w w w . j a v a 2s. c o m } String sessionId = XSPUtils.getHttpSession().getId(); String url = XSPUtils.externalContext().getRequestContextPath() + "?logout&redirectto=" + externalContext().getRequestContextPath(); XSPUtils.getRequest().getSession(false).invalidate(); //wipe out the cookies for (Cookie cookie : getCookies()) { cookie.setValue(StringCache.EMPTY); cookie.setPath("/"); cookie.setMaxAge(0); XSPUtils.getResponse().addCookie(cookie); } try { NotesContext notesContext = NotesContext.getCurrent(); notesContext.getModule().removeSession(sessionId); XSPUtils.externalContext().redirect(url); } catch (IOException e) { logger.log(Level.SEVERE, null, e); } }
From source file:org.itracker.web.util.LoginUtilities.java
public static User setupSession(User user, String encPassword, HttpServletRequest request, HttpServletResponse response) {// ww w . jav a 2 s . c o m if (user == null) { logger.warn("setupSession: null user", (logger.isDebugEnabled() ? new RuntimeException() : null)); throw new IllegalArgumentException("null user"); } UserService userService = ServletContextUtils.getItrackerServices().getUserService(); if (logger.isDebugEnabled()) { logger.debug("Creating new session"); } HttpSession session = request.getSession(true); if (logger.isDebugEnabled()) { logger.debug("Setting session timeout to " + getConfiguredSessionTimeout() + " minutes"); } session.setMaxInactiveInterval(getConfiguredSessionTimeout() * 60); if (logger.isDebugEnabled()) { logger.debug("Setting session tracker"); } session.setAttribute(Constants.SESSION_TRACKER_KEY, new SessionTracker(user.getLogin(), session.getId())); if (logger.isDebugEnabled()) { logger.debug("Setting user information"); } session.setAttribute(Constants.USER_KEY, user); if (logger.isDebugEnabled()) { logger.debug("Setting preferences for user " + user.getLogin()); } UserPreferences userPrefs = user.getPreferences(); // TODO : this is a hack, remove when possible if (userPrefs == null) { logger.warn("setupSession: got user with no preferences!: " + user + " (prefs: " + user.getPreferences() + ")"); userPrefs = new UserPreferences(); } session.setAttribute(Constants.PREFERENCES_KEY, userPrefs); if (logger.isDebugEnabled()) { logger.debug("Setting user " + user + " locale to " + ITrackerResources.getLocale(userPrefs.getUserLocale())); } session.setAttribute(Constants.LOCALE_KEY, ITrackerResources.getLocale(userPrefs.getUserLocale())); // TODO: cookie could be removed Cookie cookie = new Cookie(Constants.COOKIE_NAME, ""); cookie.setPath(request.getContextPath()); cookie.setValue(""); cookie.setMaxAge(0); response.addCookie(cookie); if (logger.isDebugEnabled()) { logger.debug("Setting permissions for user " + user.getLogin()); } Map<Integer, Set<PermissionType>> usersMapOfProjectIdsAndSetOfPermissionTypes = userService .getUsersMapOfProjectIdsAndSetOfPermissionTypes(user, AuthenticationConstants.REQ_SOURCE_WEB); session.setAttribute(Constants.PERMISSIONS_KEY, usersMapOfProjectIdsAndSetOfPermissionTypes); // Reset some session forms session.setAttribute(Constants.SEARCH_QUERY_KEY, null); SessionManager.clearSessionNeedsReset(user.getLogin()); if (logger.isDebugEnabled()) { logger.debug("User session data updated."); } return user; }
From source file:org.opencms.ui.login.CmsLoginHelper.java
/** * Sets the cookie data.<p>// ww w . ja va2 s .co m * * @param pcType the pctype value * @param username the username value * @param oufqn the oufqn value * * @param request the current request * @param response the current response */ public static void setCookieData(String pcType, String username, String oufqn, HttpServletRequest request, HttpServletResponse response) { // set the PC type cookie only if security dialog is enabled if (OpenCms.getLoginManager().isEnableSecurity() && CmsStringUtil.isNotEmpty(pcType)) { Cookie pcTypeCookie = getCookie(request, COOKIE_PCTYPE); pcTypeCookie.setValue(pcType); setCookie(pcTypeCookie, false, request, response); } // only store user name and OU cookies on private PC types if (PCTYPE_PRIVATE.equals(pcType)) { // set the user name cookie Cookie userNameCookie = getCookie(request, COOKIE_USERNAME); userNameCookie.setValue(username); setCookie(userNameCookie, false, request, response); // set the organizational unit cookie Cookie ouFqnCookie = getCookie(request, COOKIE_OUFQN); ouFqnCookie.setValue(oufqn); setCookie(ouFqnCookie, false, request, response); } else if (OpenCms.getLoginManager().isEnableSecurity() && PCTYPE_PUBLIC.equals(pcType)) { // delete user name and organizational unit cookies Cookie userNameCookie = getCookie(request, COOKIE_USERNAME); setCookie(userNameCookie, true, request, response); Cookie ouFqnCookie = getCookie(request, COOKIE_OUFQN); setCookie(ouFqnCookie, true, request, response); } }
From source file:org.carewebframework.ui.FrameworkWebSupport.java
/** * Sets a cookie into the response. Cookies are URLEncoded for consistency (Version 0+ of * Cookies)/*from w w w. ja va2 s. c o m*/ * * @param cookieName Name of cookie. * @param value Value of cookie. If null, the cookie is removed from the client if it exists. * @param httpResponse Response object. * @param httpRequest Request object. * @return Newly created cookie. * @throws IllegalArgumentException if cookieName, httpResponse, or httpRequest arguments are * null */ public static Cookie setCookie(final String cookieName, String value, final HttpServletResponse httpResponse, final HttpServletRequest httpRequest) { Validate.notNull(httpResponse, "The httpResponse must not be null"); Cookie cookie = getCookie(cookieName, httpRequest); if (value != null) { value = encodeCookieValue(value); } if (cookie == null) { if (value == null) { return null; } cookie = new Cookie(cookieName, value); } else if (value == null) { cookie.setMaxAge(0); } else { cookie.setValue(value); } if (httpRequest.isSecure()) { cookie.setSecure(true); } httpResponse.addCookie(cookie); return cookie; }
From source file:io.lavagna.web.helper.UserSession.java
public static void authenticateUserIfRemembered(HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) { Cookie c; if (isUserAuthenticated(req) || (c = getCookie(req, "LAVAGNA_REMEMBER_ME")) == null) { return;/* w ww . j a v a2 s. c om*/ } ImmutablePair<Integer, String> uIdToken = extractUserIdAndToken(c.getValue()); if (uIdToken != null && userRepository.rememberMeTokenExists(uIdToken.getLeft(), uIdToken.getRight())) { userRepository.deleteRememberMeToken(uIdToken.getLeft(), uIdToken.getRight()); User user = userRepository.findById(uIdToken.getLeft()); setUser(user.getId(), user.isAnonymous(), req, resp, userRepository, true); } else { // delete cookie because it's invalid c.setMaxAge(0); c.setValue(null); resp.addCookie(c); } }
From source file:com.liferay.portal.util.CookieKeys.java
public static void addCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie, boolean secure) { if (!PropsValues.SESSION_ENABLE_PERSISTENT_COOKIES || PropsValues.TCK_URL) { return;/* w w w. ja v a 2 s. com*/ } // LEP-5175 String name = cookie.getName(); String originalValue = cookie.getValue(); String encodedValue = originalValue; if (isEncodedCookie(name)) { encodedValue = new String(Hex.encodeHex(originalValue.getBytes())); if (_log.isDebugEnabled()) { _log.debug("Add encoded cookie " + name); _log.debug("Original value " + originalValue); _log.debug("Hex encoded value " + encodedValue); } } cookie.setSecure(secure); cookie.setValue(encodedValue); cookie.setVersion(VERSION); // Setting a cookie will cause the TCK to lose its ability to track // sessions response.addCookie(cookie); }
From source file:de.sainth.recipe.backend.rest.controller.LogoutController.java
@RequestMapping() @ResponseStatus(HttpStatus.NO_CONTENT)/*from w ww . j a v a 2 s. c o m*/ void logout(HttpServletRequest request, HttpServletResponse response) { if ("/logout".equals(request.getServletPath())) { Optional<Cookie> cookie = Arrays.stream(request.getCookies()) .filter(c -> "recipe_bearer".equals(c.getName())).findFirst(); if (cookie.isPresent()) { Cookie c = cookie.get(); c.setValue(""); c.setPath("/"); c.setMaxAge(0); response.addCookie(c); } response.setStatus(HttpServletResponse.SC_NO_CONTENT); } }
From source file:com.acme.demo.web.LogoutController.java
private void handleLogOutResponse(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); for (Cookie cookie : cookies) { cookie.setMaxAge(0);/*from w w w. j a va2s . co m*/ cookie.setValue(null); cookie.setPath("/"); response.addCookie(cookie); } }