-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #516 from bcgov/develop/alex-GRAD2-2377
GRAD2-2377
- Loading branch information
Showing
13 changed files
with
267 additions
and
47 deletions.
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
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
42 changes: 42 additions & 0 deletions
42
api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/ResponseObjCache.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,42 @@ | ||
package ca.bc.gov.educ.api.graduation.model.dto; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.util.Base64; | ||
|
||
public class ResponseObjCache { | ||
|
||
private long tokenExpiry = 0; | ||
private ResponseObj responseObj; | ||
|
||
// tokenExpiry-[seconds] provides a slight offset, if token WILL expire in | ||
// [seconds], obtain a new one | ||
private int offset; | ||
|
||
public ResponseObjCache(int offset) { | ||
this.offset = offset; | ||
} | ||
|
||
public ResponseObj getResponseObj() { | ||
return responseObj; | ||
} | ||
|
||
public void setResponseObj(ResponseObj responseObj) { | ||
this.setTokenExpiry(responseObj); | ||
this.responseObj = responseObj; | ||
} | ||
|
||
public boolean isExpired(){ | ||
// tokenExpiry-[seconds] provides a slight offset, if token WILL expire in | ||
// 10 seconds, obtain a new one | ||
return (responseObj == null) || (tokenExpiry-offset) < (System.currentTimeMillis() / 1000); | ||
} | ||
|
||
private void setTokenExpiry(ResponseObj responseObj){ | ||
String[] parts = responseObj.getAccess_token().split("\\."); | ||
JSONObject payload = new JSONObject(new String(Base64.getUrlDecoder().decode(parts[1]))); | ||
this.tokenExpiry = payload.getLong("exp"); | ||
} | ||
|
||
|
||
} |
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
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
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
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
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
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
Oops, something went wrong.