From 84359acf8bceb0161f5af9d73b717d73a81a43c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eva=20M=C3=BCller?= Date: Thu, 5 Dec 2024 16:32:42 +0100 Subject: [PATCH] Redirect to login page if refresh token has expired --- .../java/org/jenkinsci/plugins/oic/OicSecurityRealm.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java b/src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java index cce9b5c6..ca151330 100644 --- a/src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java +++ b/src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java @@ -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")))) { req.getSession().invalidate(); } - res.sendRedirect(Jenkins.get().getSecurityRealm().getLoginUrl()); + if (res != null) { + res.sendRedirect(Jenkins.get().getSecurityRealm().getLoginUrl()); + } } public boolean isExpired(OicCredentials credentials) { @@ -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);