List of usage examples for javax.servlet.http HttpServletResponse addCookie
public void addCookie(Cookie cookie);
From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java
protected void setCookies(final PageInfo pageInfo, final HttpServletResponse response) { Collection<SerializableCookie> cookies = pageInfo.getSerializableCookies(); for (SerializableCookie cookie : cookies) { response.addCookie(cookie.toCookie()); }// w w w. j a v a 2 s . c o m }
From source file:de.escidoc.core.aa.servlet.Login.java
/** * Sends the response in case of successful logout of the user.<br> <ul> <li>The cookie containing the eSciDoc user * handle is deleted.</li> <li>Either <ul> <li>the user is redirected to the provided targetUrl, or</li> <li>a * default logout page is presented to the user, if no targetUrl has been provided</li> </ul> </li> </ul> * * @param request The http request.//w w w. j a va 2s . co m * @param response The http response. * @throws IOException In case of an error. * @throws WebserverSystemException Thrown if cookie creation fails due to an internal error. */ private void sendLoggedOut(final HttpServletRequest request, final HttpServletResponse response) throws IOException, WebserverSystemException { response.reset(); response.setContentType("text/html"); // delete cookies response.addCookie(deleteAuthCookie()); response.addCookie(deleteSpringSecurityCookie()); String redirectUrl; try { redirectUrl = retrieveDecodedTarget(request); } catch (final MissingParameterException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Error on retriving decoded target.", e); } redirectUrl = null; } if (redirectUrl == null) { sendResponse(response, getLoggedOutPage(null)); } else { sendRedirectingResponse(response, getLoggedOutPage(redirectUrl), redirectUrl); } }
From source file:custom.application.login.java
public void logout() { HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); try {/* w w w . j a va2 s . c o m*/ this.passport = new passport(request, response, "waslogined"); this.passport.logout(); if (request.getCookies() != null) { Cookie[] cookies = request.getCookies(); int i = 0; Cookie cookie; while (cookies.length > i) { cookie = cookies[i]; cookie.setMaxAge(0); cookie.setValue(""); response.addCookie(cookie); i++; } } Reforward reforward = new Reforward(request, response); reforward.setDefault(this.getLink(this.context.getAttribute("default.login.page").toString())); reforward.forward(); } catch (ApplicationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:net.geant.edugain.filter.EduGAINFilter.java
private void attachCookies(String name, HashMap<String, String> attrs, HttpServletResponse response, boolean outdated) throws ServletException { String maxAge = "0"; Cookie lcook = null;//from w ww .ja v a2 s . c o m if (!outdated) { lcook = new Cookie(name, cipher.encode(name, generateCookie(attrs, outdated))); } else { lcook = new Cookie(name, ""); lcook.setMaxAge(Integer.parseInt(maxAge)); } lcook.setPath(this.location); response.addCookie(lcook); }
From source file:eu.semlibproject.annotationserver.servlets.OpenIDAuthentication.java
private void processReturn(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { User cUser = this.verifyResponse(req); if (cUser == null || !cUser.isAuthenticated()) { req.setAttribute(SemlibConstants.OPENID_AUTH_ERROR, "1"); req.setAttribute(SemlibConstants.OPENID_ERROR_MESSAGE, SemlibConstants.OPENID_ERROR_MSG_AUTH_ERROR); getServletContext().getRequestDispatcher(returnPath).forward(req, resp); } else {//from ww w . j a v a2 s . co m String userID = cUser.getUserID(); String accessToken = TokenManager.getInstance().generateAndAddNewToken(cUser); Cookie cookie = CookiesManager.getInstance().generateNewASCookie(accessToken); resp.addCookie(cookie); req.setAttribute(SemlibConstants.OPENID_USERLOGGED, "1"); req.setAttribute(SemlibConstants.OPENID_USERID, userID); //String urlForRedirect = resp.encodeRedirectURL(returnPath.toString()); //resp.sendRedirect(urlForRedirect); getServletContext().getRequestDispatcher(returnPath).forward(req, resp); } }
From source file:neu.edu.lab08.HomeController.java
@RequestMapping(value = "/logout", method = RequestMethod.GET) public String logout(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { cookies[i].setValue(""); cookies[i].setPath("/"); cookies[i].setMaxAge(0);//from www . j a va 2s.c o m response.addCookie(cookies[i]); } } // model.addAttribute("user", null); // model.addAttribute("messageList", null); // model.addAttribute("contactsList", null); // HttpSession session = request.getSession(); // session.setAttribute("username", null); return initUserLoginForm(model, request); }
From source file:com.sinosoft.one.mvc.web.var.FlashImpl.java
public void writeNewMessages() { if (logger.isDebugEnabled()) { logger.debug("writeNextMessages"); }// w ww .j av a 2 s .c om HttpServletResponse response = invocation.getResponse(); List<String> responseCookies = null; for (Map.Entry<String, String> entry : next.entrySet()) { if (responseCookies == null) { responseCookies = new ArrayList<String>(next.size()); } String cookieValue; if (entry.getValue() == null) { cookieValue = ""; } else { try { cookieValue = base64.encodeToString(entry.getValue().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new Error(e); } } Cookie cookie = new Cookie(cookiePrefix + entry.getKey(), cookieValue); cookie.setPath("/"); // cookie.setMaxAge(1); response.addCookie(cookie); responseCookies.add(cookie.getName()); if (logger.isDebugEnabled()) { logger.debug("write flash cookie:" + cookie.getName() + "=" + cookie.getValue()); } } for (Map.Entry<String, String> entry : last.entrySet()) { if (responseCookies == null || !responseCookies.contains(entry.getKey())) { Cookie c = new Cookie(entry.getKey(), null); c.setMaxAge(0); c.setPath("/"); response.addCookie(c); if (logger.isDebugEnabled()) { logger.debug("delete flash cookie:" + c.getName() + "=" + c.getValue()); } } } }
From source file:com.pureinfo.tgirls.servlet.TestServlet.java
private void addCookie(User _loginUser, HttpServletRequest _request, HttpServletResponse _response) throws UnsupportedEncodingException { Cookie name = new Cookie(CookieUtils.NAME, URLEncoder.encode(_loginUser.getName(), "utf-8")); Cookie nickName = new Cookie(CookieUtils.NICK_NAME, URLEncoder.encode(_loginUser.getNickname(), "utf-8")); Cookie taobaoId = new Cookie(CookieUtils.TAOBAO_ID, URLEncoder.encode(_loginUser.getTaobaoID(), "utf-8")); Cookie img = new Cookie(CookieUtils.HEAD_IMG, URLEncoder.encode(_loginUser.getHeadImg(), "utf-8")); //Cookie topsession = new Cookie(CookieUtils.TOP_SESSION_ID, _request.getParameter(APPConstants.REQ_PARAMETER_SESSION)); //name.setPath("/"); //nickName.setPath(_request.getContextPath()); _response.addCookie(name); _response.addCookie(nickName);//from w ww .j a va2s . c o m _response.addCookie(taobaoId); _response.addCookie(img); }
From source file:com.laxser.blitz.web.var.FlashImpl.java
public void writeNewMessages() { if (logger.isDebugEnabled()) { logger.debug("writeNextMessages"); }// w w w . j a v a2 s . co m HttpServletResponse response = invocation.getResponse(); List<String> responseCookies = null; for (Map.Entry<String, String> entry : next.entrySet()) { if (responseCookies == null) { responseCookies = new ArrayList<String>(next.size()); } String cookieValue; if (entry.getValue() == null) { cookieValue = ""; } else { try { cookieValue = base64.encodeToString(entry.getValue().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new Error(e); } } Cookie cookie = new Cookie(cookiePrefix + entry.getKey(), cookieValue); cookie.setPath("/"); cookie.setMaxAge(1); response.addCookie(cookie); responseCookies.add(cookie.getName()); if (logger.isDebugEnabled()) { logger.debug("write flash cookie:" + cookie.getName() + "=" + cookie.getValue()); } } for (Map.Entry<String, String> entry : last.entrySet()) { if (responseCookies == null || !responseCookies.contains(entry.getKey())) { Cookie c = new Cookie(entry.getKey(), null); c.setMaxAge(0); c.setPath("/"); response.addCookie(c); if (logger.isDebugEnabled()) { logger.debug("delete flash cookie:" + c.getName() + "=" + c.getValue()); } } } }
From source file:com.vmware.identity.openidconnect.sample.RelyingPartyController.java
@RequestMapping(value = "/logout_slo", method = RequestMethod.GET) public void logoutSlo(HttpServletRequest request, HttpServletResponse response) throws OIDCClientException { SessionID sessionId = getSessionID(request); if (sessionId == null) { return;//from ww w. j a v a2 s .c o m } OIDCTokens tokens = this.sessionManager.remove(sessionId); assert tokens != null; SessionID sloSid = ListenerHelper.parseSLORequest(request); assert Objects.equals(sloSid, tokens.getIDToken().getSessionID()); response.addCookie(logoutSessionCookie()); }