List of usage examples for javax.servlet.http HttpServletResponse addCookie
public void addCookie(Cookie cookie);
From source file:am.ik.categolj2.app.authentication.AuthenticationHelper.java
void saveUserInformationInCookie(String username, String firstName, String lastName, String email, OAuth2AccessToken accessToken, HttpServletResponse response) throws UnsupportedEncodingException { try {// w w w.j a va 2s. co m Cookie cookie = new Cookie(Categolj2Cookies.USER_COOKIE, objectMapper.writeValueAsString(new UserInfo(username, firstName, lastName, email))); cookie.setMaxAge(getRefreshTokenMaxAge(accessToken)); response.addCookie(cookie); } catch (JsonProcessingException e) { logger.error("JSON conversion failed!", e); } }
From source file:memedb.httpd.MemeDBHandler.java
private void addCredentialedCookie(HttpServletResponse response, Credentials cred) { Cookie cookie = new Cookie(COOKIE_ID, cred.getToken()); cookie.setMaxAge(24 * 60 * 60); // max time is one day... afterwhich, it needs to reauth. response.addCookie(cookie); }
From source file:com.afousan.controller.RetwisController.java
private void addAuthCookie(String auth, String name, HttpServletResponse response) { RetwisSecurity.setUser(name, retwis.findUid(name)); Cookie cookie = new Cookie(CookieInterceptor.RETWIS_COOKIE, auth); cookie.setComment("Retwis-J demo"); // cookie valid for up to 1 week cookie.setMaxAge(60 * 60 * 24 * 7);//from w w w . j a v a 2 s . c o m response.addCookie(cookie); }
From source file:au.gov.dto.dibp.appointments.security.csrf.CookieBasedCsrfTokenRepository.java
@Override public void saveToken(CsrfToken token, HttpServletRequest request, HttpServletResponse response) { Cookie csrfCookie;/* w ww.j a v a2 s .c o m*/ if (token == null) { csrfCookie = new Cookie(CSRF_COOKIE_AND_PARAMETER_NAME, ""); csrfCookie.setMaxAge(0); } else { csrfCookie = new Cookie(token.getParameterName(), token.getToken()); csrfCookie.setMaxAge(COOKIE_MAX_AGE_SECONDS); } csrfCookie.setHttpOnly(true); csrfCookie.setSecure(request.isSecure()); response.addCookie(csrfCookie); }
From source file:org.jasig.cas.web.support.CookieRetrievingCookieGenerator.java
public void addCookie(final HttpServletRequest request, final HttpServletResponse response, final String cookieValue) { if (!StringUtils.hasText(request.getParameter(RememberMeCredentials.REQUEST_PARAMETER_REMEMBER_ME))) { super.addCookie(response, cookieValue); } else {/* w w w . j ava 2s. c o m*/ final Cookie cookie = createCookie(cookieValue); cookie.setMaxAge(this.rememberMeMaxAge); if (isCookieSecure()) { cookie.setSecure(true); } response.addCookie(cookie); } }
From source file:org.apache.unomi.plugins.baseplugin.actions.MergeProfilesOnPropertyAction.java
public void sendProfileCookie(Profile profile, ServletResponse response) { if (response instanceof HttpServletResponse) { HttpServletResponse httpServletResponse = (HttpServletResponse) response; Cookie profileIdCookie = new Cookie(profileIdCookieName, profile.getItemId()); profileIdCookie.setPath("/"); profileIdCookie.setMaxAge(cookieAgeInSeconds); httpServletResponse.addCookie(profileIdCookie); }//from w w w. j ava 2 s .c om }
From source file:com.erudika.para.security.CachedCsrfTokenRepository.java
private void storeTokenAsCookie(CsrfToken token, HttpServletRequest request, HttpServletResponse response) { if (isValidButNotInCookie(token, request)) { Cookie c = new Cookie(cookieName, token.getToken()); c.setMaxAge(Config.SESSION_TIMEOUT_SEC.intValue()); // don't enable HttpOnly - javascript can't access the cookie if enabled c.setHttpOnly(false);// w w w . j a v a 2 s.c o m c.setPath("/"); response.addCookie(c); } }
From source file:net.sourceforge.vulcan.web.struts.actions.ManagePreferencesAction.java
public ActionForward save(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { final PreferencesForm form = (PreferencesForm) actionForm; request.removeAttribute(Keys.PREFERENCES); request.getSession().setAttribute(Keys.PREFERENCES, form.getConfig()); final Cookie cookie = new Cookie(Keys.PREFERENCES, preferencesStore.convertToString(form.getConfig())); cookie.setPath(request.getContextPath()); cookie.setMaxAge(60 * 60 * 24 * 365); response.addCookie(cookie); return mapping.findForward("dashboard"); }
From source file:com.music.web.AuthenticationController.java
@RequestMapping("/logout") public String logout(HttpSession session, HttpServletRequest request, HttpServletResponse response) { session.invalidate();/* w w w . j av a 2 s .co m*/ Cookie cookie = WebUtils.getCookie(request, SocialSignInAdapter.AUTH_TOKEN_COOKIE_NAME); if (cookie != null) { cookie.setMaxAge(0); cookie.setDomain(".computoser.com"); cookie.setPath("/"); response.addCookie(cookie); } cookie = WebUtils.getCookie(request, SocialSignInAdapter.AUTH_TOKEN_SERIES_COOKIE_NAME); if (cookie != null) { cookie.setMaxAge(0); cookie.setDomain(".computoser.com"); cookie.setPath("/"); response.addCookie(cookie); } return "redirect:/"; }
From source file:com.hypersocket.session.json.SessionUtils.java
public void addAPISession(HttpServletRequest request, HttpServletResponse response, Session session) { Cookie cookie = new Cookie(HYPERSOCKET_API_SESSION, session.getId()); cookie.setMaxAge(60 * session.getTimeout()); cookie.setSecure(request.getProtocol().equalsIgnoreCase("https")); cookie.setPath("/"); //cookie.setDomain(request.getServerName()); response.addCookie(cookie); }