Skip to content

Commit 52532ae

Browse files
committed
added some validation checks to the tsdb oauth
1 parent 850fd86 commit 52532ae

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/normalizeddata/timeseriesdb/oauth/OAuthTokenResponse.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public class OAuthTokenResponse {
4949
@JsonProperty(value = "refresh_token")
5050
private String refreshToken;
5151
@JsonProperty(value = "expires_in")
52-
private int expiresIn;
52+
private Integer expiresIn;
5353
@JsonProperty(value = "token_type")
5454
private String tokenType;
55+
56+
public boolean checkInvalid() {
57+
return ((accessToken == null) || (expiresIn == null) || (tokenType == null));
58+
}
5559
}

IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/normalizeddata/timeseriesdb/oauth/TimeSeriesDBOAuthTokenRetriever.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ public synchronized String getToken() throws OAuthTokenRetrievalException {
129129
throw new OAuthTokenRetrievalException(
130130
"IOException in mapping, this should not happen " + e.getLocalizedMessage(), e);
131131
}
132+
// make sure that the fields we need have been set
133+
if (atr.checkInvalid()) {
134+
throw new OAuthTokenRetrievalException("Returned token details have null or missing values " + atr
135+
+ ", maybe an authentication issue. Check the properties username, password, tenancyocid and databasename under "
136+
+ TimeSeriesDBProperties.TIME_SERIES_PROPERTY_OAUTH);
137+
}
132138
this.currentToken = atr.getAccessToken();
133139
this.tokenType = atr.getTokenType();
134140
// get a new renewal time, allow 60 seconds for processing the renewal if we
@@ -148,5 +154,8 @@ public synchronized String getToken() throws OAuthTokenRetrievalException {
148154
public void onStartup(StartupEvent event) {
149155
log.info("Startup event received for TimeSeriesDBOAuthTokenRetriever tsDBuserCredentials="
150156
+ tsDBuserCredentials.safeToString() + ", queryX=" + queryX + ", queryY=" + queryY);
157+
if (debugOauth) {
158+
log.info("Full credentials are " + tsDBuserCredentials.toString());
159+
}
151160
}
152161
}

0 commit comments

Comments
 (0)