Skip to content

Commit eed36c7

Browse files
authored
[SDK-2558] Add support for tenant session cookie (#457)
* [SDK-2558] Add support for tenant session cookie * remove unnecessary setter
1 parent 553915c commit eed36c7

4 files changed

Lines changed: 54 additions & 2 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.auth0.json.mgmt.tenants;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
/**
9+
* Represents the value of the {@code session_cookie} field of the {@link Tenant}.
10+
*/
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
@JsonInclude(JsonInclude.Include.NON_NULL)
13+
public class SessionCookie {
14+
15+
@JsonProperty("mode")
16+
private String mode;
17+
18+
@JsonCreator
19+
public SessionCookie(@JsonProperty("mode") String mode) {
20+
this.mode = mode;
21+
}
22+
23+
public String getMode() {
24+
return mode;
25+
}
26+
}

src/main/java/com/auth0/json/mgmt/tenants/Tenant.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class Tenant {
4040
@JsonProperty("session_lifetime")
4141
private Integer sessionLifetime;
4242

43+
@JsonProperty("session_cookie")
44+
private SessionCookie sessionCookie;
45+
4346
@JsonProperty("idle_session_lifetime")
4447
private Integer idleSessionLifetime;
4548

@@ -273,6 +276,21 @@ public Integer getSessionLifetime() {
273276
return sessionLifetime;
274277
}
275278

279+
/**
280+
* @return the value of the session cookie.
281+
*/
282+
public SessionCookie getSessionCookie() {
283+
return sessionCookie;
284+
}
285+
286+
/**
287+
* Sets the value of the session cookie.
288+
* @param sessionCookie the value of the session cookie to set.
289+
*/
290+
public void setSessionCookie(SessionCookie sessionCookie) {
291+
this.sessionCookie = sessionCookie;
292+
}
293+
276294
/**
277295
* Setter for the login session lifetime. This is how long the session will stay valid. Value is in hours.
278296
*

src/test/java/com/auth0/json/mgmt/tenants/TenantTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
public class TenantTest extends JsonTest<Tenant> {
1414

15-
private static final String json = "{\"change_password\":{},\"guardian_mfa_page\":{},\"default_audience\":\"https://domain.auth0.com/myapi\",\"default_directory\":\"Username-Password-Authentication\",\"error_page\":{},\"flags\":{},\"friendly_name\":\"My-Tenant\",\"picture_url\":\"https://pic.to/123\",\"support_email\":\"support@auth0.com\",\"support_url\":\"https://support.auth0.com\",\"allowed_logout_urls\":[\"https://domain.auth0.com/logout\"], \"session_lifetime\":24, \"idle_session_lifetime\":0.5}";
15+
private static final String json = "{\"change_password\":{},\"guardian_mfa_page\":{},\"default_audience\":\"https://domain.auth0.com/myapi\",\"default_directory\":\"Username-Password-Authentication\",\"error_page\":{},\"flags\":{},\"friendly_name\":\"My-Tenant\",\"picture_url\":\"https://pic.to/123\",\"support_email\":\"support@auth0.com\",\"support_url\":\"https://support.auth0.com\",\"allowed_logout_urls\":[\"https://domain.auth0.com/logout\"], \"session_lifetime\":24, \"idle_session_lifetime\":0.5, \"session_cookie\":{\"mode\": \"persistent\"}}";
16+
1617

1718
@Test
1819
public void shouldSerialize() throws Exception {
@@ -30,6 +31,7 @@ public void shouldSerialize() throws Exception {
3031
tenant.setAllowedLogoutUrls(Collections.singletonList("https://domain.auth0.com/logout"));
3132
tenant.setSessionLifetime(48);
3233
tenant.setIdleSessionLifetime(0);
34+
tenant.setSessionCookie(new SessionCookie("persistent"));
3335

3436
String serialized = toJSON(tenant);
3537
assertThat(serialized, is(notNullValue()));
@@ -47,6 +49,7 @@ public void shouldSerialize() throws Exception {
4749
assertThat(serialized, JsonMatcher.hasEntry("allowed_logout_urls", Arrays.asList("https://domain.auth0.com/logout")));
4850
assertThat(serialized, JsonMatcher.hasEntry("session_lifetime", 48));
4951
assertThat(serialized, JsonMatcher.hasEntry("idle_session_lifetime", 0));
52+
assertThat(serialized, JsonMatcher.hasEntry("session_cookie", notNullValue()));
5053
}
5154

5255
@Test
@@ -67,6 +70,8 @@ public void shouldDeserialize() throws Exception {
6770
assertThat(tenant.getAllowedLogoutUrls(), contains("https://domain.auth0.com/logout"));
6871
assertThat(tenant.getSessionLifetime(), is(24));
6972
assertThat(tenant.getIdleSessionLifetime(), is(0));
73+
assertThat(tenant.getSessionCookie(), is(notNullValue()));
74+
assertThat(tenant.getSessionCookie().getMode(), is("persistent"));
7075
}
7176

7277
}

src/test/resources/mgmt/tenant.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@
2929
"support_url": "https://mycompany.org/support",
3030
"allowed_logout_urls": [
3131
"https://mycompany.org/logoutCallback"
32-
]
32+
],
33+
"session_cookie": {
34+
"mode": "persistent"
35+
}
3336
}

0 commit comments

Comments
 (0)