Java 类org.apache.http.cookie.CookieOrigin 实例源码

项目:RobotServer    文件:HttpService.java   
@Override
public void afterPropertiesSet() throws Exception {
    cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider> create().register("easy", new CookieSpecProvider() {
        public CookieSpec create(HttpContext context) {
            return new DefaultCookieSpec() {
                @Override
                public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
                }
            };
        }
    }).build();

    requestConfig = RequestConfig.custom().setCookieSpec("easy")
            .setConnectionRequestTimeout(propertyConfigurer.getIntValue("connection.request.timeout"))
            .setSocketTimeout(propertyConfigurer.getIntValue("socket_timeout"))
            .setConnectTimeout(propertyConfigurer.getIntValue("connection_timeout")).build();
}
项目:lams    文件:RFC2965Spec.java   
@Override
public List<Cookie> parse(
        final Header header,
        CookieOrigin origin) throws MalformedCookieException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE2)) {
        throw new MalformedCookieException("Unrecognized cookie header '"
                + header.toString() + "'");
    }
    origin = adjustEffectiveHost(origin);
    HeaderElement[] elems = header.getElements();
    return createCookies(elems, origin);
}
项目:lams    文件:RFC2965Spec.java   
/**
 * Set 'effective host name' as defined in RFC 2965.
 * <p>
 * If a host name contains no dots, the effective host name is
 * that name with the string .local appended to it.  Otherwise
 * the effective host name is the same as the host name.  Note
 * that all effective host names contain at least one dot.
 *
 * @param origin origin where cookie is received from or being sent to.
 * @return
 */
private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) {
    String host = origin.getHost();

    // Test if the host name appears to be a fully qualified DNS name,
    // IPv4 address or IPv6 address
    boolean isLocalHost = true;
    for (int i = 0; i < host.length(); i++) {
        char ch = host.charAt(i);
        if (ch == '.' || ch == ':') {
            isLocalHost = false;
            break;
        }
    }
    if (isLocalHost) {
        host += ".local";
        return new CookieOrigin(
                host,
                origin.getPort(),
                origin.getPath(),
                origin.isSecure());
    } else {
        return origin;
    }
}
项目:lams    文件:BestMatchSpec.java   
public void validate(
        final Cookie cookie,
        final CookieOrigin origin) throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (cookie.getVersion() > 0) {
        if (cookie instanceof SetCookie2) {
            getStrict().validate(cookie, origin);
        } else {
            getObsoleteStrict().validate(cookie, origin);
        }
    } else {
        getCompat().validate(cookie, origin);
    }
}
项目:lams    文件:BestMatchSpec.java   
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");
    }
    if (cookie.getVersion() > 0) {
        if (cookie instanceof SetCookie2) {
            return getStrict().match(cookie, origin);
        } else {
            return getObsoleteStrict().match(cookie, origin);
        }
    } else {
        return getCompat().match(cookie, origin);
    }
}
项目:lams    文件:RFC2965PortAttributeHandler.java   
/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    int port = origin.getPort();
    if (cookie instanceof ClientCookie
            && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
        if (!portMatch(port, cookie.getPorts())) {
            throw new CookieRestrictionViolationException(
                    "Port attribute violates RFC 2965: "
                    + "Request port not found in cookie's port list.");
        }
    }
}
项目:lams    文件:RFC2965PortAttributeHandler.java   
/**
 * Match cookie port attribute. If the Port attribute is not specified
 * in header, the cookie can be sent to any port. Otherwise, the request port
 * must be in the cookie's port list.
 */
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");
    }
    int port = origin.getPort();
    if (cookie instanceof ClientCookie
            && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
        if (cookie.getPorts() == null) {
            // Invalid cookie state: port not specified
            return false;
        }
        if (!portMatch(port, cookie.getPorts())) {
            return false;
        }
    }
    return true;
}
项目:lams    文件:RFC2965DomainAttributeHandler.java   
/**
 * 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(Locale.ENGLISH);
    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());
    return effectiveHostWithoutDomain.indexOf('.') == -1;
}
项目:lams    文件:NetscapeDomainHandler.java   
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    super.validate(cookie, origin);
    // Perform Netscape Cookie draft specific validation
    String host = origin.getHost();
    String domain = cookie.getDomain();
    if (host.contains(".")) {
        int domainParts = new StringTokenizer(domain, ".").countTokens();

        if (isSpecialDomain(domain)) {
            if (domainParts < 2) {
                throw new CookieRestrictionViolationException("Domain attribute \""
                    + domain
                    + "\" violates the Netscape cookie specification for "
                    + "special domains");
            }
        } else {
            if (domainParts < 3) {
                throw new CookieRestrictionViolationException("Domain attribute \""
                    + domain
                    + "\" violates the Netscape cookie specification");
            }
        }
    }
}
项目:lams    文件:BasicDomainHandler.java   
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();
    String domain = cookie.getDomain();
    if (domain == null) {
        return false;
    }
    if (host.equals(domain)) {
        return true;
    }
    if (!domain.startsWith(".")) {
        domain = '.' + domain;
    }
    return host.endsWith(domain) || host.equals(domain.substring(1));
}
项目:purecloud-iot    文件:TestCookieNetscapeDraft.java   
/**
 * Expire attribute with two digit year.
 */
