Source:
public QueryRequest process(Source source, QueryRequest input) throws StopProcessingException { OAuthFederatedSource oauthSource = getSource(source); if (oauthSource == null) { return input; } Object securityAssertion = input.getProperties().get(SECURITY_SUBJECT); if (!(securityAssertion instanceof Subject)) { LOGGER.warn("A user Subject is not available."); throw new StopProcessingException("A user Subject is not available."); } Subject subject = (Subject) securityAssertion; String userId = SubjectUtils.getEmailAddress(subject); if (userId == null) { userId = SubjectUtils.getName(subject); } TokenInformation.TokenEntry tokenEntry = tokenStorage.read(userId, oauthSource.getId()); OIDCProviderMetadata metadata; try { metadata = OIDCProviderMetadata.parse( resourceRetriever .retrieveResource(new URL(oauthSource.getOauthDiscoveryUrl())) .getContent()); } catch (OAuthServiceException | IOException | ParseException e) { LOGGER.error( "Unable to retrieve OAuth provider's metadata for the source.", oauthSource.getId()); throw new StopProcessingException("Unable to retrieve OAuth provider's metadata."); } if (tokenEntry == null) { findExistingTokens(oauthSource, userId); throw createNoAuthException( oauthSource, userId, metadata, "the user's tokens were not found."); } if (!oauthSource.getOauthDiscoveryUrl().equals(tokenEntry.getDiscoveryUrl())) { tokenStorage.delete(userId, oauthSource.getId()); throw createNoAuthException( oauthSource, userId, metadata, "the oauth provider information has been changed and is different from the one stored."); } verifyAccessToken(oauthSource, userId, tokenEntry, metadata); return input; }

Target:
public QueryRequest process(Source source, QueryRequest input) throws StopProcessingException { OAuthFederatedSource oauthSource = getSource(source); if (oauthSource == null) { return input; } Object securityAssertion = input.getProperties().get(SECURITY_SUBJECT); if (!(securityAssertion instanceof Subject)) { LOGGER.warn("A user Subject is not available."); throw new StopProcessingException("A user Subject is not available."); } Subject subject = (Subject) securityAssertion; String userId = SubjectUtils.getEmailAddress(subject); if (userId == null) { userId = SubjectUtils.getName(subject); } TokenInformation.TokenEntry tokenEntry = tokenStorage.read(userId, oauthSource.getId()); OIDCProviderMetadata metadata; try { metadata = OIDCProviderMetadata.parse( resourceRetriever .retrieveResource(new URL(oauthSource.getOauthDiscoveryUrl())) .getContent()); } catch (OAuthServiceException | IOException | ParseException e) { LOGGER.error( "Unable to retrieve OAuth provider's metadata for the source.", oauthSource.getId()); throw new StopProcessingException("Unable to retrieve OAuth provider's metadata."); } if (tokenEntry == null) { findExistingTokens(oauthSource, userId, metadata); throw createNoAuthException( oauthSource, userId, metadata, "the user's tokens were not found."); } if (!oauthSource.getOauthDiscoveryUrl().equals(tokenEntry.getDiscoveryUrl())) { tokenStorage.delete(userId, oauthSource.getId()); findExistingTokens(oauthSource, userId, metadata); throw createNoAuthException( oauthSource, userId, metadata, "the oauth provider information has been changed and is different from the one stored."); } verifyAccessToken(oauthSource, userId, tokenEntry, metadata); return input; }