Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProgressDataCloudAuthenticationConfigurer implements AuthenticationConfigu
@Override
public void configureAuthentication(OkHttpClient.Builder clientBuilder, DatabaseClientFactory.ProgressDataCloudAuthContext securityContext) {
final String apiKey = securityContext.getApiKey();
if (apiKey == null || apiKey.trim().length() < 1) {
if (apiKey == null || apiKey.trim().isEmpty()) {
throw new IllegalArgumentException("No API key provided");
}
TokenGenerator tokenGenerator = new DefaultTokenGenerator(this.host, securityContext);
Expand Down Expand Up @@ -56,8 +56,8 @@ public DefaultTokenGenerator(String host, DatabaseClientFactory.ProgressDataClou
public String generateToken() {
final Response tokenResponse = callTokenEndpoint();
String token = getAccessTokenFromResponse(tokenResponse);
if (logger.isInfoEnabled()) {
logger.info("Successfully obtained authentication token");
if (logger.isDebugEnabled()) {
logger.debug("Successfully obtained authentication token");
}
return token;
}
Expand All @@ -70,8 +70,8 @@ private Response callTokenEndpoint() {
OkHttpUtil.configureSocketFactory(clientBuilder, securityContext.getSSLContext(), securityContext.getTrustManager());
OkHttpUtil.configureHostnameVerifier(clientBuilder, securityContext.getSSLHostnameVerifier());

if (logger.isInfoEnabled()) {
logger.info("Calling token endpoint at: " + tokenUrl);
if (logger.isDebugEnabled()) {
logger.debug("Calling token endpoint at: {}", tokenUrl);
}

final Call call = clientBuilder.build().newCall(
Expand All @@ -85,7 +85,7 @@ private Response callTokenEndpoint() {
return call.execute();
} catch (IOException e) {
throw new ProgressDataCloudException(String.format("Unable to call token endpoint at %s; cause: %s",
tokenUrl, e.getMessage(), e));
tokenUrl, e.getMessage()), e);
}
}

Expand All @@ -97,7 +97,8 @@ protected HttpUrl buildTokenUrl() {
.host(host)
.port(443)
.build()
.resolve(securityContext.getTokenEndpoint()).newBuilder();
.resolve(securityContext.getTokenEndpoint())
.newBuilder();

Integer duration = securityContext.getTokenDuration();
return duration != null ?
Expand Down Expand Up @@ -146,7 +147,7 @@ public TokenAuthenticationInterceptor(TokenGenerator tokenGenerator) {
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
addTokenToRequest(builder);
builder = addTokenToRequest(builder);
Response response = chain.proceed(builder.build());
if (response.code() == 401) {
logger.info("Received 401; will generate new token if necessary and retry request");
Expand All @@ -155,7 +156,7 @@ public Response intercept(Chain chain) throws IOException {
generateNewTokenIfNecessary(currentToken);

builder = chain.request().newBuilder();
addTokenToRequest(builder);
builder = addTokenToRequest(builder);
response = chain.proceed(builder.build());
}
return response;
Expand Down