@Override public boolean isSecure() { return nettyCookie.isSecure(); }
private List<Cookie> get(String domain, String path, boolean secure) { final boolean[] removeExpired = {false}; List<Cookie> result = cookieJar.entrySet().stream().filter(pair -> { CookieKey key = pair.getKey(); StoredCookie storedCookie = pair.getValue(); boolean hasCookieExpired = hasCookieExpired(storedCookie.cookie, storedCookie.createdAt); if (hasCookieExpired && !removeExpired[0]) removeExpired[0] = true; return !hasCookieExpired && domainsMatch(key.domain, domain, storedCookie.hostOnly) && pathsMatch(key.path, path) && (secure || !storedCookie.cookie.isSecure()); }).map(v -> v.getValue().cookie).collect(Collectors.toList()); if (removeExpired[0]) removeExpired(); return result; }
@Override public MultiValueMap<String, ResponseCookie> getCookies() { MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>(); this.response.cookies().values().stream().flatMap(Collection::stream) .forEach(cookie -> result.add(cookie.name(), ResponseCookie.from(cookie.name(), cookie.value()) .domain(cookie.domain()) .path(cookie.path()) .maxAge(cookie.maxAge()) .secure(cookie.isSecure()) .httpOnly(cookie.isHttpOnly()) .build())); return CollectionUtils.unmodifiableMultiValueMap(result); }
@Override public MultiValueMap<String, ResponseCookie> getCookies() { MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>(); this.response.cookies().values().stream().flatMap(Collection::stream) .forEach(cookie -> result.add(cookie.name(), ResponseCookie.from(cookie.name(), cookie.value()) .domain(cookie.domain()) .path(cookie.path()) .maxAge(cookie.maxAge()) .secure(cookie.isSecure()) .httpOnly(cookie.isHttpOnly()) .build())); return CollectionUtils.unmodifiableMultiValueMap(result); }
@Override public void run() throws IOException { org.apache.http.HttpResponse response = helper.getResponse(root()); String value = response.getFirstHeader(HttpHeaders.SET_COOKIE).getValue(); Cookie decodeCookie = ClientCookieDecoder.STRICT.decode(value); assertThat(decodeCookie.isSecure(), is(true)); } });
private MultiValueMap<String, ResponseCookie> initCookies() { final MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>(); headers.getAll(HttpHeaderNames.SET_COOKIE) .stream() .map(ClientCookieDecoder.LAX::decode) .forEach(c -> cookies.add(c.name(), ResponseCookie.from(c.name(), c.value()) .maxAge(c.maxAge()) .domain(c.domain()) .path(c.path()) .secure(c.isSecure()) .httpOnly(c.isHttpOnly()) .build())); return cookies; }
private void shouldServeCookiesBasedOnTheUriScheme() { CookieStore store = new ThreadSafeCookieStore(); store.add(Uri.create("https://foo.org/moodle/"), ClientCookieDecoder.LAX.decode("cookie1=VALUE1; Path=/")); store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE2; Path=/")); store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE3; Path=/; Secure")); Uri uri = Uri.create("https://foo.org/moodle/login"); assertTrue(store.getAll().size() == 1); assertTrue(store.get(uri).get(0).value().equals("VALUE3")); assertTrue(store.get(uri).get(0).isSecure()); }
private void shouldServeSecureCookiesForSpecificallyRetrievedHttpUriScheme() { CookieStore store = new ThreadSafeCookieStore(); store.add(Uri.create("https://foo.org/moodle/"), ClientCookieDecoder.LAX.decode("cookie1=VALUE1; Path=/")); store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE2; Path=/")); store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE3; Path=/; Secure")); Uri uri = Uri.create("https://foo.org/moodle/login"); assertTrue(store.get(uri).size() == 1); assertTrue(store.get(uri).get(0).value().equals("VALUE3")); assertTrue(store.get(uri).get(0).isSecure()); } }
@Test public void should_set_and_recognize_cookie_with_secure() throws IOException { runWithConfiguration("cookie.json"); Cookie decodeCookie = getCookie("/cookie-with-secure"); assertThat(decodeCookie.name(), is("login")); assertThat(decodeCookie.value(), is("true")); assertThat(decodeCookie.isSecure(), is(true)); }
private void shouldAlsoServeNonSecureCookiesBasedOnTheUriScheme() { CookieStore store = new ThreadSafeCookieStore(); store.add(Uri.create("https://foo.org/moodle/"), ClientCookieDecoder.LAX.decode("cookie1=VALUE1; Path=/")); store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE2; Path=/")); store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE3; Path=/; HttpOnly")); Uri uri = Uri.create("https://foo.org/moodle/login"); assertTrue(store.getAll().size() == 1); assertTrue(store.get(uri).get(0).value().equals("VALUE3")); assertTrue(!store.get(uri).get(0).isSecure()); }
harCookie.setHttpOnly(cookie.isHttpOnly()); harCookie.setPath(cookie.path()); harCookie.setSecure(cookie.isSecure()); if (cookie.maxAge() > 0) {
add(buf, CookieHeaderNames.DOMAIN, cookie.domain()); if (cookie.isSecure()) { add(buf, CookieHeaderNames.SECURE);
assertThat(setCookie.path()).isEqualTo("/"); assertThat(setCookie.maxAge()).isEqualTo(Duration.ofSeconds(60).getSeconds()); assertThat(setCookie.isSecure()).isTrue(); assertThat(setCookie.isHttpOnly()).isTrue(); })
@Override public boolean isSecure() { return cookie.isSecure(); }
@Override public boolean isSecured() { return cookie.isSecure(); }
@Override public boolean isSecure() { return nettyCookie.isSecure(); }
@Override public MultiValueMap<String, ResponseCookie> getCookies() { MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>(); this.response.cookies().values().stream().flatMap(Collection::stream) .forEach(cookie -> result.add(cookie.name(), ResponseCookie.from(cookie.name(), cookie.value()) .domain(cookie.domain()) .path(cookie.path()) .maxAge(cookie.maxAge()) .secure(cookie.isSecure()) .httpOnly(cookie.isHttpOnly()) .build())); return CollectionUtils.unmodifiableMultiValueMap(result); }
@Override public MultiValueMap<String, ResponseCookie> getCookies() { MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>(); this.response.cookies().values().stream().flatMap(Collection::stream) .forEach(cookie -> result.add(cookie.name(), ResponseCookie.from(cookie.name(), cookie.value()) .domain(cookie.domain()) .path(cookie.path()) .maxAge(cookie.maxAge()) .secure(cookie.isSecure()) .httpOnly(cookie.isHttpOnly()) .build())); return CollectionUtils.unmodifiableMultiValueMap(result); }
@Override public Collection<Cookie> getRequestCookies() { final List<Cookie> newCookies = new ArrayList<>(); final Set<io.netty.handler.codec.http.cookie.Cookie> cookies = request.getCookies(); for (final io.netty.handler.codec.http.cookie.Cookie cookie : cookies) { final Cookie newCookie = new Cookie(cookie.name(), cookie.value()); newCookie.setDomain(cookie.domain()); newCookie.setPath(cookie.path()); newCookie.setMaxAge((int) cookie.maxAge()); newCookie.setSecure(cookie.isSecure()); newCookie.setHttpOnly(cookie.isHttpOnly()); newCookies.add(newCookie); } return newCookies; }
private static ResponseCookie convert(Cookie cookie) { String value = cookie.wrap() ? quote(cookie.value()) : cookie.value(); return responseCookie(cookie.name(), value) .domain(cookie.domain()) .path(cookie.path()) .maxAge(cookie.maxAge()) .httpOnly(cookie.isHttpOnly()) .secure(cookie.isSecure()) .build(); }