/** * Match cookie domain attribute. */ public boolean match(final Cookie cookie, final CookieOrigin origin) { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String host = origin.getHost().toLowerCase(); String cookieDomain = cookie.getDomain(); // The effective host name MUST domain-match the Domain // attribute of the cookie. if (!domainMatch(host, cookieDomain)) { return false; } // effective host name minus domain must not contain any dots String effectiveHostWithoutDomain = host.substring( 0, host.length() - cookieDomain.length()); if (effectiveHostWithoutDomain.indexOf('.') != -1) { return false; } return true; }
int domainParts = new StringTokenizer(cookie.getDomain(), ".") .countTokens(); if (isSpecialDomain(cookie.getDomain())) { if (domainParts < 2) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates the Netscape cookie specification for " + "special domains"); if (domainParts < 3) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates the Netscape cookie specification");
&& (!cookie.getDomain().equals(host))) { if (!cookie.getDomain().startsWith(".")) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot"); int dotIndex = cookie.getDomain().indexOf('.', 1); if (dotIndex < 0 || dotIndex == cookie.getDomain().length() - 1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: domain must contain an embedded dot"); if (!host.endsWith(cookie.getDomain())) { throw new MalformedCookieException( "Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\""); - cookie.getDomain().length()); if (hostWithoutDomain.indexOf('.') != -1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: host minus domain may not contain any dots");
if (cookie.getDomain() == null) { throw new MalformedCookieException("Invalid cookie state: " + "domain not specified"); String cookieDomain = cookie.getDomain().toLowerCase(); cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot"); && (!cookieDomain.equals(".local"))) { throw new MalformedCookieException( "Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: the value contains no embedded dots " + "and the value is not .local"); "Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: effective host name does not " + "domain-match domain attribute."); if (effectiveHostWithoutDomain.indexOf('.') != -1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: " + "effective host minus domain may not contain any dots"); if (!cookie.getDomain().equals(host)) { throw new MalformedCookieException("Illegal domain attribute: \"" + cookie.getDomain() + "\"." + "Domain of origin: \"" + host + "\"");
if (!host.endsWith(cookie.getDomain())) { String s = cookie.getDomain(); if (s.startsWith(".")) { s = s.substring(1, s.length()); "Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\""); if (!host.equals(cookie.getDomain())) { throw new MalformedCookieException( "Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\"");
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The string buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) { String value = cookie.getValue(); if (value == null) { value = ""; } formatParam(buffer, new NameValuePair(cookie.getName(), value), version); if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version); } if ((cookie.getDomain() != null) && cookie.isDomainAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version); } }
/** * Returns the currently configured cookies for the specified domain, in an unmodifiable set. * @param domain the domain on which to filter the returned cookies * @return the currently configured cookies for the specified domain, in an unmodifiable set */ public synchronized Set<Cookie> getCookies(final String domain) { final Set<Cookie> cookies = new LinkedHashSet<Cookie>(); for (Cookie cookie : cookies_) { if (StringUtils.equals(cookie.getDomain(), domain)) { cookies.add(cookie); } } return Collections.unmodifiableSet(cookies); }
/** * Returns the currently configured cookies for the specified domain, in an unmodifiable set. * @param domain the domain on which to filter the returned cookies * @return the currently configured cookies for the specified domain, in an unmodifiable set */ public synchronized Set<Cookie> getCookies(final String domain) { final Set<Cookie> cookies = new LinkedHashSet<Cookie>(); for (Cookie cookie : cookies_) { if (StringUtils.equals(cookie.getDomain(), domain)) { cookies.add(cookie); } } return Collections.unmodifiableSet(cookies); }
/** * Returns the currently configured cookies for the specified domain, in an unmodifiable set. * @param domain the domain on which to filter the returned cookies * @return the currently configured cookies for the specified domain, in an unmodifiable set */ public synchronized Set<Cookie> getCookies(final String domain) { final Set<Cookie> cookies = new LinkedHashSet<Cookie>(); for (Cookie cookie : cookies_) { if (StringUtils.equals(cookie.getDomain(), domain)) { cookies.add(cookie); } } return Collections.unmodifiableSet(cookies); }
/** * Get the cookies for a specific domain and path */ public Cookie[] getCookies(String domain, String path) { Cookie[] cookies = getCookies(); List<Cookie> list = new ArrayList<Cookie>(); for (Cookie cookie : cookies) { String test = cookie.getDomain(); if (test.startsWith(".")) test = test.substring(1); if ((domain.endsWith(test) || test.endsWith(domain)) && (path == null || cookie.getPath().startsWith(path))) { list.add(cookie); } } return list.toArray(new Cookie[list.size()]); }
private static List<List<Pair<String, String>>> convertTokenValues(Map<String, Cookie> values) { List<List<Pair<String, String>>> tokens = new ArrayList<>(); for (Entry<String, Cookie> token : values.entrySet()) { Cookie cookie = token.getValue(); List<Pair<String, String>> fields = new ArrayList<>(); fields.add(new Pair<>("name", token.getKey())); fields.add(new Pair<>("value", cookie.getValue())); fields.add(new Pair<>("domain", cookie.getDomain())); fields.add(new Pair<>("path", cookie.getPath())); fields.add(new Pair<>("secure", Boolean.toString(cookie.getSecure()))); tokens.add(fields); } return tokens; } }
/** * Return a Cookie array * and auto importing domain and path when domain was empty. * * @param uri required Apache Common VFS supported file systems and response JSON format content. * @return Cookie[] */ Cookie[] getCookies(String uri){ if( null == cookies || 0 == cookies.size()) return null; for(Cookie cookie: cookies){ if("".equals(cookie.getDomain())){ String domain = uri.replaceAll("^.*:\\/\\/([^\\/]+)[\\/]?.*$", "$1"); cookie.setDomain(domain); cookie.setPath("/"); cookie.setExpiryDate(null); cookie.setSecure(false); } } return cookies.toArray(new Cookie[cookies.size()]); }
public Cookie[] getCookies() { org.apache.commons.httpclient.Cookie[] cookies = message.getInboundProperty(HttpConnector.HTTP_COOKIES_PROPERTY); if (cookies == null) return null; Cookie[] servletCookies = new Cookie[cookies.length]; for (org.apache.commons.httpclient.Cookie c : cookies) { Cookie servletCookie = new Cookie(c.getName(), c.getValue()); servletCookie.setComment(c.getComment()); servletCookie.setDomain(c.getDomain()); } return servletCookies; }
/** * This method formats the cookie so it can be send from server to client in a * {@linkplain HttpConstants#HEADER_COOKIE_SET "Set-Cookie"} header. */ public static String formatCookieForASetCookieHeader(Cookie cookie) { StringBuffer sb = new StringBuffer(); ServerCookie.appendCookieValue(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getComment(), -1, cookie.getSecure(), false); Date expiryDate = cookie.getExpiryDate(); if (expiryDate != null) { sb.append("; Expires="); sb.append(EXPIRE_FORMATTER.format(expiryDate)); } return sb.toString(); }
/** @deprecated (0.14.0) Use {@link #addCookie(ZestCookie)} instead. */ @Deprecated public void addCookie(Cookie cookie) { addCookie( cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiryDate(), cookie.getSecure()); }
public Set<Cookie> getCookies() { Set<org.apache.commons.httpclient.Cookie> rawCookies = webClient.getCookieManager().getCookies(getHostName()); Set<Cookie> retCookies = new HashSet<Cookie>(); for(org.apache.commons.httpclient.Cookie c : rawCookies) { if (c.getPath() != null && getPath().startsWith(c.getPath())) { retCookies.add(new ReturnedCookie(c.getName(), c.getValue(), c.getDomain(), c.getPath(), c.getExpiryDate(), c.getSecure())); } } return retCookies; }
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The string buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) { String value = cookie.getValue(); if (value == null) { value = ""; } formatParam(buffer, new NameValuePair(cookie.getName(), value), version); if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version); } if ((cookie.getDomain() != null) && cookie.isDomainAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version); } }
private void logCookiesAtState(String when) { Cookie[] cookies = getState().getCookies(); if (cookies.length == 0) { Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE " + when); } else { Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (" + when + ")"); for (int i=0; i<cookies.length; i++) { Log_OC.d(TAG + " #" + mInstanceNumber, " (" + i + "):" + "\n name: " + cookies[i].getName() + "\n value: " + cookies[i].getValue() + "\n domain: " + cookies[i].getDomain() + "\n path: " + cookies[i].getPath() ); } } }
private void logCookie(Cookie cookie) { Log_OC.d(TAG, "Cookie name: "+ cookie.getName() ); Log_OC.d(TAG, " value: "+ cookie.getValue() ); Log_OC.d(TAG, " domain: "+ cookie.getDomain()); Log_OC.d(TAG, " path: "+ cookie.getPath() ); Log_OC.d(TAG, " version: "+ cookie.getVersion() ); Log_OC.d(TAG, " expiryDate: " + (cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--")); Log_OC.d(TAG, " comment: "+ cookie.getComment() ); Log_OC.d(TAG, " secure: "+ cookie.getSecure() ); }