mirror of
https://github.com/Telecominfraproject/wlan-cloud-rrm.git
synced 2025-11-02 11:37:54 +00:00
@@ -142,9 +142,6 @@ public class UCentralClient {
|
|||||||
*/
|
*/
|
||||||
private WebTokenResult accessToken;
|
private WebTokenResult accessToken;
|
||||||
|
|
||||||
/** Time window before expiry (6 hours) in secondes */
|
|
||||||
private final int TOKEN_REFRESH_WINDOW_S = 21600;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param rrmEndpoint advertise this RRM endpoint to the SDK
|
* @param rrmEndpoint advertise this RRM endpoint to the SDK
|
||||||
@@ -210,7 +207,10 @@ public class UCentralClient {
|
|||||||
logger.debug("Response body: {}", response.getBody());
|
logger.debug("Response body: {}", response.getBody());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (token == null || token.access_token == null || token.access_token.isEmpty()) {
|
if (
|
||||||
|
token == null || token.access_token == null ||
|
||||||
|
token.access_token.isEmpty()
|
||||||
|
) {
|
||||||
logger.error("Login failed: Missing access token");
|
logger.error("Login failed: Missing access token");
|
||||||
logger.debug("Response body: {}", response.toString());
|
logger.debug("Response body: {}", response.toString());
|
||||||
return false;
|
return false;
|
||||||
@@ -233,6 +233,20 @@ public class UCentralClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the token is completely expired even if
|
||||||
|
* for a token refresh request
|
||||||
|
*
|
||||||
|
* @return true if the refresh token is expired
|
||||||
|
*/
|
||||||
|
private boolean isRefreshTokenExpired() {
|
||||||
|
if (accessToken == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return accessToken.created + accessToken.expires_in <
|
||||||
|
Instant.now().getEpochSecond();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an access token is expired.
|
* Check if an access token is expired.
|
||||||
*
|
*
|
||||||
@@ -242,7 +256,7 @@ public class UCentralClient {
|
|||||||
if (accessToken == null) {
|
if (accessToken == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return accessToken.created + TOKEN_REFRESH_WINDOW_S <
|
return accessToken.created + accessToken.idle_timeout <
|
||||||
Instant.now().getEpochSecond();
|
Instant.now().getEpochSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +271,7 @@ public class UCentralClient {
|
|||||||
if (!usePublicEndpoints) {
|
if (!usePublicEndpoints) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (accessToken == null) {
|
if (isRefreshTokenExpired()) {
|
||||||
logger.info("Token is expired, login again");
|
logger.info("Token is expired, login again");
|
||||||
if (login()) {
|
if (login()) {
|
||||||
return accessToken;
|
return accessToken;
|
||||||
@@ -430,7 +444,7 @@ public class UCentralClient {
|
|||||||
.connectTimeout(connectTimeoutMs)
|
.connectTimeout(connectTimeoutMs)
|
||||||
.socketTimeout(socketTimeoutMs);
|
.socketTimeout(socketTimeoutMs);
|
||||||
if (usePublicEndpoints) {
|
if (usePublicEndpoints) {
|
||||||
if (accessToken != null) {
|
if (!isRefreshTokenExpired()) {
|
||||||
req.header(
|
req.header(
|
||||||
"Authorization",
|
"Authorization",
|
||||||
"Bearer " + accessToken.access_token
|
"Bearer " + accessToken.access_token
|
||||||
@@ -483,7 +497,7 @@ public class UCentralClient {
|
|||||||
req.queryString(parameters);
|
req.queryString(parameters);
|
||||||
}
|
}
|
||||||
if (usePublicEndpoints) {
|
if (usePublicEndpoints) {
|
||||||
if (accessToken != null) {
|
if (!isRefreshTokenExpired()) {
|
||||||
req.header(
|
req.header(
|
||||||
"Authorization",
|
"Authorization",
|
||||||
"Bearer " + accessToken.access_token
|
"Bearer " + accessToken.access_token
|
||||||
|
|||||||
Reference in New Issue
Block a user