public void validate(Cookie cookie, CookieOrigin cookieorigin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookieorigin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String s = cookieorigin.getHost(); cookieorigin = cookie.getDomain(); if (cookieorigin == null) { throw new CookieRestrictionViolationException("Cookie domain may not be null"); } if (s.contains(".")) { if (!s.endsWith(cookieorigin)) { cookie = cookieorigin; if (cookieorigin.startsWith(".")) { cookie = cookieorigin.substring(1, cookieorigin.length()); } if (!s.equals(cookie)) { throw new CookieRestrictionViolationException( (new StringBuilder()) .append("Illegal domain attribute \"") .append(cookie) .append("\". Domain of origin: \"") .append(s) .append("\"") .toString()); } } } else if (!s.equals(cookieorigin)) { throw new CookieRestrictionViolationException( (new StringBuilder()) .append("Illegal domain attribute \"") .append(cookieorigin) .append("\". Domain of origin: \"") .append(s) .append("\"") .toString()); } }
public boolean match(Cookie cookie, CookieOrigin cookieorigin) { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookieorigin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String s = cookieorigin.getHost(); cookieorigin = cookie.getDomain(); if (cookieorigin != null) { if (s.equals(cookieorigin)) { return true; } cookie = cookieorigin; if (!cookieorigin.startsWith(".")) { cookie = (new StringBuilder()).append('.').append(cookieorigin).toString(); } if (s.endsWith(cookie) || s.equals(cookie.substring(1))) { return true; } } return false; }