@Test
public void testNetscapeCookieExpireAttributeTwoDigitYear() throws Exception {
    final CookieSpec cookiespec = new NetscapeDraftSpec();
    final Header header = new BasicHeader("Set-Cookie",
        "name=value; path=/; domain=.mydomain.com; expires=Thursday, 01-Jan-70 00:00:10 GMT; comment=no_comment");
    final CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    cookiespec.validate(cookies.get(0), origin);
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());
    final Cookie cookie = cookies.get(0);
    final Calendar c = Calendar.getInstance();
    c.setTimeZone(TimeZone.getTimeZone("GMT"));
    c.setTime(cookie.getExpiryDate());
    final int year = c.get(Calendar.YEAR);
    Assert.assertEquals(2070, year);
}
项目:purecloud-iot    文件:TestCookieNetscapeDraft.java   
/**
 * Tests Netscape specific expire attribute parsing.
 */
@Test
public void testNetscapeCookieExpireAttribute() throws Exception {
    final CookieSpec cookiespec = new NetscapeDraftSpec();
    final Header header = new BasicHeader("Set-Cookie",
        "name=value; path=/; domain=.mydomain.com; expires=Thu, 01-Jan-2070 00:00:10 GMT; comment=no_comment");
    final CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    cookiespec.validate(cookies.get(0), origin);
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());
    final Cookie cookie = cookies.get(0);
    final Calendar c = Calendar.getInstance();
    c.setTimeZone(TimeZone.getTimeZone("GMT"));
    c.setTime(cookie.getExpiryDate());
    final int year = c.get(Calendar.YEAR);
    Assert.assertEquals(2070, year);
}
项目:purecloud-iot    文件:TestCookieRFC2965Spec.java   
/**
 * test cookie {@code Port} matching.
 */
@Test
public void testMatchPort() throws Exception {
    // cookie can be sent to any port if port attribute not specified
    BasicClientCookie2 cookie = new BasicClientCookie2("name", "value");
    cookie.setDomain(".domain.com");
    cookie.setPath("/");
    cookie.setPorts(null);

    final CookieSpec cookiespec = new RFC2965Spec();
    final CookieOrigin origin1 = new CookieOrigin("www.domain.com", 8080 /* request port */, "/", false);
    Assert.assertTrue(cookiespec.match(cookie, origin1));
    final CookieOrigin origin2 = new CookieOrigin("www.domain.com", 323 /* request port */, "/", false);
    Assert.assertTrue(cookiespec.match(cookie, origin2));

    // otherwise, request port must be in cookie's port list
    cookie = new BasicClientCookie2("name", "value");
    cookie.setDomain(".domain.com");
    cookie.setPath("/");
    cookie.setPorts(new int[] {80, 8080});
    cookie.setAttribute(ClientCookie.PORT_ATTR, "80, 8080");
    final CookieOrigin origin3 = new CookieOrigin("www.domain.com", 434 /* request port */, "/", false);
    Assert.assertFalse(cookiespec.match(cookie, origin3));
    final CookieOrigin origin4 = new CookieOrigin("www.domain.com", 8080 /* request port */, "/", false);
    Assert.assertTrue(cookiespec.match(cookie, origin4));
}
项目:remote-files-sync    文件:RFC2965PortAttributeHandlerHC4.java   
/**
 * Match cookie port attribute. If the Port attribute is not specified
 * in header, the cookie can be sent to any port. Otherwise, the request port
 * must be in the cookie's port list.
 */
