-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
147 additions
and
120 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
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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/truelayer/java/http/auth/cache/CredentialsCacheHelper.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,17 @@ | ||
package com.truelayer.java.http.auth.cache; | ||
|
||
import com.truelayer.java.entities.RequestScopes; | ||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class CredentialsCacheHelper { | ||
private static final String CACHE_KEY_PREFIX = "tl-auth-token"; | ||
|
||
public static String buildKey(String clientId, RequestScopes requestScopes) { | ||
List<String> scopes = new ArrayList<>(requestScopes.getScopes()); | ||
Collections.sort(scopes); | ||
return MessageFormat.format("{0}:{1}:{2}", CACHE_KEY_PREFIX, clientId, scopes.hashCode()); | ||
} | ||
} |
21 changes: 3 additions & 18 deletions
21
src/main/java/com/truelayer/java/http/auth/cache/ICredentialsCache.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 |
---|---|---|
@@ -1,28 +1,13 @@ | ||
package com.truelayer.java.http.auth.cache; | ||
|
||
import com.truelayer.java.auth.entities.AccessToken; | ||
import com.truelayer.java.entities.RequestScopes; | ||
import java.util.Optional; | ||
|
||
public interface ICredentialsCache { | ||
|
||
/** | ||
* Gets the cached access token for the given request scopes. | ||
* @param scopes the requested scopes | ||
* @return an optional access token. If the token is expired an empty optional is returned | ||
*/ | ||
Optional<AccessToken> getToken(RequestScopes scopes); | ||
Optional<AccessToken> getToken(String key); | ||
|
||
/** | ||
* Stores an access token in cache for the given request scopes. | ||
* @param token the new token to store | ||
* @param scopes the requested scopes | ||
*/ | ||
void storeToken(RequestScopes scopes, AccessToken token); | ||
void storeToken(String key, AccessToken token); | ||
|
||
/** | ||
* Remove the entry in the cache for the given request scopes. | ||
* @param scopes the requested scopes | ||
*/ | ||
void clearToken(RequestScopes scopes); | ||
void clearToken(String key); | ||
} |
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.