From 6d3b27ed2b66fbb8d43944e675367964817340cd Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Thu, 9 Sep 2021 23:17:10 +0200 Subject: [PATCH] Added additional methods --- src/zutil/Timer.java | 10 ++++++ .../net/http/page/oauth/OAuth2Registry.java | 36 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/zutil/Timer.java b/src/zutil/Timer.java index 3c50a43..ec13ea6 100755 --- a/src/zutil/Timer.java +++ b/src/zutil/Timer.java @@ -49,6 +49,7 @@ public class Timer { reset(); } + /** * Will start or restart the timer if it is already running * @@ -73,6 +74,15 @@ public class Timer { return timestamp + period < System.currentTimeMillis(); } + /** + * @return the timestamp in the future based on epoc in milliseconds where the timer will timeout or -1 if the timer has already timeout. + */ + public long getTimeoutTimeMillis() { + if (hasTimedOut()) + return -1; + return timestamp + period; + } + public String toString() { if (hasTimedOut()) return "Timed out"; diff --git a/src/zutil/net/http/page/oauth/OAuth2Registry.java b/src/zutil/net/http/page/oauth/OAuth2Registry.java index d2f1cd0..f976bc8 100644 --- a/src/zutil/net/http/page/oauth/OAuth2Registry.java +++ b/src/zutil/net/http/page/oauth/OAuth2Registry.java @@ -235,6 +235,42 @@ public class OAuth2Registry implements Serializable { return null; } + /** + * @param clientId is the client_id string + * @return all the authorization codes assigned to the given clientID or empty list if client does not exist + */ + public List getAuthenticationCodes(String clientId) { + OAuth2ClientRegister clientRegister = getClientRegister(clientId); + + if (clientRegister != null) + return new ArrayList<>(clientRegister.authCodes.keySet()); + return Collections.EMPTY_LIST; + } + + /** + * @param clientId is the client_id string + * @return all the access tokens assigned to the given clientID or empty list if client does not exist + */ + public List getAccessTokens(String clientId) { + OAuth2ClientRegister clientRegister = getClientRegister(clientId); + + if (clientRegister != null) + return new ArrayList<>(clientRegister.accessTokens.keySet()); + return Collections.EMPTY_LIST; + } + + /** + * @param token is the access token to get timeout value for. + * @return an epic based value in milliseconds where the token stops being valid or -1 if token is already invalid or does not exist. + */ + public long getAccessTokenTimeout(String token) { + OAuth2ClientRegister clientRegister = getClientRegisterForToken(token); + + if (clientRegister != null) + return clientRegister.accessTokens.get(token).getTimeoutTimeMillis(); + return -1; + } + // ------------------------------------------------------ // Listeners // ------------------------------------------------------