Skip to content

Commit

Permalink
- Fix NPE exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Jul 9, 2024
1 parent 863d55a commit 23a046c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Response doInternalRedirect(
token = getAccessToken();
refreshToken = getRefreshAccessToken();
}
return buildCallbackResponse(token, refreshToken, provider);
return buildCallbackResponse(response, token, refreshToken, provider);
}

private KeycloakTokenDetails getDetails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,16 @@ public void autofill(OAuth2Configuration conf) {
s -> {
@SuppressWarnings("unchecked")
List<String> scopes = (List<String>) s;

// Get existing scopes from conf and split into a Set
Set<String> mergedScopes = new HashSet<>();
mergedScopes.addAll(Arrays.asList(conf.getScopes().split(",")));

// Add new scopes from the response to the set
mergedScopes.addAll(scopes);

// Update the configuration with the merged scopes
conf.setScopes(String.join(",", mergedScopes));
conf.setScopes(collectScopes(scopes));
});
}
}
}

private String collectScopes(List<String> scopes) {
return String.join(",", scopes);
}

protected String getUserinfoEndpointAttrName() {
return USERINFO_ENDPOINT_ATTR_NAME;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public Response doInternalRedirect(
HttpServletRequest request, HttpServletResponse response, String provider) {
String token = getAccessToken();
String refreshToken = getRefreshAccessToken();
return buildCallbackResponse(token, refreshToken, provider);
return buildCallbackResponse(response, token, refreshToken, provider);
}

protected Response.ResponseBuilder getCallbackResponseBuilder(
String token, String refreshToken, String provider) {
HttpServletResponse response, String token, String refreshToken, String provider) {
Response.ResponseBuilder result = new ResponseBuilderImpl();
IdPConfiguration configuration = configuration(provider);
LOGGER.info("Callback Provider: {}", provider);
Expand Down Expand Up @@ -84,7 +84,7 @@ protected Response.ResponseBuilder getCallbackResponseBuilder(
+ e.getMessage());
}
} else {
LOGGER.error("No access token found on callback request.");
LOGGER.error("No access token found on callback request: {}", response.getStatus());
result =
Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("No access token found.");
Expand All @@ -104,8 +104,10 @@ protected TokenStorage tokenStorage() {
return GeoStoreContext.bean(TokenStorage.class);
}

protected Response buildCallbackResponse(String token, String refreshToken, String provider) {
Response.ResponseBuilder result = getCallbackResponseBuilder(token, refreshToken, provider);
protected Response buildCallbackResponse(
HttpServletResponse response, String token, String refreshToken, String provider) {
Response.ResponseBuilder result =
getCallbackResponseBuilder(response, token, refreshToken, provider);
return result.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ public Response doInternalRedirect(
}
assert requestAttributes != null;
requestAttributes.setAttribute(PROVIDER_KEY, provider, 0);
return buildCallbackResponse(token, refreshToken, provider);
return buildCallbackResponse(response, token, refreshToken, provider);
}
}

0 comments on commit 23a046c

Please sign in to comment.