Source:
public void setUserTokenOnClient( Client client, String sourceId, String clientId, String clientSecret, String username, String password, String discoveryUrl, Map<String, String> additionalParameters) { if (client == null || Strings.isBlank(sourceId) || Strings.isBlank(username)) { return; } TokenInformation.TokenEntry tokenEntry = tokenStorage.read(username, sourceId); if (tokenEntry != null && discoveryUrl.equalsIgnoreCase(tokenEntry.getDiscoveryUrl()) && !isExpired(tokenEntry.getAccessToken())) { LOGGER.debug("Adding access token to OAUTH header."); client.header(OAUTH, BEARER + tokenEntry.getAccessToken()); return; } if (Strings.isBlank(clientId) || Strings.isBlank(clientSecret) || Strings.isBlank(username) || Strings.isBlank(password) || Strings.isBlank(discoveryUrl)) { return; } String encodedClientIdSecret = Base64.getEncoder().encodeToString((clientId + ":" + clientSecret).getBytes(UTF_8)); Map<String, String> queryParameters = additionalParameters == null ? new HashMap<>() : new HashMap<>(additionalParameters); queryParameters.put(USERNAME, username); queryParameters.put(PASSWORD, password); String accessToken = getNewAccessToken( username, sourceId, encodedClientIdSecret, discoveryUrl, PASSWORD, queryParameters); if (accessToken == null) { return; } client.header(OAUTH, BEARER + accessToken); }

Target:
public void setUserTokenOnClient( Client client, String sourceId, String clientId, String clientSecret, String username, String password, String discoveryUrl, Map<String, String> additionalParameters) { if (client == null || Strings.isBlank(sourceId) || Strings.isBlank(username)) { return; } TokenInformation.TokenEntry tokenEntry = tokenStorage.read(username, sourceId); if (tokenEntry != null && discoveryUrl.equalsIgnoreCase(tokenEntry.getDiscoveryUrl()) && !isExpired(tokenEntry.getAccessToken())) { LOGGER.debug("Adding access token to OAUTH header."); client.header(OAUTH, BEARER + tokenEntry.getAccessToken()); return; } if (Strings.isBlank(clientId) || Strings.isBlank(clientSecret) || Strings.isBlank(username) || Strings.isBlank(password) || Strings.isBlank(discoveryUrl)) { return; } OIDCProviderMetadata metadata; try { metadata = OIDCProviderMetadata.parse( resourceRetriever.retrieveResource(new URL(discoveryUrl)).getContent()); } catch (IOException | ParseException e) { LOGGER.error("Unable to retrieve OAuth provider's metadata.", e); return; } if (tokenEntry != null && discoveryUrl.equalsIgnoreCase(tokenEntry.getDiscoveryUrl()) && isExpired(tokenEntry.getAccessToken()) && !isExpired(tokenEntry.getRefreshToken())) { String accessToken = refreshToken( sourceId, clientId, clientSecret, username, discoveryUrl, tokenEntry.getRefreshToken(), metadata); if (accessToken != null) { LOGGER.debug("Adding access token to OAUTH header."); client.header(OAUTH, BEARER + accessToken); return; } } String encodedClientIdSecret = Base64.getEncoder().encodeToString((clientId + ":" + clientSecret).getBytes(UTF_8)); Map<String, String> queryParameters = additionalParameters == null ? new HashMap<>() : new HashMap<>(additionalParameters); queryParameters.put(USERNAME, username); queryParameters.put(PASSWORD, password); String accessToken = getNewAccessToken( username, sourceId, encodedClientIdSecret, discoveryUrl, PASSWORD, queryParameters, metadata); if (accessToken == null) { return; } client.header(OAUTH, BEARER + accessToken); }