List of usage examples for javax.servlet.http Cookie setValue
public void setValue(String newValue)
From source file:org.orcid.core.manager.impl.InternalSSOManagerImpl.java
@Override public void deleteToken(String orcid, HttpServletRequest request, HttpServletResponse response) { this.deleteToken(orcid); // Delete the cookie if (request.getCookies() != null) { for (Cookie cookie : request.getCookies()) { if (cookie.getName().equals(COOKIE_NAME)) { cookie.setMaxAge(0);/*from w ww . j a v a 2 s. c o m*/ cookie.setValue(StringUtils.EMPTY); cookie.setSecure(true); cookie.setHttpOnly(true); cookie.setDomain(allowedDomain.trim()); response.addCookie(cookie); } } } }
From source file:com.persistent.cloudninja.controller.LogoutFilter.java
private void removeCookie(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String authCookieName) {//from ww w .j ava 2s .co m Cookie[] cookies = httpServletRequest.getCookies(); Cookie currentCookie = null; if (cookies != null && cookies.length > 0) { for (Cookie c : cookies) { if (authCookieName.equals(c.getName())) { currentCookie = c; currentCookie.setMaxAge(0); currentCookie.setValue(""); currentCookie.setPath("/"); httpServletResponse.addCookie(currentCookie); } } } }
From source file:nl.strohalm.cyclos.controls.access.LogoutAction.java
@Override public ActionForward execute(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { request.getSession().invalidate();//w ww. j av a2 s . co m // When there is an 'afterLogout' cookie, it means we will redirect back to another site after logout final Cookie afterLogout = RequestHelper.getCookie(request, "afterLogout"); if (afterLogout != null && StringUtils.isNotEmpty(afterLogout.getValue())) { String url = afterLogout.getValue(); // Clear the cookie value afterLogout.setValue(""); response.addCookie(afterLogout); try { final LocalSettings settings = settingsService.getLocalSettings(); url = URLDecoder.decode(url, settings.getCharset()); } catch (final UnsupportedEncodingException e) { } response.sendRedirect(url); return null; } ActionForward forward = mapping.findForward("success"); // It may have a queryString to be passed again to the login page (ie: in case of customized login pages)... String queryString = RequestHelper.getCookieValue(request, "loginQueryString"); if (StringUtils.isNotEmpty(queryString)) { queryString = StringHelper.decodeUrl(queryString); // Remove some variables we want to clear after a logout queryString = StringHelper.removeQueryStringVariable(queryString, "returnTo"); // Remove a trailing & if (queryString.endsWith("&")) { queryString = queryString.substring(0, queryString.length() - 1); } // Apply the queryString String path = forward.getPath(); if (StringUtils.isNotEmpty(queryString)) { path += "?" + queryString; } // Then set the forward forward = new ActionForward(path, true); } return forward; }
From source file:org.alfresco.web.app.servlet.LanguageCookieFilter.java
protected String positionCookie(ServletRequest servletRequest, ServletResponse servletResponse, String mlLang, String cookieName, boolean content) { if (mlLang == null || mlLang.length() == 0) { // try to get the cookie and set the content locale prop there Cookie[] cookies = ((HttpServletRequest) servletRequest).getCookies(); Cookie cookie;//from ww w . j a v a 2 s. c om boolean found = false; if (cookies != null) { for (int i = 0; i < cookies.length; i++) { cookie = cookies[i]; if (cookie.getName().equals(cookieName)) { String lang = cookie.getValue(); if (content) { if (lang.length() == 0) { I18NUtil.setContentLocale(null); } else { I18NUtil.setContentLocale(new Locale(lang)); } return lang; } else { I18NUtil.setLocale(new Locale(lang)); return lang; } } } } } else { Cookie mlpref = getCookie(servletRequest, cookieName); if (mlpref == null) { mlpref = new Cookie(cookieName, mlLang); } else mlpref.setValue(mlLang); // Set expiry date after 24 Hrs for both the cookies. //mlpref.setMaxAge(60 * 60 * 24); ((HttpServletResponse) servletResponse).addCookie(mlpref); if (content) { I18NUtil.setContentLocale(new Locale(mlLang)); return mlLang; } else { I18NUtil.setLocale(new Locale(mlLang)); return mlLang; } /* * { if(mlLang.equals("reset")) { Cookie mlpref = new * Cookie(cookieName, mlLang); // Set expiry date after 24 Hrs for * both the cookies. mlpref.setMaxAge(0); mlpref.setValue(""); * ((HttpServletResponse) servletResponse).addCookie(mlpref); if * (content) { I18NUtil.setContentLocale(null); return mlLang; } * else { I18NUtil.setLocale(null); return mlLang; } } else */ } return mlLang; }
From source file:com.persistent.cloudninja.controller.TenantProfileController.java
@RequestMapping(value = "{tenantId}/showTenantProfilePage.htm", method = RequestMethod.POST) public ModelAndView showProfilePage(HttpServletRequest request, HttpServletResponse response, @CookieValue(value = "CLOUDNINJAAUTH", required = false) String cookie, @ModelAttribute("logoFileDTO") LogoFileDTO logoFileDTO, BindingResult result) { // validate the file uploaded for logo logoFileDTOValidator.validate(logoFileDTO, result); // if no errors in validation then only process the request if (!result.hasErrors()) { if (cookie == null) { cookie = request.getAttribute("cookieNameAttr").toString(); }//from www . j a v a 2 s .c o m String tenantId = AuthFilterUtils .getFieldValueFromCookieString(CloudNinjaConstants.COOKIE_TENANTID_PREFIX, cookie); String logoFileName = fileUploadService.fileUploadService(logoFileDTO.getFile(), tenantId); String logoCookieName = "CLOUDNINJALOGO"; // update the logo cookie with the new logo file Cookie cookies[] = request.getCookies(); Cookie logoCookie = null; if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals(logoCookieName)) { logoCookie = cookies[i]; logoCookie.setValue(logoFileName); logoCookie.setMaxAge(-1); logoCookie.setPath("/"); response.addCookie(logoCookie); break; } } } } return new ModelAndView("tenantProfilePage", "logoFileDTO", logoFileDTO); }
From source file:com.glaf.core.util.RequestUtils.java
public static void removeLoginUser(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie cookie : cookies) { if (StringUtils.equals(cookie.getName(), Constants.COOKIE_NAME)) { cookie.setMaxAge(0);//from w ww.j a v a 2 s .c om cookie.setPath("/"); cookie.setValue(UUID32.getUUID()); response.addCookie(cookie); logger.debug("remove user from cookie"); } } } HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(Constants.LOGIN_INFO); session.invalidate(); } }
From source file:org.mule.transport.http.servlet.MuleHttpServletResponse.java
private org.apache.commons.httpclient.Cookie toHttpClientCookie(Cookie cookie) { org.apache.commons.httpclient.Cookie internal = new org.apache.commons.httpclient.Cookie(); internal.setName(cookie.getName());// w w w .ja v a 2 s .c om internal.setValue(cookie.getValue()); internal.setComment(cookie.getComment()); internal.setDomain(cookie.getDomain()); // internal.setExpiryDate(toExpiry(cookie.getMaxAge())); internal.setPath(cookie.getPath()); internal.setVersion(cookie.getVersion()); return internal; }
From source file:de.metas.procurement.webui.service.impl.LoginRememberMeService.java
private void removeRememberMeCookie() { try {/*from w ww .jav a2 s. c o m*/ Cookie cookie = getRememberMeCookie(); if (cookie == null) { return; } cookie = new Cookie(COOKIENAME_RememberMe, null); cookie.setValue(null); cookie.setMaxAge(0); // by setting the cookie maxAge to 0 it will deleted immediately cookie.setPath("/"); VaadinService.getCurrentResponse().addCookie(cookie); logger.debug("Cookie removed"); } catch (final Exception e) { logger.warn("Failed removing the cookie", e); } }
From source file:com.redhat.rhn.frontend.servlets.test.PxtSessionDelegateImplTest.java
private Cookie getPxtCookieWithInvalidSessionKey() { Cookie pxtCookie = getPxtCookie(); String key = pxtCookie.getValue(); key = key.replace('x', ':'); pxtCookie.setValue(key); return pxtCookie; }
From source file:org.encuestame.mvc.interceptor.EnMeSecurityInterceptor.java
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { request.setAttribute("user_locale", WidgetUtil.getCurrentLocale(request)); request.setAttribute("hide_header_menu", false); request.setAttribute("help_links", false); final Authentication auth = getSecCtx().getAuthentication(); log.trace("preHandle security auth " + auth); if (!SecurityUtils.checkIsSessionIsExpired(auth)) { log.trace("auth valid"); if (SecurityUtils.checkIsSessionIsAnonymousUser(auth)) { log.trace("session expired"); request.setAttribute("logged", false); request.setAttribute("help_links", false); } else {/*w ww . j ava 2 s . co m*/ //cookies log.trace("session is valid"); final String username = getUserPrincipalUsername(); final UserAccount user = getByUsername(username); request.setAttribute("account", ConvertDomainBean.convertUserAccountToSignUpBean(user)); //help links ENCUESTAME-668 final String mappedPath = request.getRequestURI().replace(request.getContextPath(), ""); if (getListPaths().indexOf(mappedPath) != -1) { //path inside of the list of helps Boolean status = getSecurityService().checkHelpURL(mappedPath, getUserAccount()); request.setAttribute("mappedPath", mappedPath); if (status) { request.setAttribute("help_links", true); } else { request.setAttribute("help_links", false); } } // if (username != EnMeUtils.ANONYMOUS_USER) { getLocaleResolver().setLocale(request, response, getUserAccountLocale(user)); } request.setAttribute("isActivated", user.getInviteCode() == null ? true : false); log.trace("Account User Interceptor " + user); //set language final String lang = WidgetUtil.convertToDojoLocale(user.getLanguage()); log.debug("Language --->" + lang); request.setAttribute("user_locale", user.getLanguage() == null ? WidgetUtil.getCurrentLocale(request) : lang); Cookie cookieName = WebUtils.getCookie(request, this.COOKIE_NAME); if (cookieName != null) { log.trace("Cookie " + cookieName.getName()); cookieName.setValue(RandomStringUtils.random(4)); //TODO: testing cookies. } request.setAttribute("logged", true); } } else { log.info("Session Expired"); request.setAttribute("logged", false); } //enable or disable development status request.setAttribute("development", EnMePlaceHolderConfigurer.getBooleanProperty("encuestame.development")); //customized logo request.setAttribute("logo", this.getCustomizedHeaderLogo()); request.setAttribute("domain", WidgetUtil.getDomain(request)); request.setAttribute("realPath", request.getRequestURI()); return true; }