public boolean match(final Cookie cookie, final CookieOrigin origin) {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    final int port = origin.getPort();
    if (cookie instanceof ClientCookie
            && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
        if (cookie.getPorts() == null) {
            // Invalid cookie state: port not specified
            return false;
        }
        if (!portMatch(port, cookie.getPorts())) {
            return false;
        }
    }
    return true;
}
项目:remote-files-sync    文件:NetscapeDomainHandlerHC4.java   
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    super.validate(cookie, origin);
    // Perform Netscape Cookie draft specific validation
    final String host = origin.getHost();
    final String domain = cookie.getDomain();
    if (host.contains(".")) {
        final int domainParts = new StringTokenizer(domain, ".").countTokens();

        if (isSpecialDomain(domain)) {
            if (domainParts < 2) {
                throw new CookieRestrictionViolationException("Domain attribute \""
                    + domain
                    + "\" violates the Netscape cookie specification for "
                    + "special domains");
            }
        } else {
            if (domainParts < 3) {
                throw new CookieRestrictionViolationException("Domain attribute \""
                    + domain
                    + "\" violates the Netscape cookie specification");
            }
        }
    }
}
项目:remote-files-sync    文件:BasicDomainHandlerHC4.java   
public boolean match(final Cookie cookie, final CookieOrigin origin) {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    final String host = origin.getHost();
    String domain = cookie.getDomain();
    if (domain == null) {
        return false;
    }
    if (host.equals(domain)) {
        return true;
    }
    if (!domain.startsWith(".")) {
        domain = '.' + domain;
    }
    return host.endsWith(domain) || host.equals(domain.substring(1));
}
项目:purecloud-iot    文件:TestCookieNetscapeDraft.java   
@Test
public void testParseWithWrongNetscapeDomain2() throws Exception {
    final Header header = new BasicHeader("Set-Cookie","cookie-name=cookie-value; domain=.y.z");

    final CookieSpec cookiespec = new NetscapeDraftSpec();
    try {
        final CookieOrigin origin = new CookieOrigin("x.y.z", 80, "/", false);
        final List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        Assert.fail("MalformedCookieException exception should have been thrown");
    } catch (final MalformedCookieException e) {
        // expected
    }
}
项目:purecloud-iot    文件:TestCookieRFC2965Spec.java   
/**
 * Test parsing cookie {@code "Port"} attribute.
 */
