use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieDeserializer method deserialize.
@Override
public Cookie deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode jsonNode = mapper.readTree(jp);
Cookie cookie = new Cookie(readJsonNode(jsonNode, "name").asText(), readJsonNode(jsonNode, "value").asText());
cookie.setComment(readJsonNode(jsonNode, "comment").asText());
cookie.setDomain(readJsonNode(jsonNode, "domain").asText());
cookie.setMaxAge(readJsonNode(jsonNode, "maxAge").asInt(-1));
cookie.setSecure(readJsonNode(jsonNode, "secure").asBoolean());
cookie.setVersion(readJsonNode(jsonNode, "version").asInt());
cookie.setPath(readJsonNode(jsonNode, "path").asText());
cookie.setHttpOnly(readJsonNode(jsonNode, "httpOnly").asBoolean());
return cookie;
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class SavedCookieTests method testGetCookie.
@Test
public void testGetCookie() {
Cookie other = this.savedCookie.getCookie();
assertThat(other.getComment()).isEqualTo(this.cookie.getComment());
assertThat(other.getDomain()).isEqualTo(this.cookie.getDomain());
assertThat(other.getMaxAge()).isEqualTo(this.cookie.getMaxAge());
assertThat(other.getName()).isEqualTo(this.cookie.getName());
assertThat(other.getPath()).isEqualTo(this.cookie.getPath());
assertThat(other.getSecure()).isEqualTo(this.cookie.getSecure());
assertThat(other.getValue()).isEqualTo(this.cookie.getValue());
assertThat(other.getVersion()).isEqualTo(this.cookie.getVersion());
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class SimpleSavedRequestTests method constructorWhenGivenSavedRequestThenCopies.
@Test
public void constructorWhenGivenSavedRequestThenCopies() {
SavedRequest savedRequest = new SimpleSavedRequest(prepareSavedRequest());
assertThat(savedRequest.getMethod()).isEqualTo("POST");
List<Cookie> cookies = savedRequest.getCookies();
assertThat(cookies).hasSize(1);
Cookie cookie = cookies.get(0);
assertThat(cookie.getName()).isEqualTo("cookiename");
assertThat(cookie.getValue()).isEqualTo("cookievalue");
Collection<String> headerNames = savedRequest.getHeaderNames();
assertThat(headerNames).hasSize(1);
String headerName = headerNames.iterator().next();
assertThat(headerName).isEqualTo("headername");
List<String> headerValues = savedRequest.getHeaderValues("headername");
assertThat(headerValues).hasSize(1);
String headerValue = headerValues.get(0);
assertThat(headerValue).isEqualTo("headervalue");
List<Locale> locales = savedRequest.getLocales();
assertThat(locales).hasSize(1);
Locale locale = locales.get(0);
assertThat(locale).isEqualTo(Locale.ENGLISH);
Map<String, String[]> parameterMap = savedRequest.getParameterMap();
assertThat(parameterMap).hasSize(1);
String[] values = parameterMap.get("key");
assertThat(values).hasSize(1);
assertThat(values[0]).isEqualTo("value");
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieRequestCacheTests method matchingRequestWhenRequestContainsSavedRequestCookieThenSetsAnExpiredCookieInResponse.
@Test
public void matchingRequestWhenRequestContainsSavedRequestCookieThenSetsAnExpiredCookieInResponse() {
CookieRequestCache cookieRequestCache = new CookieRequestCache();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setServerPort(443);
request.setSecure(true);
request.setScheme("https");
request.setServerName("abc.com");
request.setRequestURI("/destination");
request.setQueryString("param1=a¶m2=b¶m3=1122");
String redirectUrl = "https://abc.com/destination?param1=a¶m2=b¶m3=1122";
request.setCookies(new Cookie(DEFAULT_COOKIE_NAME, encodeCookie(redirectUrl)));
MockHttpServletResponse response = new MockHttpServletResponse();
cookieRequestCache.getMatchingRequest(request, response);
Cookie expiredCookie = response.getCookie(DEFAULT_COOKIE_NAME);
assertThat(expiredCookie).isNotNull();
assertThat(expiredCookie.getValue()).isEmpty();
assertThat(expiredCookie.getMaxAge()).isZero();
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieRequestCacheTests method saveRequestWhenMatchesThenSavedRequestInACookieOnResponse.
@Test
public void saveRequestWhenMatchesThenSavedRequestInACookieOnResponse() {
CookieRequestCache cookieRequestCache = new CookieRequestCache();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setServerPort(443);
request.setSecure(true);
request.setScheme("https");
request.setServerName("abc.com");
request.setRequestURI("/destination");
request.setQueryString("param1=a¶m2=b¶m3=1122");
MockHttpServletResponse response = new MockHttpServletResponse();
cookieRequestCache.saveRequest(request, response);
Cookie savedCookie = response.getCookie(DEFAULT_COOKIE_NAME);
assertThat(savedCookie).isNotNull();
String redirectUrl = decodeCookie(savedCookie.getValue());
assertThat(redirectUrl).isEqualTo("https://abc.com/destination?param1=a¶m2=b¶m3=1122");
assertThat(savedCookie.getMaxAge()).isEqualTo(-1);
assertThat(savedCookie.getPath()).isEqualTo("/");
assertThat(savedCookie.isHttpOnly()).isTrue();
assertThat(savedCookie.getSecure()).isTrue();
}
Aggregations