Skip to content

Commit

Permalink
extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Nov 15, 2022
1 parent 2cd1ce0 commit 4f4d20e
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,26 @@ public DefaultOpenIdProviderMetadata fetch() {
.orElseGet(fetch(openIdClientConfiguration));
}

@NonNull
private Supplier<DefaultOpenIdProviderMetadata> fetch(@NonNull OpenIdClientConfiguration openIdClientConfiguration) {
return () -> openIdClientConfiguration.getIssuer()
.map(issuer -> {
try {
URL configurationUrl = new URL(issuer, StringUtils.prependUri(issuer.getPath(), openIdClientConfiguration.getConfigurationPath()));
if (LOG.isDebugEnabled()) {
LOG.debug("Sending request for OpenID configuration for provider [{}] to URL [{}]", openIdClientConfiguration.getName(), configurationUrl);
}
return client.toBlocking().retrieve(configurationUrl.toString(), DefaultOpenIdProviderMetadata.class);
} catch (HttpClientResponseException e) {
throw new BeanInstantiationException("Failed to retrieve OpenID configuration for " + openIdClientConfiguration.getName(), e);
} catch (MalformedURLException e) {
throw new BeanInstantiationException("Failure parsing issuer URL " + issuer.toString(), e);
}
}).orElse(new DefaultOpenIdProviderMetadata());
.map(this::fetch)
.orElse(new DefaultOpenIdProviderMetadata());
}

@NonNull
private DefaultOpenIdProviderMetadata fetch(@NonNull URL issuer) {
try {
URL configurationUrl = new URL(issuer, StringUtils.prependUri(issuer.getPath(), openIdClientConfiguration.getConfigurationPath()));
if (LOG.isDebugEnabled()) {
LOG.debug("Sending request for OpenID configuration for provider [{}] to URL [{}]", openIdClientConfiguration.getName(), configurationUrl);
}
return client.toBlocking().retrieve(configurationUrl.toString(), DefaultOpenIdProviderMetadata.class);
} catch (HttpClientResponseException e) {
throw new BeanInstantiationException("Failed to retrieve OpenID configuration for " + openIdClientConfiguration.getName(), e);
} catch (MalformedURLException e) {
throw new BeanInstantiationException("Failure parsing issuer URL " + issuer.toString(), e);
}
}

/**
Expand Down

0 comments on commit 4f4d20e

Please sign in to comment.