@Test
public void testParsePort() throws Exception {
    final CookieSpec cookiespec = new RFC2965Spec();
    final CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
    final Header header = new BasicHeader("Set-Cookie2", "name=value;Port=\"80,800,8000\";Version=1;Port=nonsense");
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());
    // only the first occurrence of port attribute is considered, others ignored
    final ClientCookie cookie = (ClientCookie) cookies.get(0);
    final int[] ports = cookie.getPorts();
    Assert.assertNotNull(ports);
    Assert.assertEquals(3, ports.length);
    Assert.assertEquals(80, ports[0]);
    Assert.assertEquals(800, ports[1]);
    Assert.assertEquals(8000, ports[2]);
    Assert.assertTrue(cookie.containsAttribute(ClientCookie.PORT_ATTR));
}
项目:purecloud-iot    文件:TestDefaultCookieSpec.java   
@Test
public void testVersion1CookieWithInvalidExpires() throws Exception {
    final CookieSpec cookiespec = new DefaultCookieSpec();
    final CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);

    final Header origHeader = new BasicHeader("Set-Cookie",
            "test=\"test\"; Version=1; Expires=Mon, 11-Feb-2013 10:39:19 GMT; Path=/");
    final List<Cookie> cookies = cookiespec.parse(origHeader, origin);
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());

    final List<Header> headers = cookiespec.formatCookies(cookies);
    Assert.assertNotNull(headers);
    Assert.assertEquals(1, headers.size());
    final Header header1 = headers.get(0);
    Assert.assertEquals("test=\"test\"", header1.getValue());
}
项目:purecloud-iot    文件:TestNetscapeCookieAttribHandlers.java   
@Test
public void testNetscapeDomainValidate1() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
    final CookieAttributeHandler h = new NetscapeDomainHandler();

    cookie.setDomain("somehost");
    h.validate(cookie, origin);

    cookie.setDomain("otherhost");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
        // expected
    }
}
项目:purecloud-iot    文件:TestDefaultCookieSpec.java   
@Test
public void testCookieStandardCompliantMatch() throws Exception {
    final CookieSpec cookiespec = new DefaultCookieSpec();
    final CookieOrigin origin = new CookieOrigin("a.b.domain.com", 80, "/", false);

    // Make sure the strict (RFC2965) cookie matching
    // is used for version 1 cookies
    final BasicClientCookie2 cookie = new BasicClientCookie2("name", "value");
    cookie.setVersion(1);
    cookie.setDomain(".domain.com");
    cookie.setAttribute(ClientCookie.DOMAIN_ATTR, cookie.getDomain());
    cookie.setPath("/");
    cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());

    Assert.assertFalse(cookiespec.match(cookie, origin));

    cookie.setDomain(".b.domain.com");

    Assert.assertTrue(cookiespec.match(cookie, origin));
}
项目:purecloud-iot    文件:BrowserCompatSpec.java   
/** Default constructor */
public BrowserCompatSpec(final String[] datepatterns, final BrowserCompatSpecFactory.SecurityLevel securityLevel) {
    super(new BrowserCompatVersionAttributeHandler(),
            new BasicDomainHandler(),
            securityLevel == BrowserCompatSpecFactory.SecurityLevel.SECURITYLEVEL_IE_MEDIUM ?
                    new BasicPathHandler() {
                        @Override
                        public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException {
                            // No validation
                        }
                    } : new BasicPathHandler(),
            new BasicMaxAgeHandler(),
            new BasicSecureHandler(),
            new BasicCommentHandler(),
            new BasicExpiresHandler(datepatterns != null ? datepatterns.clone() : DEFAULT_DATE_PATTERNS));
}
项目:purecloud-iot    文件:TestRFC2109CookieAttribHandlers.java   
@Test
public void testRFC2109DomainValidate3() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
    final CookieAttributeHandler h = new RFC2109DomainHandler();

    cookie.setDomain(".a.com");
    h.validate(cookie, origin);

    cookie.setDomain(".com");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
        // expected
    }
}
项目:purecloud-iot    文件:TestCookieNetscapeDraft.java   
@Test
public void testParseAbsPath() throws Exception {
    final Header header = new BasicHeader("Set-Cookie", "name1=value1;Path=/path/");

    final CookieSpec cookiespec = new NetscapeDraftSpec();
    final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    for (int i = 0; i < cookies.size(); i++) {
        cookiespec.validate(cookies.get(i), origin);
    }
    Assert.assertEquals("Found 1 cookies.",1,cookies.size());
    Assert.assertEquals("Name","name1",cookies.get(0).getName());
    Assert.assertEquals("Value","value1",cookies.get(0).getValue());
    Assert.assertEquals("Domain","host",cookies.get(0).getDomain());
    Assert.assertEquals("Path","/path/",cookies.get(0).getPath());
}
项目:purecloud-iot    文件:RFC2965PortAttributeHandler.java   
/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    final int port = origin.getPort();
    if (cookie instanceof ClientCookie
            && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
        if (!portMatch(port, cookie.getPorts())) {
            throw new CookieRestrictionViolationException(
                    "Port attribute violates RFC 2965: "
                    + "Request port not found in cookie's port list.");
        }
    }
}
项目:purecloud-iot    文件:TestCookieNetscapeDraft.java   
@Test
public void testParseVersionIgnored() throws Exception {
    final Header header = new BasicHeader("Set-Cookie", "name1=value1;Path=/path/;Version=1;");

    final CookieSpec cookiespec = new NetscapeDraftSpec();
    final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    for (int i = 0; i < cookies.size(); i++) {
        cookiespec.validate(cookies.get(i), origin);
    }
    Assert.assertEquals("Found 1 cookies.",1,cookies.size());
    final Cookie cookie = cookies.get(0);
    Assert.assertEquals("Name","name1", cookie.getName());
    Assert.assertEquals("Value", "value1", cookie.getValue());
    Assert.assertEquals("Domain", "host", cookie.getDomain());
    Assert.assertEquals("Path","/path/", cookie.getPath());
    Assert.assertEquals(0, cookie.getVersion());
}
项目:purecloud-iot    文件:TestCookieRFC2109Spec.java   
/**
 * Tests if cookie constructor rejects cookie name starting with $.
 */
