List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:org.jboss.dashboard.ui.controller.requestChain.NavigationCookieProcessor.java
public boolean processRequest() throws Exception { HttpServletRequest request = getHttpRequest(); HttpServletResponse response = getHttpResponse(); if (isUseCookie()) { Section section = getNavigationManager().getCurrentSection(); if (section != null) { String lang = LocaleManager.lookup().getCurrentLang(); StringBuffer sb = new StringBuffer(); sb.append(lang).append(cookieSeparator).append(Long.toString(section.getId().longValue(), idsRadix)) .append(cookieSeparator); sb.append(section.getWorkspace().getId()); Cookie navigationCookie = new Cookie(cookieName, sb.toString()); navigationCookie.setPath(StringUtils.defaultIfEmpty(request.getContextPath(), "/")); response.addCookie(navigationCookie); }/*from w ww . j a v a 2 s. com*/ } return true; }
From source file:org.geonetwork.http.SessionTimeoutCookieFilter.java
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse httpResp = (HttpServletResponse) resp; HttpServletRequest httpReq = (HttpServletRequest) req; HttpSession session = httpReq.getSession(false); //If we are not being accessed by a bot/crawler if (session != null) { long currTime = System.currentTimeMillis(); Cookie cookie = new Cookie("serverTime", "" + currTime); cookie.setPath("/"); cookie.setSecure(req.getServletContext().getSessionCookieConfig().isSecure()); httpResp.addCookie(cookie);/*from www. ja va 2 s . co m*/ UserSession userSession = null; if (session != null) { Object tmp = session.getAttribute(JeevesServlet.USER_SESSION_ATTRIBUTE_KEY); if (tmp instanceof UserSession) { userSession = (UserSession) tmp; } } // If user is authenticated, then set expiration time if (userSession != null && StringUtils.isNotEmpty(userSession.getName())) { long expiryTime = currTime + session.getMaxInactiveInterval() * 1000; cookie = new Cookie("sessionExpiry", "" + expiryTime); } else { cookie = new Cookie("sessionExpiry", "" + currTime); } cookie.setPath("/"); cookie.setSecure(req.getServletContext().getSessionCookieConfig().isSecure()); httpResp.addCookie(cookie); } filterChain.doFilter(req, resp); }
From source file:fr.gael.dhus.spring.security.handler.LoginSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { String name = authentication.getName(); try {/*ww w. ja v a2 s .c o m*/ ValidityAuthentication auth = (ValidityAuthentication) authentication; name = EncryptPassword.encrypt(name, PasswordEncryption.MD5); Cookie authCookie = new Cookie(CookieKey.AUTHENTICATION_COOKIE_NAME, name); authCookie.setPath("/"); authCookie.setHttpOnly(true); authCookie.setMaxAge(-1); String validity = auth.getValidity(); // Cookie validityCookie = new Cookie (CookieKey.VALIDITY_COOKIE_NAME, // validity); // validityCookie.setPath ("/"); // validityCookie.setHttpOnly (true); String integrity = EncryptPassword.encrypt(name + validity, PasswordEncryption.SHA1); Cookie integrityCookie = new Cookie(CookieKey.INTEGRITY_COOKIE_NAME, integrity); integrityCookie.setPath("/"); integrityCookie.setHttpOnly(true); integrityCookie.setMaxAge(-1); response.addCookie(authCookie); // response.addCookie (validityCookie); response.addCookie(integrityCookie); request.getSession().setAttribute("integrity", integrity); SecurityContextProvider.saveSecurityContext(integrity, SecurityContextHolder.getContext()); } catch (Exception e) { LOGGER.warn("Authentication process failed ! No cookie was generated", e); } }
From source file:com.epam.cme.storefront.security.cookie.EnhancedCookieGenerator.java
/** * //ww w. java 2 s.c om * Sets dynamically the {@link Cookie#setPath(String)} value using available * {@link HttpServletRequest#getContextPath()}. */ protected void setEnhancedCookiePath(final HttpServletRequest request, final Cookie cookie) { if (!canUseDefaultPath()) { cookie.setPath(request.getContextPath()); } }
From source file:org.eclipse.dirigible.runtime.content.ThemesServlet.java
private void setCookieUser(HttpServletResponse resp, String themeName) { Cookie cookie = new Cookie(ICommonConstants.COOKIE_THEME, themeName); cookie.setMaxAge(30 * 24 * 60 * 60); cookie.setPath(SLASH); resp.addCookie(cookie);/* ww w. j a v a 2s .c o m*/ }
From source file:com.aurel.track.master.ModuleBL.java
public static Cookie sendPOSTRequest(String urlString) { Cookie responseCookie = null; try {/*w w w .j av a 2 s .c o m*/ HttpClient httpclient = new DefaultHttpClient();//HttpClients.createDefault(); HttpPost httppost = new HttpPost(urlString); // Request parameters and other properties. //Execute and get the response. HttpContext localContext = new BasicHttpContext(); CookieStore cookieStore = new BasicCookieStore(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); HttpResponse response = httpclient.execute(httppost, localContext); if (cookieStore.getCookies().size() > 0) { List<org.apache.http.cookie.Cookie> cookies = cookieStore.getCookies(); for (org.apache.http.cookie.Cookie cookie : cookies) { if (cookie.getName().equals("JSESSIONID")) { responseCookie = new Cookie(cookie.getName(), cookie.getValue()); responseCookie.setPath(cookie.getPath()); responseCookie.setDomain(cookie.getDomain()); } } } if (response.getEntity() != null) { response.getEntity().consumeContent(); } } catch (Exception ex) { LOGGER.debug(ExceptionUtils.getStackTrace(ex)); } return responseCookie; }
From source file:com.ms.commons.summer.security.web.DefaultSecurityFormResolver.java
/** * ?tokenCookie/*from w w w . j a v a2 s . c om*/ * * @param request * @param str */ public void renderSessionTokenInput(final HttpServletRequest request, final HttpServletResponse response, final StringBuilder str) { String token = createToken(); Cookie cookie = new Cookie(FORM_RESUBMIT_TOKEN, token); cookie.setPath("/"); response.addCookie(cookie); str.append("<input type=\"hidden\" name=\"").append(FORM_RESUBMIT_TOKEN).append("\" value=\"").append(token) .append("\"/>"); if (logger.isDebugEnabled()) { logger.debug("render session token value = " + token); } }
From source file:de.berlios.jhelpdesk.web.preferences.LookAndFeelEditController.java
private Cookie createCookie(HttpServletRequest req, Locale loc) { Cookie cookie = new Cookie("jhd_locale", loc.getLanguage()); cookie.setMaxAge(SECONDS_BY_WEEK);/*from w ww . ja v a 2 s . co m*/ cookie.setPath(req.getContextPath()); return cookie; }
From source file:com.ms.commons.summer.security.web.DefaultSecurityFormResolver.java
/** * ?token????InvalidTokenException/*from ww w .j ava 2s . c o m*/ * * @param request * @param response * @throws InvalidTokenException */ public void validSessionToken(final HttpServletRequest request, final HttpServletResponse response) throws InvalidTokenException { Cookie[] cookies = request.getCookies(); String ctoken = null; if (cookies != null) { for (Cookie cookie : cookies) { if (FORM_RESUBMIT_TOKEN.equals(cookie.getName())) { ctoken = cookie.getValue(); break; } } } String rtoken = request.getParameter(FORM_RESUBMIT_TOKEN); if (rtoken == null || rtoken.length() == 0) { throw new InvalidTokenException("can't find token in request"); } if (ctoken == null || ctoken.length() == 0) { throw new InvalidTokenException("can't find token in cookie"); } if (!ctoken.equals(rtoken)) { throw new InvalidTokenException("failed to check for token in request"); } // cookietoken? Cookie c = new Cookie(FORM_RESUBMIT_TOKEN, ""); c.setPath("/"); response.addCookie(c); }
From source file:com.mobileman.projecth.web.util.PersistentCookieHelper.java
public void setUser(HttpServletResponse response, User user) { String hash = createHash("" + System.currentTimeMillis(), user); //save hash to cvookie Cookie cookie = new Cookie(COOKIE_NAME, hash); cookie.setPath(PATH); cookie.setMaxAge(365 * 24 * 3600);//from www . ja va 2s .c om response.addCookie(cookie); }