List of usage examples for javax.servlet.http Cookie getVersion
public int getVersion()
From source file:org.jasig.portal.portlet.container.services.SessionOnlyPortletCookieImpl.java
SessionOnlyPortletCookieImpl(Cookie cookie) { this.name = cookie.getName(); this.value = cookie.getValue(); this.comment = cookie.getComment(); this.domain = cookie.getDomain(); this.path = cookie.getPath(); this.version = cookie.getVersion(); this.secure = cookie.getSecure(); setMaxAge(cookie.getMaxAge());// w w w . j av a 2 s.co m }
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.j ava 2 s. c o m*/ 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:org.opencms.flex.CmsFlexResponse.java
/** * Method overloaded from the standard HttpServletRequest API.<p> * * Cookies must be set directly as a header, otherwise they might not be set * in the super class.<p>/*from ww w .j av a2 s. c o m*/ * * @see javax.servlet.http.HttpServletResponseWrapper#addCookie(javax.servlet.http.Cookie) */ @Override public void addCookie(Cookie cookie) { if (cookie == null) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_ADD_COOKIE_0)); } StringBuffer header = new StringBuffer(128); // name and value header.append(cookie.getName()); header.append('='); header.append(cookie.getValue()); // add version 1 / RFC 2109 specific information if (cookie.getVersion() == 1) { header.append("; Version=1"); // comment if (cookie.getComment() != null) { header.append("; Comment="); header.append(cookie.getComment()); } } // domain if (cookie.getDomain() != null) { header.append("; Domain="); header.append(cookie.getDomain()); } // max-age / expires if (cookie.getMaxAge() >= 0) { if (cookie.getVersion() == 0) { // old Netscape format header.append("; Expires="); long time; if (cookie.getMaxAge() == 0) { time = 10000L; } else { time = System.currentTimeMillis() + (cookie.getMaxAge() * 1000L); } header.append(CmsDateUtil.getOldCookieDate(time)); } else { // new RFC 2109 format header.append("; Max-Age="); header.append(cookie.getMaxAge()); } } // path if (cookie.getPath() != null) { header.append("; Path="); header.append(cookie.getPath()); } // secure if (cookie.getSecure()) { header.append("; Secure"); } addHeader("Set-Cookie", header.toString()); }
From source file:org.opensubsystems.core.util.servlet.WebUtils.java
/** * Create debug string containing all parameter names and their values from * the request, all attributes, all cookies and other data characterizing the * request.//from w w w. j av a 2s .c om * * @param hsrqRequest - the servlet request. * @return String - debug string containing all parameter names and their * values from the request */ public static String debug(HttpServletRequest hsrqRequest) { Enumeration enumNames; Enumeration enumValues; Iterator iterValues; String strName; String[] arValues; Cookie[] arCookies; int iIndex; Map<String, String[]> mpParamMap; StringBuilder sbfReturn = new StringBuilder(); sbfReturn.append("HttpServletRequest=["); sbfReturn.append("\nRemoteAddress="); sbfReturn.append(StringUtils.valueIfNotNull(hsrqRequest.getRemoteAddr())); sbfReturn.append(";"); sbfReturn.append("\nRemotePort="); sbfReturn.append(hsrqRequest.getRemotePort()); sbfReturn.append(";"); sbfReturn.append("\nRemoteHost="); sbfReturn.append(StringUtils.valueIfNotNull(hsrqRequest.getRemoteHost())); sbfReturn.append(";"); sbfReturn.append("\nRemoteUser="); sbfReturn.append(StringUtils.valueIfNotNull(hsrqRequest.getRemoteUser())); sbfReturn.append(";"); sbfReturn.append("\nFullURL="); sbfReturn.append(getFullRequestURL(hsrqRequest)); sbfReturn.append(";"); sbfReturn.append("\nContextPath="); sbfReturn.append(hsrqRequest.getContextPath()); sbfReturn.append(";"); sbfReturn.append("\nServletPath="); sbfReturn.append(hsrqRequest.getServletPath()); sbfReturn.append(";"); sbfReturn.append("\nPathInfo ="); sbfReturn.append(hsrqRequest.getPathInfo()); sbfReturn.append(";"); sbfReturn.append("\nRequestURI="); sbfReturn.append(hsrqRequest.getRequestURI()); sbfReturn.append(";"); sbfReturn.append("\nRequestURL="); sbfReturn.append(hsrqRequest.getRequestURL()); sbfReturn.append(";"); sbfReturn.append("\nMethod="); sbfReturn.append(hsrqRequest.getMethod()); sbfReturn.append(";"); sbfReturn.append("\nAuthenticationType="); sbfReturn.append(StringUtils.valueIfNotNull(hsrqRequest.getAuthType())); sbfReturn.append(";"); sbfReturn.append("\nCharacterEncoding="); sbfReturn.append(StringUtils.valueIfNotNull(hsrqRequest.getCharacterEncoding())); sbfReturn.append(";"); sbfReturn.append("\nContentType="); sbfReturn.append(StringUtils.valueIfNotNull(hsrqRequest.getContentType())); sbfReturn.append(";"); sbfReturn.append("\nMultiPart="); sbfReturn.append(ServletFileUpload.isMultipartContent(hsrqRequest)); sbfReturn.append(";"); // Parameters //////////////////////////////////////////////////////////// try { Map.Entry<String, String[]> entry; // Use getParameterMap rather than request.getParameterNames since it // correctly handles multipart requests mpParamMap = WebParamUtils.getParameterMap("WebUtils: ", hsrqRequest); for (iterValues = mpParamMap.entrySet().iterator(); iterValues.hasNext();) { entry = (Map.Entry<String, String[]>) iterValues.next(); strName = entry.getKey(); arValues = entry.getValue(); sbfReturn.append("\nParam="); sbfReturn.append(strName); sbfReturn.append(" values="); for (iIndex = 0; iIndex < arValues.length; iIndex++) { sbfReturn.append(arValues[iIndex]); if (iIndex < (arValues.length - 1)) { sbfReturn.append(";"); } } if (iterValues.hasNext()) { sbfReturn.append(";"); } } } catch (OSSInvalidDataException ex) { sbfReturn.append("<Cannot access parameter map of the request>"); s_logger.log(Level.SEVERE, "Cannot access parameter map of the request", ex); } // Uploaded files //////////////////////////////////////////////////////// if (ServletFileUpload.isMultipartContent(hsrqRequest)) { try { FileItem item; Map<String, FileItem> mpFiles; TwoElementStruct<Map<String, Object>, Map<String, FileItem>> params; params = WebParamUtils.getMultipartParameters("WebUtils: ", hsrqRequest); mpFiles = params.getSecond(); for (iterValues = mpFiles.values().iterator(); iterValues.hasNext();) { item = (FileItem) iterValues.next(); sbfReturn.append("\nUpload="); sbfReturn.append(item.getName()); sbfReturn.append(" field="); sbfReturn.append(item.getFieldName()); sbfReturn.append(" contentType="); sbfReturn.append(item.getContentType()); sbfReturn.append(" isInMemory="); sbfReturn.append(item.isInMemory()); sbfReturn.append(" sizeInBytes="); sbfReturn.append(item.getSize()); if (iterValues.hasNext()) { sbfReturn.append(";"); } } } catch (OSSInvalidDataException ex) { sbfReturn.append("<Cannot access list of multipart parameters>"); s_logger.log(Level.SEVERE, "Cannot access list of multipart parameters", ex); } } // Headers /////////////////////////////////////////////////////////////// for (enumNames = hsrqRequest.getHeaderNames(); enumNames.hasMoreElements();) { strName = (String) enumNames.nextElement(); sbfReturn.append("\nHeader="); sbfReturn.append(strName); sbfReturn.append(" values="); for (enumValues = hsrqRequest.getHeaders(strName); enumValues.hasMoreElements();) { sbfReturn.append(enumValues.nextElement()); if (enumValues.hasMoreElements()) { sbfReturn.append(";"); } } if (enumNames.hasMoreElements()) { sbfReturn.append(";"); } } // Cookies /////////////////////////////////////////////////////////////// arCookies = hsrqRequest.getCookies(); if (arCookies != null) { Cookie cookie; for (iIndex = 0; iIndex < arCookies.length; iIndex++) { cookie = arCookies[iIndex]; sbfReturn.append("\nCookie="); sbfReturn.append(cookie.getName()); sbfReturn.append(" path="); sbfReturn.append(cookie.getPath()); sbfReturn.append(" path="); sbfReturn.append(cookie.getDomain()); sbfReturn.append(" maxage="); sbfReturn.append(cookie.getMaxAge()); sbfReturn.append(" version="); sbfReturn.append(cookie.getVersion()); sbfReturn.append(" secure="); sbfReturn.append(cookie.getSecure()); sbfReturn.append(" value="); sbfReturn.append(cookie.getValue()); sbfReturn.append(" comment="); sbfReturn.append(StringUtils.valueIfNotNull(cookie.getComment())); if (iIndex < (arCookies.length - 1)) { sbfReturn.append(";"); } } } if (enumNames.hasMoreElements()) { sbfReturn.append(";"); } // Attributes //////////////////////////////////////////////////////////// for (enumNames = hsrqRequest.getAttributeNames(); enumNames.hasMoreElements();) { strName = (String) enumNames.nextElement(); sbfReturn.append("\nAttribute="); sbfReturn.append(strName); sbfReturn.append(" value="); sbfReturn.append(hsrqRequest.getAttribute(strName)); if (enumNames.hasMoreElements()) { sbfReturn.append(";"); } } // Content /////////////////////////////////////////////////////////////// sbfReturn.append("\nContent="); try { sbfReturn.append(StringUtils.convertStreamToString(hsrqRequest.getInputStream(), true)); } catch (IOException ex) { sbfReturn.append("<Cannot access input stream of the request>"); s_logger.log(Level.SEVERE, "Cannot access input stream of the request", ex); } sbfReturn.append(";"); return sbfReturn.toString(); }
From source file:org.piraso.web.base.WebEntryUtils.java
public static CookieEntry toEntry(Cookie cookie) { CookieEntry entry = new CookieEntry(); entry.setName(cookie.getName());//w ww.j a va 2 s .co m entry.setValue(cookie.getValue()); entry.setComment(cookie.getComment()); entry.setDomain(cookie.getDomain()); entry.setMaxAge(cookie.getMaxAge()); entry.setPath(cookie.getPath()); entry.setSecure(cookie.getSecure()); entry.setVersion(cookie.getVersion()); return entry; }
From source file:org.projectforge.business.user.filter.UserFilter.java
@Override public void doFilter(final ServletRequest req, final ServletResponse resp, final FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; if (log.isDebugEnabled() == true) { log.debug("doFilter " + request.getRequestURI() + ": " + request.getSession().getId()); final Cookie[] cookies = request.getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { log.debug("Cookie " + cookie.getName() + ", path=" + cookie.getPath() + ", value=" + cookie.getValue() + ", secure=" + cookie.getVersion() + ", maxAge=" + cookie.getMaxAge() + ", domain=" + cookie.getDomain()); }//from ww w . j av a 2 s . c o m } } final HttpServletResponse response = (HttpServletResponse) resp; UserContext userContext = null; try { MDC.put("ip", (Object) request.getRemoteAddr()); MDC.put("session", (Object) request.getSession().getId()); if (ignoreFilterFor(request) == true) { // Ignore the filter for this request: if (log.isDebugEnabled() == true) { log.debug("Ignore: " + request.getRequestURI()); } chain.doFilter(request, response); } else { // final boolean sessionTimeout = request.isRequestedSessionIdValid() == false; userContext = (UserContext) request.getSession().getAttribute(SESSION_KEY_USER); if (userContext != null) { if (updateRequiredFirst == false) { // Get the fresh user from the user cache (not in maintenance mode because user group cache is perhaps not initialized correctly // if updates of e. g. the user table are necessary. userContext.refreshUser(); } if (log.isDebugEnabled() == true) { log.debug("User found in session: " + request.getRequestURI()); } } else if (updateRequiredFirst == false) { // Ignore stay-logged-in if redirect to update page is required. userContext = checkStayLoggedIn(request, response); if (userContext != null) { if (log.isDebugEnabled() == true) { log.debug("User's stay logged-in cookie found: " + request.getRequestURI()); } userContext.setStayLoggedIn(true); // Used by MenuMobilePage. UserFilter.login(request, userContext); } } final PFUserDO user = userContext != null ? userContext.getUser() : null; if (user != null) { MDC.put("user", (Object) user.getUsername()); ThreadLocalUserContext.setUserContext(userContext); request = decorateWithLocale(request); chain.doFilter(request, response); } else { if (((HttpServletRequest) req).getRequestURI().startsWith(WICKET_PAGES_PREFIX) == true) { // Access-checking is done by Wicket, not by this filter: request = decorateWithLocale(request); chain.doFilter(request, response); } else { response.getWriter().append("No access."); } } } } finally { ThreadLocalUserContext.clear(); MDC.remove("ip"); MDC.remove("session"); final PFUserDO user = userContext != null ? userContext.getUser() : null; if (user != null) { MDC.remove("user"); } if (log.isDebugEnabled() == true) { StringBuffer sb = new StringBuffer(); sb.append("doFilter finished for "); sb.append(request.getRequestURI()); if (request.getSession(false) != null) { sb.append(request.getSession(false).getId()); } else { sb.append("No active session available."); } log.debug(sb.toString()); } } }
From source file:org.projectforge.web.UserFilter.java
public void doFilter(final ServletRequest req, final ServletResponse resp, final FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; if (log.isDebugEnabled() == true) { log.debug("doFilter " + request.getRequestURI() + ": " + request.getSession().getId()); final Cookie[] cookies = request.getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { log.debug("Cookie " + cookie.getName() + ", path=" + cookie.getPath() + ", value=" + cookie.getValue() + ", secure=" + cookie.getVersion() + ", maxAge=" + cookie.getMaxAge() + ", domain=" + cookie.getDomain()); }//from ww w . j a v a 2 s .co m } } final HttpServletResponse response = (HttpServletResponse) resp; PFUserDO user = null; try { MDC.put("ip", request.getRemoteAddr()); MDC.put("session", request.getSession().getId()); if (ignoreFilterFor(request) == true) { // Ignore the filter for this request: if (log.isDebugEnabled() == true) { log.debug("Ignore: " + request.getRequestURI()); } chain.doFilter(request, response); } else { // final boolean sessionTimeout = request.isRequestedSessionIdValid() == false; user = (PFUserDO) request.getSession().getAttribute(SESSION_KEY_USER); if (user != null) { if (log.isDebugEnabled() == true) { log.debug("User found in session: " + request.getRequestURI()); } } else if (updateRequiredFirst == false) { // Ignore stay-logged-in if redirect to update page is required. user = checkStayLoggedIn(request, response); if (user != null) { if (log.isDebugEnabled() == true) { log.debug("User's stay logged-in cookie found: " + request.getRequestURI()); } user.setAttribute(USER_ATTR_STAY_LOGGED_IN, true); // Used by MenuMobilePage. UserFilter.login(request, user); } } if (user != null) { MDC.put("user", user.getUsername()); PFUserContext.setUser(user); request = decorateWithLocale(request, user); chain.doFilter(request, response); } else { if (((HttpServletRequest) req).getRequestURI().startsWith(WICKET_PAGES_PREFIX) == true) { // Access-checking is done by Wicket, not by this filter: request = decorateWithLocale(request, user); chain.doFilter(request, response); } else { response.getWriter().append("No access."); } } } } finally { PFUserContext.setUser(null); MDC.remove("ip"); MDC.remove("session"); if (user != null) { MDC.remove("user"); } if (log.isDebugEnabled() == true) { log.debug("doFilter finished for " + request.getRequestURI() + ": " + request.getSession().getId()); } } }
From source file:org.sakaiproject.util.RequestFilter.java
protected void addCookie(HttpServletResponse res, Cookie cookie) { if (!m_cookieHttpOnly) { // Use the standard servlet mechanism for setting the cookie res.addCookie(cookie);//w w w. j a va 2 s. c om } else { // Set the cookie manually StringBuffer sb = new StringBuffer(); ServerCookie.appendCookieValue(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getComment(), cookie.getMaxAge(), cookie.getSecure(), m_cookieHttpOnly); res.addHeader("Set-Cookie", sb.toString()); } return; }