@Test
public void testCookieNameStartingWithDollarSign() throws Exception {
    final Header setcookie = new BasicHeader("Set-Cookie", "$invalid_name=");
    final CookieSpec cookiespec = new RFC2109Spec();
    final CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
    try {
        final List<Cookie> cookies = cookiespec.parse(setcookie, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        Assert.fail("MalformedCookieException exception should have been thrown");
    } catch (final MalformedCookieException e) {
        // expected
    }
}
项目:purecloud-iot    文件:TestRequestAddCookies.java   
@Test
public void testAuthDefaultHttpPortWhenProxy() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/stuff");

    this.target = new HttpHost("localhost.local");
    final HttpRoute route = new HttpRoute(
            new HttpHost("localhost.local", 80), null, new HttpHost("localhost", 8888), false);

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

    final HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);

    final CookieOrigin cookieOrigin = context.getCookieOrigin();
    Assert.assertNotNull(cookieOrigin);
    Assert.assertEquals(this.target.getHostName(), cookieOrigin.getHost());
    Assert.assertEquals(80, cookieOrigin.getPort());
    Assert.assertEquals("/stuff", cookieOrigin.getPath());
    Assert.assertFalse(cookieOrigin.isSecure());
}
项目:purecloud-iot    文件:TestCookieNetscapeDraft.java   
@Test
public void testParseAbsPath2() throws Exception {
    final Header header = new BasicHeader("Set-Cookie", "name1=value1;Path=/");

    final CookieSpec cookiespec = new NetscapeDraftSpec();
    final CookieOrigin origin = new CookieOrigin("host", 80, "/", true);
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    for (int i = 0; i < cookies.size(); i++) {
        cookiespec.validate(cookies.get(i), origin);
    }
    Assert.assertEquals("Found 1 cookies.",1,cookies.size());
    Assert.assertEquals("Name","name1",cookies.get(0).getName());
    Assert.assertEquals("Value","value1",cookies.get(0).getValue());
    Assert.assertEquals("Domain","host",cookies.get(0).getDomain());
    Assert.assertEquals("Path","/",cookies.get(0).getPath());
}
项目:purecloud-iot    文件:DefaultCookieSpec.java   
@Override
public void validate(
        final Cookie cookie,
        final CookieOrigin origin) throws MalformedCookieException {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    if (cookie.getVersion() > 0) {
        if (cookie instanceof SetCookie2) {
            strict.validate(cookie, origin);
        } else {
            obsoleteStrict.validate(cookie, origin);
        }
    } else {
        netscapeDraft.validate(cookie, origin);
    }
}
项目:purecloud-iot    文件:TestCookieRFC2109Spec.java   
/**
 * Domain does not start with a dot
 */
