Skip to content

Commit

Permalink
Avoid UriComponentsBuilder.fromUri
Browse files Browse the repository at this point in the history
Closes 15852
  • Loading branch information
bodograumann committed Sep 25, 2024
1 parent 3b20844 commit 4416beb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

/**
Expand Down Expand Up @@ -82,11 +83,12 @@ private JwtDecoderProviderConfigurationUtils() {
}

static Map<String, Object> getConfigurationForOidcIssuerLocation(String oidcIssuerLocation) {
return getConfiguration(oidcIssuerLocation, rest, oidc(URI.create(oidcIssuerLocation)));
UriComponents uri = UriComponentsBuilder.fromUriString(oidcIssuerLocation).build();
return getConfiguration(oidcIssuerLocation, rest, oidc(uri));
}

static Map<String, Object> getConfigurationForIssuerLocation(String issuer, RestOperations rest) {
URI uri = URI.create(issuer);
UriComponents uri = UriComponentsBuilder.fromUriString(issuer).build();
return getConfiguration(issuer, rest, oidc(uri), oidcRfc8414(uri), oauth(uri));
}

Expand Down Expand Up @@ -183,25 +185,25 @@ private static Map<String, Object> getConfiguration(String issuer, RestOperation
throw new IllegalArgumentException(errorMessage);
}

private static URI oidc(URI issuer) {
private static URI oidc(UriComponents issuer) {
// @formatter:off
return UriComponentsBuilder.fromUri(issuer)
return UriComponentsBuilder.newInstance().uriComponents(issuer)
.replacePath(issuer.getPath() + OIDC_METADATA_PATH)
.build(Collections.emptyMap());
// @formatter:on
}

private static URI oidcRfc8414(URI issuer) {
private static URI oidcRfc8414(UriComponents issuer) {
// @formatter:off
return UriComponentsBuilder.fromUri(issuer)
return UriComponentsBuilder.newInstance().uriComponents(issuer)
.replacePath(OIDC_METADATA_PATH + issuer.getPath())
.build(Collections.emptyMap());
// @formatter:on
}

private static URI oauth(URI issuer) {
private static URI oauth(UriComponents issuer) {
// @formatter:off
return UriComponentsBuilder.fromUri(issuer)
return UriComponentsBuilder.newInstance().uriComponents(issuer)
.replacePath(OAUTH_METADATA_PATH + issuer.getPath())
.build(Collections.emptyMap());
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

final class ReactiveJwtDecoderProviderConfigurationUtils {
Expand Down Expand Up @@ -93,29 +94,29 @@ else if (jwk.getKeyType() == KeyType.EC) {
}

static Mono<Map<String, Object>> getConfigurationForIssuerLocation(String issuer, WebClient web) {
URI uri = URI.create(issuer);
UriComponents uri = UriComponentsBuilder.fromUriString(issuer).build();
return getConfiguration(issuer, web, oidc(uri), oidcRfc8414(uri), oauth(uri));
}

private static URI oidc(URI issuer) {
private static URI oidc(UriComponents issuer) {
// @formatter:off
return UriComponentsBuilder.fromUri(issuer)
return UriComponentsBuilder.newInstance().uriComponents(issuer)
.replacePath(issuer.getPath() + OIDC_METADATA_PATH)
.build(Collections.emptyMap());
// @formatter:on
}

private static URI oidcRfc8414(URI issuer) {
private static URI oidcRfc8414(UriComponents issuer) {
// @formatter:off
return UriComponentsBuilder.fromUri(issuer)
return UriComponentsBuilder.newInstance().uriComponents(issuer)
.replacePath(OIDC_METADATA_PATH + issuer.getPath())
.build(Collections.emptyMap());
// @formatter:on
}

private static URI oauth(URI issuer) {
private static URI oauth(UriComponents issuer) {
// @formatter:off
return UriComponentsBuilder.fromUri(issuer)
return UriComponentsBuilder.newInstance().uriComponents(issuer)
.replacePath(OAUTH_METADATA_PATH + issuer.getPath())
.build(Collections.emptyMap());
// @formatter:on
Expand Down

0 comments on commit 4416beb

Please sign in to comment.