Skip to content

Commit

Permalink
Merge pull request #1716 from ManuelB/jenkins-1.614-branch-JJI-188
Browse files Browse the repository at this point in the history
 [JENKINS-28553] Stable workaround for adding PluginServletFilter
  • Loading branch information
daniel-beck committed Jul 1, 2015
2 parents a5f704c + 79f99e1 commit 76c1e77
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/src/main/java/hudson/util/PluginServletFilter.java
Expand Up @@ -27,6 +27,7 @@
import hudson.security.SecurityRealm;
import jenkins.model.Jenkins;

import javax.annotation.CheckForNull;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
Expand Down Expand Up @@ -71,8 +72,11 @@ public class PluginServletFilter implements Filter, ExtensionPoint {

/**
* Lookup the instance from servlet context.
*
* @param c the ServletContext most of the time taken from a Jenkins instance
* @return get the current PluginServletFilter if it is already available
*/
private static PluginServletFilter getInstance(ServletContext c) {
private static @CheckForNull PluginServletFilter getInstance(ServletContext c) {
return (PluginServletFilter)c.getAttribute(KEY);
}

Expand All @@ -90,20 +94,25 @@ public void init(FilterConfig config) throws ServletException {

public static void addFilter(Filter filter) throws ServletException {
Jenkins j = Jenkins.getInstance();
if (j==null) {

PluginServletFilter container = null;
if(j != null) {
container = getInstance(j.servletContext);
}
// https://marvelution.atlassian.net/browse/JJI-188
if (j==null || container == null) {
// report who is doing legacy registration
LOGGER.log(Level.WARNING, "Filter instance is registered too early: "+filter, new Exception());
LEGACY.add(filter);
} else {
PluginServletFilter container = getInstance(j.servletContext);
filter.init(container.config);
container.list.add(filter);
}
}

public static void removeFilter(Filter filter) throws ServletException {
Jenkins j = Jenkins.getInstance();
if (j==null) {
if (j==null || getInstance(j.servletContext) == null) {
LEGACY.remove(filter);
} else {
getInstance(j.servletContext).list.remove(filter);
Expand Down

0 comments on commit 76c1e77

Please sign in to comment.