Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#309-read-config-from-arbitrary-dire…
Browse files Browse the repository at this point in the history
…ctories
  • Loading branch information
NicholasAzar committed Feb 13, 2019
2 parents c498f51 + 3792e95 commit 878fb94
Show file tree
Hide file tree
Showing 11 changed files with 550 additions and 247 deletions.
5 changes: 4 additions & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<groupId>com.networknt</groupId>
<artifactId>status</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>monad-result</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down Expand Up @@ -85,5 +89,4 @@
<scope>test</scope>
</dependency>
</dependencies>

</project>
161 changes: 38 additions & 123 deletions client/src/main/java/com/networknt/client/Http2Client.java

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions client/src/main/java/com/networknt/client/oauth/Jwt.java
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;
}
}
Loading

0 comments on commit 878fb94

Please sign in to comment.