Skip to content

Commit bebc7bc

Browse files
committed
Handle cookie path correctly
1 parent a68d5c3 commit bebc7bc

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.2.2
2+
* oauth2-oidc-remember-me
3+
* Handle cookie path correctly
4+
15
# 2.2.1
26
* Use `ConcurrentReferenceHashMap` in favor of `Collections.synchronizedMap(new WeakHashMap<>())` to improve performance
37

oauth2-oidc-remember-me/src/main/java/software/xdev/sse/oauth2/rememberme/OAuth2CookieRememberMeServices.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ protected Cookie buildCookie(final String name, final String value)
608608
cookie.setHttpOnly(true);
609609
cookie.setSecure(this.cookieSecureService.isSecure());
610610
cookie.setMaxAge((int)this.config.getExpiration().toSeconds());
611-
cookie.setPath("/");
611+
cookie.setPath(this.config.getCookiePath());
612612
return cookie;
613613
}
614614

@@ -691,6 +691,9 @@ protected void deleteCookie(final Cookie cookie, final HttpServletResponse respo
691691
{
692692
// Expire cookie
693693
cookie.setMaxAge(0);
694+
// Set path correctly or browser will ignore it
695+
cookie.setPath(this.config.getCookiePath());
696+
694697
response.addCookie(cookie);
695698

696699
LOG.debug("Expiring Cookie[name='{}']", cookie.getName());

oauth2-oidc-remember-me/src/main/java/software/xdev/sse/oauth2/rememberme/config/OAuth2CookieRememberMeServicesConfig.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class OAuth2CookieRememberMeServicesConfig
3030
private String payloadCookieName = "AC"; // Auth Cache
3131
@NotEmpty
3232
private String idCookieName = "ACID"; // Auth Cache Identifier
33+
@NotEmpty
34+
private String cookiePath = "/";
3335

3436
@NotNull
3537
private Duration expiration = Duration.ofDays(3);
@@ -76,6 +78,16 @@ public void setIdCookieName(final String idCookieName)
7678
this.idCookieName = idCookieName;
7779
}
7880

81+
public String getCookiePath()
82+
{
83+
return this.cookiePath;
84+
}
85+
86+
public void setCookiePath(final String cookiePath)
87+
{
88+
this.cookiePath = cookiePath;
89+
}
90+
7991
public Duration getExpiration()
8092
{
8193
return this.expiration;
@@ -98,7 +110,7 @@ public void setMaxPerUser(final int maxPerUser)
98110

99111
public OAuth2CookieRememberMeServicesCleanupScheduleConfig getCleanupSchedule()
100112
{
101-
return cleanupSchedule;
113+
return this.cleanupSchedule;
102114
}
103115

104116
public void setCleanupSchedule(final OAuth2CookieRememberMeServicesCleanupScheduleConfig cleanupSchedule)
@@ -116,6 +128,8 @@ public String toString()
116128
+ this.payloadCookieName
117129
+ "', idCookieName='"
118130
+ this.idCookieName
131+
+ "', cookiePath='"
132+
+ this.cookiePath
119133
+ "', expiration="
120134
+ this.expiration
121135
+ ", maxPerUser="

0 commit comments

Comments
 (0)