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);