List of usage examples for javax.servlet.http Cookie Cookie
public Cookie(String name, String value)
From source file:alpha.portal.webapp.util.RequestUtil.java
/** * Convenience method to set a cookie.// w w w . j a v a 2 s . co m * * @param response * the current response * @param name * the name of the cookie * @param value * the value of the cookie * @param path * the path to set it on */ public static void setCookie(final HttpServletResponse response, final String name, final String value, final String path) { if (RequestUtil.log.isDebugEnabled()) { RequestUtil.log.debug("Setting cookie '" + name + "' on path '" + path + "'"); } final Cookie cookie = new Cookie(name, value); cookie.setSecure(false); cookie.setPath(path); cookie.setMaxAge(3600 * 24 * 30); // 30 days response.addCookie(cookie); }
From source file:com.tamnd.app.filters.CsrfHeaderFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN"); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie);//ww w. j av a 2 s . co m } } filterChain.doFilter(request, response); // CsrfToken token = (CsrfToken) request.getAttribute(REQUEST_ATTRIBUTE_NAME); // if (token != null) { // response.setHeader(RESPONSE_HEADER_NAME, token.getHeaderName()); // response.setHeader(RESPONSE_PARAM_NAME, token.getParameterName()); // response.setHeader(RESPONSE_TOKEN_NAME , token.getToken()); // } // filterChain.doFilter(request, response); }
From source file:com.yahoo.yos.RequestToken.java
public Cookie getCookie() throws UnsupportedEncodingException, JSONException { return new Cookie("yosdk_rt", new String(Base64.encodeBase64(toJSONObject().toString().getBytes("UTF-8")), "UTF-8")); }
From source file:com.bennavetta.appsite.serve.HttpServletResp.java
@Override public void setCookie(String name, String value, int maxAge) { Cookie cookie = new Cookie(name, value); cookie.setMaxAge(maxAge);// w ww . j av a2 s. c o m response.addCookie(cookie); }
From source file:com.reever.humilheme.web.CookieController.java
public Cookie createCookie(HttpServletRequest request, HttpServletResponse response, String conteudo) { String path = StringUtils.isEmpty(request.getContextPath()) ? "/" : request.getContextPath(); try {/*from w w w. j ava 2 s . c o m*/ conteudo = URLEncoder.encode(conteudo, "UTF-8"); } catch (UnsupportedEncodingException e) { _logger.error("Erro no encode do cookie", e); } Cookie cookie = new Cookie(nomeCookie, conteudo); cookie.setMaxAge(expiry); cookie.setPath(path); cookie.setVersion(1); response.addCookie(cookie); return cookie; }
From source file:net.anthonychaves.bookmarks.web.TokenController.java
@RequestMapping(method = RequestMethod.POST) public String rememberMe(HttpSession session, HttpServletResponse response, ModelMap model) { int duration = 168; //hours to remember me for = 1 week User user = (User) session.getAttribute("user"); String tokenId = tokenService.setupNewLoginToken(user); Cookie cookie = new Cookie("loginToken", tokenId); cookie.setMaxAge(duration * 60 * 60); cookie.setPath("/bookmarks"); response.addCookie(cookie);/*from www . j a va 2 s . c o m*/ model.addAttribute("status", "success"); return "redirect:/b/user"; }
From source file:com.pureinfo.tgirls.servlet.CookieTestServlet.java
@Override protected void doPost(HttpServletRequest _req, HttpServletResponse _resp) throws ServletException, IOException { try {//w w w . j a v a 2 s . c o m String userId = _req.getParameter("id"); if (StringUtils.isEmpty(userId)) { userId = "1"; } IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); User u = mgr.getUserByTaobaoId(userId); _req.getSession().setAttribute(ArkHelper.ATTR_LOGIN_USER, u); Cookie c = new Cookie("", ""); // _req.getCookies()[0]. } catch (PureException e) { // TODO Auto-generated catch block e.printStackTrace(System.err); } }
From source file:de.escidoc.core.common.servlet.UserHandleCookieUtil.java
/** * Creates an authentication cookie holding the provided eSciDoc user handle.<br> The cookie is valid for all * locations of the eSciDoc domain. Its max age is set to the value of the configuration parameter * escidoc.userHandle.cookie.lifetime./*from w w w . j a va 2s . c om*/ * * @param handle The eSciDocUserHandle. * @return Returns the created {@link Cookie}. * @throws WebserverSystemException Thrown in case of an internal error (configuration parameter not retrievable). */ public static Cookie createAuthCookie(final String handle) throws WebserverSystemException { final Cookie authCookie = new Cookie(EscidocServlet.COOKIE_LOGIN, handle); authCookie.setMaxAge(getEscidocCookieLifetime()); // Set the cookie for all locations of the escidoc domain authCookie.setPath("/"); return authCookie; }
From source file:com.junly.service.helper.TicketHelper.java
/** <p class="detail"> * cookie/*from ww w. j a va2s . co m*/ * </p> * @author junly * @date 2016422 * @param response * @param ticket */ public void setCookie(HttpServletRequest request, HttpServletResponse response, String ticket) { // ? Cookie cookie = new Cookie(ViewContants.LOGIN_TICKET_KEY, ticket); // ? ??? cookie.setDomain(request.getServerName()); // path cookie.setPath("/"); // ?? cookie.setMaxAge(ViewContants.TRUST_COOKIE_TIME); // response.addCookie(cookie); }
From source file:scratch.cucumber.example.security.servlet.XAuthTokenHttpServletRequestBinder.java
@Override public void add(HttpServletResponse response, String username) { final String token = tokenFactory.create(username); response.addHeader(X_AUTH_TOKEN, token); response.addCookie(new Cookie(X_AUTH_TOKEN, token)); }