-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/#309-read-config-from-arbitrary-dire…
…ctories
- Loading branch information
Showing
11 changed files
with
550 additions
and
247 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
161 changes: 38 additions & 123 deletions
161
client/src/main/java/com/networknt/client/Http2Client.java
Large diffs are not rendered by default.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
client/src/main/java/com/networknt/client/oauth/Jwt.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,105 @@ | ||
package com.networknt.client.oauth; | ||
|
||
import com.networknt.config.Config; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* a model class represents a JWT mostly for caching usage so that we don't need to decrypt jwt string to get info. | ||
* it will load config from client.yml/oauth/token | ||
*/ | ||
public class Jwt { | ||
private String jwt; // the cached jwt token for client credentials grant type | ||
private long expire; // jwt expire time in millisecond so that we don't need to parse the jwt. | ||
private volatile boolean renewing = false; | ||
private volatile long expiredRetryTimeout; | ||
private volatile long earlyRetryTimeout; | ||
|
||
private static long tokenRenewBeforeExpired; | ||
private static long expiredRefreshRetryDelay; | ||
private static long earlyRefreshRetryDelay; | ||
|
||
static final String OAUTH = "oauth"; | ||
static final String TOKEN = "token"; | ||
static final String TOKEN_RENEW_BEFORE_EXPIRED = "tokenRenewBeforeExpired"; | ||
static final String EXPIRED_REFRESH_RETRY_DELAY = "expiredRefreshRetryDelay"; | ||
static final String EARLY_REFRESH_RETRY_DELAY = "earlyRefreshRetryDelay"; | ||
public static final String CLIENT_CONFIG_NAME = "client"; | ||
|
||
public Jwt() { | ||
Map<String, Object> clientConfig = Config.getInstance().getJsonMapConfig(CLIENT_CONFIG_NAME); | ||
if(clientConfig != null) { | ||
Map<String, Object> oauthConfig = (Map<String, Object>)clientConfig.get(OAUTH); | ||
if(oauthConfig != null) { | ||
Map<String, Object> tokenConfig = (Map<String, Object>)oauthConfig.get(TOKEN); | ||
tokenRenewBeforeExpired = (Integer) tokenConfig.get(TOKEN_RENEW_BEFORE_EXPIRED); | ||
expiredRefreshRetryDelay = (Integer)tokenConfig.get(EXPIRED_REFRESH_RETRY_DELAY); | ||
earlyRefreshRetryDelay = (Integer)tokenConfig.get(EARLY_REFRESH_RETRY_DELAY); | ||
} | ||
} | ||
} | ||
|
||
public String getJwt() { | ||
return jwt; | ||
} | ||
|
||
public void setJwt(String jwt) { | ||
this.jwt = jwt; | ||
} | ||
|
||
public long getExpire() { | ||
return expire; | ||
} | ||
|
||
public void setExpire(long expire) { | ||
this.expire = expire; | ||
} | ||
|
||
public boolean isRenewing() { | ||
return renewing; | ||
} | ||
|
||
public void setRenewing(boolean renewing) { | ||
this.renewing = renewing; | ||
} | ||
|
||
public long getExpiredRetryTimeout() { | ||
return expiredRetryTimeout; | ||
} | ||
|
||
public void setExpiredRetryTimeout(long expiredRetryTimeout) { | ||
this.expiredRetryTimeout = expiredRetryTimeout; | ||
} | ||
|
||
public long getEarlyRetryTimeout() { | ||
return earlyRetryTimeout; | ||
} | ||
|
||
public void setEarlyRetryTimeout(long earlyRetryTimeout) { | ||
this.earlyRetryTimeout = earlyRetryTimeout; | ||
} | ||
|
||
public static long getTokenRenewBeforeExpired() { | ||
return tokenRenewBeforeExpired; | ||
} | ||
|
||
public static void setTokenRenewBeforeExpired(long tokenRenewBeforeExpired) { | ||
Jwt.tokenRenewBeforeExpired = tokenRenewBeforeExpired; | ||
} | ||
|
||
public static long getExpiredRefreshRetryDelay() { | ||
return expiredRefreshRetryDelay; | ||
} | ||
|
||
public static void setExpiredRefreshRetryDelay(long expiredRefreshRetryDelay) { | ||
Jwt.expiredRefreshRetryDelay = expiredRefreshRetryDelay; | ||
} | ||
|
||
public static long getEarlyRefreshRetryDelay() { | ||
return earlyRefreshRetryDelay; | ||
} | ||
|
||
public static void setEarlyRefreshRetryDelay(long earlyRefreshRetryDelay) { | ||
Jwt.earlyRefreshRetryDelay = earlyRefreshRetryDelay; | ||
} | ||
} |
Oops, something went wrong.