mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-24 11:13:30 +00:00
Remove deprecated Cookie usage
Remove usage of comment and verison usage Signed-off-by: M-Faheem-Khan <faheem5948@gmail.com>
This commit is contained in:
parent
d52289bd7a
commit
241c3cd35a
@ -372,9 +372,6 @@ public abstract class AbstractRememberMeServices
|
|||||||
if (this.cookieDomain != null) {
|
if (this.cookieDomain != null) {
|
||||||
cookie.setDomain(this.cookieDomain);
|
cookie.setDomain(this.cookieDomain);
|
||||||
}
|
}
|
||||||
if (maxAge < 1) {
|
|
||||||
cookie.setVersion(1);
|
|
||||||
}
|
|
||||||
cookie.setSecure((this.useSecureCookie != null) ? this.useSecureCookie : request.isSecure());
|
cookie.setSecure((this.useSecureCookie != null) ? this.useSecureCookie : request.isSecure());
|
||||||
cookie.setHttpOnly(true);
|
cookie.setHttpOnly(true);
|
||||||
|
|
||||||
|
@ -67,7 +67,6 @@ class FirewalledResponse extends HttpServletResponseWrapper {
|
|||||||
validateCrlf(SET_COOKIE_HEADER, cookie.getValue());
|
validateCrlf(SET_COOKIE_HEADER, cookie.getValue());
|
||||||
validateCrlf(SET_COOKIE_HEADER, cookie.getPath());
|
validateCrlf(SET_COOKIE_HEADER, cookie.getPath());
|
||||||
validateCrlf(SET_COOKIE_HEADER, cookie.getDomain());
|
validateCrlf(SET_COOKIE_HEADER, cookie.getDomain());
|
||||||
validateCrlf(SET_COOKIE_HEADER, cookie.getComment());
|
|
||||||
}
|
}
|
||||||
super.addCookie(cookie);
|
super.addCookie(cookie);
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,9 @@ class CookieDeserializer extends JsonDeserializer<Cookie> {
|
|||||||
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
|
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
|
||||||
JsonNode jsonNode = mapper.readTree(jp);
|
JsonNode jsonNode = mapper.readTree(jp);
|
||||||
Cookie cookie = new Cookie(readJsonNode(jsonNode, "name").asText(), readJsonNode(jsonNode, "value").asText());
|
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.setDomain(readJsonNode(jsonNode, "domain").asText());
|
||||||
cookie.setMaxAge(readJsonNode(jsonNode, "maxAge").asInt(-1));
|
cookie.setMaxAge(readJsonNode(jsonNode, "maxAge").asInt(-1));
|
||||||
cookie.setSecure(readJsonNode(jsonNode, "secure").asBoolean());
|
cookie.setSecure(readJsonNode(jsonNode, "secure").asBoolean());
|
||||||
cookie.setVersion(readJsonNode(jsonNode, "version").asInt());
|
|
||||||
cookie.setPath(readJsonNode(jsonNode, "path").asText());
|
cookie.setPath(readJsonNode(jsonNode, "path").asText());
|
||||||
JsonNode attributes = readJsonNode(jsonNode, "attributes");
|
JsonNode attributes = readJsonNode(jsonNode, "attributes");
|
||||||
cookie.setHttpOnly(readJsonNode(attributes, "HttpOnly") != null);
|
cookie.setHttpOnly(readJsonNode(attributes, "HttpOnly") != null);
|
||||||
|
@ -44,10 +44,8 @@ abstract class SavedCookieMixin {
|
|||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
SavedCookieMixin(@JsonProperty("name") String name, @JsonProperty("value") String value,
|
SavedCookieMixin(@JsonProperty("name") String name, @JsonProperty("value") String value,
|
||||||
@JsonProperty("comment") String comment, @JsonProperty("domain") String domain,
|
@JsonProperty("domain") String domain, @JsonProperty("maxAge") int maxAge,
|
||||||
@JsonProperty("maxAge") int maxAge, @JsonProperty("path") String path,
|
@JsonProperty("path") String path, @JsonProperty("secure") boolean secure) {
|
||||||
@JsonProperty("secure") boolean secure, @JsonProperty("version") int version) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,6 @@ public class SavedCookie implements Serializable {
|
|||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
private final String comment;
|
|
||||||
|
|
||||||
private final String domain;
|
private final String domain;
|
||||||
|
|
||||||
private final int maxAge;
|
private final int maxAge;
|
||||||
@ -45,28 +43,13 @@ public class SavedCookie implements Serializable {
|
|||||||
|
|
||||||
private final boolean secure;
|
private final boolean secure;
|
||||||
|
|
||||||
private final int version;
|
public SavedCookie(String name, String value, String domain, int maxAge, String path, boolean secure) {
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use
|
|
||||||
* {@link org.springframework.security.web.savedrequest.SavedCookie#SavedCookie(String, String, String, int, String, boolean)}
|
|
||||||
* instead
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "6.1")
|
|
||||||
public SavedCookie(String name, String value, String comment, String domain, int maxAge, String path,
|
|
||||||
boolean secure, int version) {
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.comment = comment;
|
|
||||||
this.domain = domain;
|
this.domain = domain;
|
||||||
this.maxAge = maxAge;
|
this.maxAge = maxAge;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.secure = secure;
|
this.secure = secure;
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SavedCookie(String name, String value, String domain, int maxAge, String path, boolean secure) {
|
|
||||||
this(name, value, null, domain, maxAge, path, secure, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavedCookie(Cookie cookie) {
|
public SavedCookie(Cookie cookie) {
|
||||||
@ -82,11 +65,6 @@ public class SavedCookie implements Serializable {
|
|||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated(forRemoval = true, since = "6.1")
|
|
||||||
public String getComment() {
|
|
||||||
return this.comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDomain() {
|
public String getDomain() {
|
||||||
return this.domain;
|
return this.domain;
|
||||||
}
|
}
|
||||||
@ -103,23 +81,14 @@ public class SavedCookie implements Serializable {
|
|||||||
return this.secure;
|
return this.secure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated(forRemoval = true, since = "6.1")
|
|
||||||
public int getVersion() {
|
|
||||||
return this.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cookie getCookie() {
|
public Cookie getCookie() {
|
||||||
Cookie cookie = new Cookie(getName(), getValue());
|
Cookie cookie = new Cookie(getName(), getValue());
|
||||||
if (getComment() != null) {
|
|
||||||
cookie.setComment(getComment());
|
|
||||||
}
|
|
||||||
if (getDomain() != null) {
|
if (getDomain() != null) {
|
||||||
cookie.setDomain(getDomain());
|
cookie.setDomain(getDomain());
|
||||||
}
|
}
|
||||||
if (getPath() != null) {
|
if (getPath() != null) {
|
||||||
cookie.setPath(getPath());
|
cookie.setPath(getPath());
|
||||||
}
|
}
|
||||||
cookie.setVersion(getVersion());
|
|
||||||
cookie.setMaxAge(getMaxAge());
|
cookie.setMaxAge(getMaxAge());
|
||||||
cookie.setSecure(isSecure());
|
cookie.setSecure(isSecure());
|
||||||
return cookie;
|
return cookie;
|
||||||
|
@ -362,17 +362,6 @@ public class AbstractRememberMeServicesTests {
|
|||||||
assertThat(cookie.isHttpOnly()).isTrue();
|
assertThat(cookie.isHttpOnly()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SEC-2791
|
|
||||||
@Test
|
|
||||||
public void setCookieMaxAge1VersionSet() {
|
|
||||||
MockRememberMeServices services = new MockRememberMeServices();
|
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
|
||||||
services.setCookie(new String[] { "value" }, 1, request, response);
|
|
||||||
Cookie cookie = response.getCookie(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
|
|
||||||
assertThat(cookie.getVersion()).isZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setCookieDomainValue() {
|
public void setCookieDomainValue() {
|
||||||
MockRememberMeServices services = new MockRememberMeServices();
|
MockRememberMeServices services = new MockRememberMeServices();
|
||||||
|
@ -93,7 +93,6 @@ public class FirewalledResponseTests {
|
|||||||
Cookie cookie = new Cookie("foo", "bar");
|
Cookie cookie = new Cookie("foo", "bar");
|
||||||
cookie.setPath("/foobar");
|
cookie.setPath("/foobar");
|
||||||
cookie.setDomain("foobar");
|
cookie.setDomain("foobar");
|
||||||
cookie.setComment("foobar");
|
|
||||||
this.fwResponse.addCookie(cookie);
|
this.fwResponse.addCookie(cookie);
|
||||||
verify(this.response).addCookie(cookie);
|
verify(this.response).addCookie(cookie);
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,9 @@ public class DefaultSavedRequestMixinTests extends AbstractMixinTests {
|
|||||||
+ "\"@class\": \"org.springframework.security.web.savedrequest.SavedCookie\", "
|
+ "\"@class\": \"org.springframework.security.web.savedrequest.SavedCookie\", "
|
||||||
+ "\"name\": \"SESSION\", "
|
+ "\"name\": \"SESSION\", "
|
||||||
+ "\"value\": \"123456789\", "
|
+ "\"value\": \"123456789\", "
|
||||||
+ "\"comment\": null, "
|
|
||||||
+ "\"maxAge\": -1, "
|
+ "\"maxAge\": -1, "
|
||||||
+ "\"path\": null, "
|
+ "\"path\": null, "
|
||||||
+ "\"secure\":false, "
|
+ "\"secure\":false, "
|
||||||
+ "\"version\": 0, "
|
|
||||||
+ "\"domain\": null"
|
+ "\"domain\": null"
|
||||||
+ "}]]";
|
+ "}]]";
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
@ -42,11 +42,9 @@ public class SavedCookieMixinTests extends AbstractMixinTests {
|
|||||||
+ "\"@class\": \"org.springframework.security.web.savedrequest.SavedCookie\", "
|
+ "\"@class\": \"org.springframework.security.web.savedrequest.SavedCookie\", "
|
||||||
+ "\"name\": \"SESSION\", "
|
+ "\"name\": \"SESSION\", "
|
||||||
+ "\"value\": \"123456789\", "
|
+ "\"value\": \"123456789\", "
|
||||||
+ "\"comment\": null, "
|
|
||||||
+ "\"maxAge\": -1, "
|
+ "\"maxAge\": -1, "
|
||||||
+ "\"path\": null, "
|
+ "\"path\": null, "
|
||||||
+ "\"secure\":false, "
|
+ "\"secure\":false, "
|
||||||
+ "\"version\": 0, "
|
|
||||||
+ "\"domain\": null"
|
+ "\"domain\": null"
|
||||||
+ "}";
|
+ "}";
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
@ -90,13 +88,11 @@ public class SavedCookieMixinTests extends AbstractMixinTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deserializeSavedCookieJsonTest() throws IOException {
|
public void deserializeSavedCookieJsonTest() throws IOException {
|
||||||
SavedCookie savedCookie = (SavedCookie) this.mapper.readValue(COOKIE_JSON, Object.class);
|
SavedCookie savedCookie = this.mapper.readValue(COOKIE_JSON, SavedCookie.class);
|
||||||
assertThat(savedCookie).isNotNull();
|
assertThat(savedCookie).isNotNull();
|
||||||
assertThat(savedCookie.getName()).isEqualTo("SESSION");
|
assertThat(savedCookie.getName()).isEqualTo("SESSION");
|
||||||
assertThat(savedCookie.getValue()).isEqualTo("123456789");
|
assertThat(savedCookie.getValue()).isEqualTo("123456789");
|
||||||
assertThat(savedCookie.isSecure()).isEqualTo(false);
|
assertThat(savedCookie.isSecure()).isEqualTo(false);
|
||||||
assertThat(savedCookie.getVersion()).isZero();
|
|
||||||
assertThat(savedCookie.getComment()).isNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,10 @@ public class SavedCookieTests {
|
|||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.cookie = new Cookie("name", "value");
|
this.cookie = new Cookie("name", "value");
|
||||||
this.cookie.setComment("comment");
|
|
||||||
this.cookie.setDomain("domain");
|
this.cookie.setDomain("domain");
|
||||||
this.cookie.setMaxAge(100);
|
this.cookie.setMaxAge(100);
|
||||||
this.cookie.setPath("path");
|
this.cookie.setPath("path");
|
||||||
this.cookie.setSecure(true);
|
this.cookie.setSecure(true);
|
||||||
this.cookie.setVersion(11);
|
|
||||||
this.savedCookie = new SavedCookie(this.cookie);
|
this.savedCookie = new SavedCookie(this.cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,11 +50,6 @@ public class SavedCookieTests {
|
|||||||
assertThat(this.savedCookie.getValue()).isEqualTo(this.cookie.getValue());
|
assertThat(this.savedCookie.getValue()).isEqualTo(this.cookie.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetComment() {
|
|
||||||
assertThat(this.savedCookie.getComment()).isEqualTo(this.cookie.getComment());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDomain() {
|
public void testGetDomain() {
|
||||||
assertThat(this.savedCookie.getDomain()).isEqualTo(this.cookie.getDomain());
|
assertThat(this.savedCookie.getDomain()).isEqualTo(this.cookie.getDomain());
|
||||||
@ -72,22 +65,15 @@ public class SavedCookieTests {
|
|||||||
assertThat(this.savedCookie.getPath()).isEqualTo(this.cookie.getPath());
|
assertThat(this.savedCookie.getPath()).isEqualTo(this.cookie.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetVersion() {
|
|
||||||
assertThat(this.savedCookie.getVersion()).isEqualTo(this.cookie.getVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCookie() {
|
public void testGetCookie() {
|
||||||
Cookie other = this.savedCookie.getCookie();
|
Cookie other = this.savedCookie.getCookie();
|
||||||
assertThat(other.getComment()).isEqualTo(this.cookie.getComment());
|
|
||||||
assertThat(other.getDomain()).isEqualTo(this.cookie.getDomain());
|
assertThat(other.getDomain()).isEqualTo(this.cookie.getDomain());
|
||||||
assertThat(other.getMaxAge()).isEqualTo(this.cookie.getMaxAge());
|
assertThat(other.getMaxAge()).isEqualTo(this.cookie.getMaxAge());
|
||||||
assertThat(other.getName()).isEqualTo(this.cookie.getName());
|
assertThat(other.getName()).isEqualTo(this.cookie.getName());
|
||||||
assertThat(other.getPath()).isEqualTo(this.cookie.getPath());
|
assertThat(other.getPath()).isEqualTo(this.cookie.getPath());
|
||||||
assertThat(other.getSecure()).isEqualTo(this.cookie.getSecure());
|
assertThat(other.getSecure()).isEqualTo(this.cookie.getSecure());
|
||||||
assertThat(other.getValue()).isEqualTo(this.cookie.getValue());
|
assertThat(other.getValue()).isEqualTo(this.cookie.getValue());
|
||||||
assertThat(other.getVersion()).isEqualTo(this.cookie.getVersion());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user