Skip to content

Use Keycloak's HttpClientProvider to jwks download#55

Open
finiasz wants to merge 1 commit into
Metatavu:developfrom
finiasz:28-corporate-proxy-support
Open

Use Keycloak's HttpClientProvider to jwks download#55
finiasz wants to merge 1 commit into
Metatavu:developfrom
finiasz:28-corporate-proxy-support

Conversation

@finiasz
Copy link
Copy Markdown
Contributor

@finiasz finiasz commented Dec 9, 2025

Use HttpClientProvider to get an HttpClient instead of creating a default one. These are taken from Keycloak's internal connection pool and natively support a proxy.

…ault one. These are taken from Keycloak's internal connection pool and natively support a proxy.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates from Java's default HttpClient to Keycloak's HttpClientProvider for downloading JWKS (JSON Web Key Set) data. This change enables the use of Keycloak's managed connection pool and native proxy support.

Key Changes:

  • Replaced java.net.http.HttpClient with Apache CloseableHttpClient obtained from Keycloak's HttpClientProvider
  • Updated method signatures to accept ScimContext parameter for accessing Keycloak's HTTP client pool
  • Migrated HTTP request/response handling from Java's HTTP client API to Apache HttpClient API

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
JwksUtils.java Refactored to use HttpClientProvider from Keycloak's session instead of creating a new HttpClient, and updated to use Apache HttpClient API for the HTTP request
ExternalTokenVerifier.java Updated verify() method to accept and pass ScimContext parameter to JwksUtils.getPublicKeysFromJwks()
AbstractScimServer.java Updated call to verifier.verify() to pass the scimContext parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @return list of public keys
*/
public static List<JwkKey> getPublicKeysFromJwks(String jwksUrl) throws URISyntaxException, IOException, InterruptedException {
public static List<JwkKey> getPublicKeysFromJwks(String jwksUrl, ScimContext scimContext) throws URISyntaxException, IOException, InterruptedException {
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method signature declares that it throws InterruptedException, but Apache HttpClient's execute() method does not throw InterruptedException. This was likely carried over from the previous java.net.http.HttpClient implementation. The InterruptedException should be removed from the throws clause as it's no longer applicable.

Suggested change
public static List<JwkKey> getPublicKeysFromJwks(String jwksUrl, ScimContext scimContext) throws URISyntaxException, IOException, InterruptedException {
public static List<JwkKey> getPublicKeysFromJwks(String jwksUrl, ScimContext scimContext) throws URISyntaxException, IOException {

Copilot uses AI. Check for mistakes.
*/
public boolean verify(String tokenString) throws URISyntaxException, IOException, InterruptedException, JWSInputException {
for (JwkKey jwkKey : JwksUtils.getPublicKeysFromJwks(jwksUrl)) {
public boolean verify(String tokenString, ScimContext scimContext) throws URISyntaxException, IOException, InterruptedException, JWSInputException {
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method signature declares that it throws InterruptedException, but this is no longer thrown by the underlying Apache HttpClient implementation. This should be removed from the throws clause to accurately reflect the method's behavior.

Suggested change
public boolean verify(String tokenString, ScimContext scimContext) throws URISyntaxException, IOException, InterruptedException, JWSInputException {
public boolean verify(String tokenString, ScimContext scimContext) throws URISyntaxException, IOException, JWSInputException {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants