-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add refresh token configuration object to client (#321)
- Loading branch information
Jake Uskoski
authored
Nov 19, 2020
1 parent
9ebdfdd
commit 19b617f
Showing
4 changed files
with
251 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
src/main/java/com/auth0/json/mgmt/client/RefreshToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
package com.auth0.json.mgmt.client; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* Class that represents the configuration of refresh tokens for a client. | ||
*/ | ||
@SuppressWarnings({"unused", "WeakerAccess"}) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class RefreshToken { | ||
|
||
@JsonProperty("rotation_type") | ||
private String rotationType; | ||
@JsonProperty("expiration_type") | ||
private String expirationType; | ||
@JsonProperty("leeway") | ||
private Integer leeway; | ||
@JsonProperty("token_lifetime") | ||
private Integer tokenLifetime; | ||
@JsonProperty("infinite_token_lifetime") | ||
private Boolean infiniteTokenLifetime; | ||
@JsonProperty("idle_token_lifetime") | ||
private Integer idleTokenLifetime; | ||
@JsonProperty("infinite_idle_token_lifetime") | ||
private Boolean infiniteIdleTokenLifetime; | ||
|
||
/** | ||
* Getter for the rotation type of the refresh token. | ||
* | ||
* @return the rotation type. | ||
*/ | ||
@JsonProperty("rotation_type") | ||
public String getRotationType() { | ||
return rotationType; | ||
} | ||
|
||
/** | ||
* Setter for the rotation type of the refresh token. | ||
* | ||
* @param rotationType the rotation type to set. | ||
*/ | ||
@JsonProperty("rotation_type") | ||
public void setRotationType(String rotationType) { | ||
this.rotationType = rotationType; | ||
} | ||
|
||
/** | ||
* Getter for the expiration type of the refresh token. | ||
* | ||
* @return the expiration type. | ||
*/ | ||
@JsonProperty("expiration_type") | ||
public String getExpirationType() { | ||
return expirationType; | ||
} | ||
|
||
/** | ||
* Setter for the expiration type of the refresh token. | ||
* | ||
* @param expirationType the expiration type to set. | ||
*/ | ||
@JsonProperty("expiration_type") | ||
public void setExpirationType(String expirationType) { | ||
this.expirationType = expirationType; | ||
} | ||
|
||
/** | ||
* Getter for the period in seconds where the previous refresh token can be exchanged without | ||
* triggering breach detection. | ||
* | ||
* @return the leeway in seconds. | ||
*/ | ||
@JsonProperty("leeway") | ||
public Integer getLeeway() { | ||
return leeway; | ||
} | ||
|
||
/** | ||
* Setter for the period in seconds where the previous refresh token can be exchanged without | ||
* triggering breach detection. | ||
* | ||
* @param leeway the leeway in seconds. | ||
*/ | ||
@JsonProperty("leeway") | ||
public void setLeeway(Integer leeway) { | ||
this.leeway = leeway; | ||
} | ||
|
||
/** | ||
* Getter for the period in seconds for which refresh tokens will remain valid. | ||
* | ||
* @return a token's lifetime in seconds. | ||
*/ | ||
@JsonProperty("token_lifetime") | ||
public Integer getTokenLifetime() { | ||
return tokenLifetime; | ||
} | ||
|
||
/** | ||
* Setter for the period in seconds for which refresh tokens will remain valid. | ||
* | ||
* @param tokenLifetime a token's lifetime in seconds. | ||
*/ | ||
@JsonProperty("token_lifetime") | ||
public void setTokenLifetime(Integer tokenLifetime) { | ||
this.tokenLifetime = tokenLifetime; | ||
} | ||
|
||
/** | ||
* Getter for determining whether tokens have a set lifetime or not. This takes precedence over | ||
* token_lifetime values. | ||
* | ||
* @return true if tokens do not have a set lifetime, false otherwise. | ||
*/ | ||
@JsonProperty("infinite_token_lifetime") | ||
public Boolean getInfiniteTokenLifetime() { | ||
return infiniteTokenLifetime; | ||
} | ||
|
||
/** | ||
* Setter for determining whether tokens have a set lifetime or not. This takes precedence over | ||
* token_lifetime values. | ||
* | ||
* @param infiniteTokenLifetime true if tokens do not have a set lifetime, false otherwise. | ||
*/ | ||
@JsonProperty("infinite_token_lifetime") | ||
public void setInfiniteTokenLifetime(Boolean infiniteTokenLifetime) { | ||
this.infiniteTokenLifetime = infiniteTokenLifetime; | ||
} | ||
|
||
/** | ||
* Getter for the period in seconds for which refresh tokens will remain valid without use. | ||
* | ||
* @return a token's lifetime without use in seconds. | ||
*/ | ||
@JsonProperty("idle_token_lifetime") | ||
public Integer getIdleTokenLifetime() { | ||
return idleTokenLifetime; | ||
} | ||
|
||
/** | ||
* Setter for the period in seconds for which refresh tokens will remain valid without use. | ||
* | ||
* @param idleTokenLifetime a token's lifetime without use in seconds. | ||
*/ | ||
@JsonProperty("idle_token_lifetime") | ||
public void setIdleTokenLifetime(Integer idleTokenLifetime) { | ||
this.idleTokenLifetime = idleTokenLifetime; | ||
} | ||
|
||
/** | ||
* Getter for determining whether tokens expire without use or not. This takes precedence over | ||
* idle_token_lifetime values. | ||
* | ||
* @return true if tokens do not expire from lack of use, false otherwise. | ||
*/ | ||
@JsonProperty("infinite_idle_token_lifetime") | ||
public Boolean getInfiniteIdleTokenLifetime() { | ||
return infiniteIdleTokenLifetime; | ||
} | ||
|
||
/** | ||
* Setter for determining whether tokens expire without use or not. This takes precedence over | ||
* idle_token_lifetime values. | ||
* | ||
* @param infiniteIdleTokenLifetime true if tokens do not expire from lack of use, false | ||
* otherwise. | ||
*/ | ||
@JsonProperty("infinite_idle_token_lifetime") | ||
public void setInfiniteIdleTokenLifetime(Boolean infiniteIdleTokenLifetime) { | ||
this.infiniteIdleTokenLifetime = infiniteIdleTokenLifetime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/auth0/json/mgmt/client/RefreshTokenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.auth0.json.mgmt.client; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
import com.auth0.json.JsonMatcher; | ||
import com.auth0.json.JsonTest; | ||
import org.junit.Test; | ||
|
||
public class RefreshTokenTest extends JsonTest<RefreshToken> { | ||
|
||
private static final String json = "{\"rotation_type\":\"non-rotating\",\"expiration_type\":\"non-expiring\",\"leeway\":0,\"token_lifetime\":0,\"infinite_token_lifetime\":false,\"idle_token_lifetime\":0,\"infinite_idle_token_lifetime\":false}"; | ||
|
||
@Test | ||
public void shouldSerialize() throws Exception { | ||
RefreshToken refreshToken = new RefreshToken(); | ||
refreshToken.setRotationType("non-rotating"); | ||
refreshToken.setExpirationType("non-expiring"); | ||
refreshToken.setLeeway(0); | ||
refreshToken.setTokenLifetime(0); | ||
refreshToken.setInfiniteTokenLifetime(false); | ||
refreshToken.setIdleTokenLifetime(0); | ||
refreshToken.setInfiniteIdleTokenLifetime(false); | ||
|
||
String serialized = toJSON(refreshToken); | ||
assertThat(serialized, is(notNullValue())); | ||
assertThat(serialized, JsonMatcher.hasEntry("rotation_type", "non-rotating")); | ||
assertThat(serialized, JsonMatcher.hasEntry("expiration_type", "non-expiring")); | ||
assertThat(serialized, JsonMatcher.hasEntry("leeway", 0)); | ||
assertThat(serialized, JsonMatcher.hasEntry("token_lifetime", 0)); | ||
assertThat(serialized, JsonMatcher.hasEntry("infinite_token_lifetime", false)); | ||
assertThat(serialized, JsonMatcher.hasEntry("idle_token_lifetime", 0)); | ||
assertThat(serialized, JsonMatcher.hasEntry("infinite_idle_token_lifetime", false)); | ||
} | ||
|
||
@Test | ||
public void shouldDeserialize() throws Exception { | ||
RefreshToken refreshToken = fromJSON(json, RefreshToken.class); | ||
|
||
assertThat(refreshToken, is(notNullValue())); | ||
assertThat(refreshToken.getRotationType(), is("non-rotating")); | ||
assertThat(refreshToken.getExpirationType(), is("non-expiring")); | ||
assertThat(refreshToken.getLeeway(), is(0)); | ||
assertThat(refreshToken.getTokenLifetime(), is(0)); | ||
assertThat(refreshToken.getInfiniteTokenLifetime(), is(false)); | ||
assertThat(refreshToken.getIdleTokenLifetime(), is(0)); | ||
assertThat(refreshToken.getInfiniteIdleTokenLifetime(), is(false)); | ||
} | ||
} |