@Test public void retrieveEndpoints_badRequest_throwsException() throws IOException { String errorDescription = "Something wen't wrong"; CloseableHttpResponse response = HttpClientTestFactory .createHttpResponse(errorDescription, HttpStatus.SC_BAD_REQUEST); when(httpClientMock.execute(any())).thenReturn(response); assertThatThrownBy(() -> retrieveEndpoints()) .isInstanceOf(OAuth2ServiceException.class) .hasMessageContaining(errorDescription); }
@Override public OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(discoveryEndpointUri, "discoveryEndpointUri must not be null!"); HttpUriRequest request = new HttpGet(discoveryEndpointUri); try (CloseableHttpResponse response = httpClient.execute(request)) { String bodyAsString = HttpClientUtil.extractResponseBodyAsString(response); int statusCode = response.getStatusLine().getStatusCode(); return handleResponse(bodyAsString, statusCode, discoveryEndpointUri); } catch (IOException e) { throw OAuth2ServiceException.builder("Error retrieving configured oidc endpoints: " + e.getMessage()) .withUri(discoveryEndpointUri) .build(); } }
DefaultOidcConfigurationService implements OidcConfigurationService { @Override public OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(discoveryEndpointUri, "discoveryEndpointUri must not be null!"); HttpUriRequest request = new HttpGet(discoveryEndpointUri); try (CloseableHttpResponse response = httpClient.execute(request)) { String bodyAsString = HttpClientUtil.extractResponseBodyAsString(response); int statusCode = response.getStatusLine().getStatusCode(); return handleResponse(bodyAsString, statusCode, discoveryEndpointUri); } catch (IOException e) { throw OAuth2ServiceException.builder("Error retrieving configured oidc endpoints: " + e.getMessage()) .withUri(discoveryEndpointUri) .build(); } } }
DefaultOidcConfigurationService implements OidcConfigurationService { @Override public OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(discoveryEndpointUri, "discoveryEndpointUri must not be null!"); HttpUriRequest request = new HttpGet(discoveryEndpointUri); try (CloseableHttpResponse response = httpClient.execute(request)) { String bodyAsString = HttpClientUtil.extractResponseBodyAsString(response); int statusCode = response.getStatusLine().getStatusCode(); return handleResponse(bodyAsString, statusCode, discoveryEndpointUri); } catch (IOException e) { throw OAuth2ServiceException.builder("Error retrieving configured oidc endpoints: " + e.getMessage()) .withUri(discoveryEndpointUri) .build(); } } DefaultOidcConfigurationService();  DefaultOidcConfigurationService(CloseableHttpClient httpClient); }
DefaultOidcConfigurationService implements OidcConfigurationService { @Override public OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(discoveryEndpointUri, "discoveryEndpointUri must not be null!"); HttpUriRequest request = new HttpGet(discoveryEndpointUri); try (CloseableHttpResponse response = httpClient.execute(request)) { String bodyAsString = HttpClientUtil.extractResponseBodyAsString(response); int statusCode = response.getStatusLine().getStatusCode(); return handleResponse(bodyAsString, statusCode, discoveryEndpointUri); } catch (IOException e) { throw OAuth2ServiceException.builder("Error retrieving configured oidc endpoints: " + e.getMessage()) .withUri(discoveryEndpointUri) .build(); } } DefaultOidcConfigurationService();  DefaultOidcConfigurationService(CloseableHttpClient httpClient); static URI getDiscoveryEndpointUri(@Nonnull String issuerUri); @Override OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri); }
DefaultOidcConfigurationService implements OidcConfigurationService { @Override public OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(discoveryEndpointUri, "discoveryEndpointUri must not be null!"); HttpUriRequest request = new HttpGet(discoveryEndpointUri); try (CloseableHttpResponse response = httpClient.execute(request)) { String bodyAsString = HttpClientUtil.extractResponseBodyAsString(response); int statusCode = response.getStatusLine().getStatusCode(); return handleResponse(bodyAsString, statusCode, discoveryEndpointUri); } catch (IOException e) { throw OAuth2ServiceException.builder("Error retrieving configured oidc endpoints: " + e.getMessage()) .withUri(discoveryEndpointUri) .build(); } } DefaultOidcConfigurationService();  DefaultOidcConfigurationService(CloseableHttpClient httpClient); static URI getDiscoveryEndpointUri(@Nonnull String issuerUri); @Override OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri);  }