@Test
public void testParseWithIllegalDomain1() throws Exception {
    final Header header = new BasicHeader("Set-Cookie",
        "cookie-name=cookie-value; domain=a.b.com; version=1");

    final CookieSpec cookiespec = new RFC2109Spec();
    final CookieOrigin origin = new CookieOrigin("www.a.b.com", 80, "/", false);
    try {
        final List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException e) {
        // expected
    }
}
项目:purecloud-iot    文件:TestCookieRFC2109Spec.java   
/**
 * Host minus domain may not contain any dots
 */
@Test
public void testParseWithIllegalDomain4() throws Exception {
    final Header header = new BasicHeader("Set-Cookie",
        "cookie-name=cookie-value; domain=.c.com; version=1");

    final CookieSpec cookiespec = new RFC2109Spec();
    final CookieOrigin origin = new CookieOrigin("a.b.c.com", 80, "/", false);
    try {
        final List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException e) {
        // expected
    }
}
项目:purecloud-iot    文件:TestCookieRFC2965Spec.java   
/**
 * test cookie {@code Domain} matching.
 */
@Test
public void testMatchDomain() throws Exception {
    final BasicClientCookie2 cookie = new BasicClientCookie2("name", "value");
    cookie.setDomain(".domain.com");
    cookie.setPath("/");
    cookie.setPorts(new int[] {80});
    final CookieSpec cookiespec = new RFC2965Spec();
    // effective host name minus domain must not contain any dots
    final CookieOrigin origin1 = new CookieOrigin("a.b.domain.com" /* request host */, 80, "/", false);
    Assert.assertFalse(cookiespec.match(cookie, origin1));
    // The effective host name MUST domain-match the Domain
    // attribute of the cookie.
    final CookieOrigin origin2 = new CookieOrigin("www.domain.org" /* request host */, 80, "/", false);
    Assert.assertFalse(cookiespec.match(cookie, origin2));
    final CookieOrigin origin3 = new CookieOrigin("www.domain.com" /* request host */, 80, "/", false);
    Assert.assertTrue(cookiespec.match(cookie, origin3));
}
项目:purecloud-iot    文件:TestBasicCookieAttribHandlers.java   
@Test
public void testBasicDomainValidate2() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
    final CookieAttributeHandler h = new BasicDomainHandler();

    cookie.setDomain("somehost");
    h.validate(cookie, origin);

    cookie.setDomain("otherhost");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
        // expected
    }
}
项目:sling-org-apache-sling-testing-clients    文件:StickyCookieSpec.java   
@Override
public List<Cookie> parse(Header header, CookieOrigin origin) throws MalformedCookieException {
    List<Cookie> cookies = super.parse(header, origin);
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals(StickyCookieHolder.COOKIE_NAME)) {
            // store it in the TestStickySessionRule threadlocal var
            StickyCookieHolder.setTestStickySessionCookie(cookie);
        }
    }
    return cookies;
}
项目:lams    文件:BasicPathHandler.java   
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    if (!match(cookie, origin)) {
        throw new CookieRestrictionViolationException(
            "Illegal path attribute \"" + cookie.getPath()
            + "\". Path of origin: \"" + origin.getPath() + "\"");
    }
}
项目:lams    文件:RFC2965VersionAttributeHandler.java   
/**
 * validate cookie version attribute. Version attribute is REQUIRED.
 */
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (cookie instanceof SetCookie2) {
        if (cookie instanceof ClientCookie
                && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) {
            throw new CookieRestrictionViolationException(
                    "Violates RFC 2965. Version attribute is required.");
        }
    }
}
项目:lams    文件:RFC2965Spec.java   
@Override
protected List<Cookie> parse(
        final HeaderElement[] elems,
        CookieOrigin origin) throws MalformedCookieException {
    origin = adjustEffectiveHost(origin);
    return createCookies(elems, origin);
}
项目:lams    文件:RFC2965Spec.java   
@Override
public void validate(final Cookie cookie, CookieOrigin origin)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    origin = adjustEffectiveHost(origin);
    super.validate(cookie, origin);
}
项目:lams    文件:RFC2965Spec.java   
@Override
public boolean match(final Cookie cookie, 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");
    }
    origin = adjustEffectiveHost(origin);
    return super.match(cookie, origin);
}