Skip to content

Commit

Permalink
Papi limit filter NPE when no Authorization header (#7122)
Browse files Browse the repository at this point in the history
* Fixes for papi limit filter and ML start

* Added the exception, fixed formatting

* Fixed the NPE when no authorization header in the request
  • Loading branch information
Camelia-Orcid authored Nov 5, 2024
1 parent 85cfb05 commit 856af1f
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,19 @@ protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServl
throws ServletException, IOException {
LOG.trace("ApiRateLimitFilter starts, rate limit is : " + enableRateLimiting);
if (enableRateLimiting) {
String tokenValue = httpServletRequest.getHeader("Authorization").replaceAll("Bearer|bearer", "").trim();

String tokenValue = null;
if (httpServletRequest.getHeader("Authorization") != null) {
tokenValue = httpServletRequest.getHeader("Authorization").replaceAll("Bearer|bearer", "").trim();
}
String ipAddress = httpServletRequest.getRemoteAddr();

String clientId = null;
try {
clientId = orcidTokenStore.readClientId(tokenValue);
} catch (Exception ex) {
LOG.error("Exception when trying to get the client id from token value, ignoring and treating as anonymous client", ex);
if (tokenValue != null) {
try {
clientId = orcidTokenStore.readClientId(tokenValue);
} catch (Exception ex) {
LOG.error("Exception when trying to get the client id from token value, ignoring and treating as anonymous client", ex);
}
}
boolean isAnonymous = (clientId == null);
LocalDate today = LocalDate.now();
Expand Down

0 comments on commit 856af1f

Please sign in to comment.