Skip to content

Commit

Permalink
Merge pull request #475 from eva-mueller-coremedia/fix-redirect-refre…
Browse files Browse the repository at this point in the history
…sh-token-has-expired

Redirect to login page if refresh token has expired
  • Loading branch information
michael-doubez authored Dec 9, 2024
2 parents 81d9392 + 84359ac commit 6e62f67
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1376,10 +1376,12 @@ public boolean handleTokenExpiration(HttpServletRequest httpRequest, HttpServlet
}

private void redirectToLoginUrl(HttpServletRequest req, HttpServletResponse res) throws IOException {
if (req.getSession(false) != null || Strings.isNullOrEmpty(req.getHeader("Authorization"))) {
if (req != null && (req.getSession(false) != null || Strings.isNullOrEmpty(req.getHeader("Authorization")))) {

Check warning on line 1379 in src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1379 is only partially covered, 2 branches are missing
req.getSession().invalidate();
}
res.sendRedirect(Jenkins.get().getSecurityRealm().getLoginUrl());
if (res != null) {

Check warning on line 1382 in src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1382 is only partially covered, one branch is missing
res.sendRedirect(Jenkins.get().getSecurityRealm().getLoginUrl());
}
}

public boolean isExpired(OicCredentials credentials) {
Expand Down Expand Up @@ -1475,7 +1477,7 @@ private boolean refreshExpiredToken(
return false;
}
LOGGER.log(Level.FINE, "Failed to refresh expired token", e);
redirectToLoginUrl(Stapler.getCurrentRequest(), Stapler.getCurrentResponse());
redirectToLoginUrl(httpRequest, httpResponse);
return false;
}
LOGGER.log(Level.WARNING, "Failed to refresh expired token", e);
Expand Down

0 comments on commit 6e62f67

Please sign in to comment.