diff --git a/core/src/main/java/hudson/security/HudsonFilter.java b/core/src/main/java/hudson/security/HudsonFilter.java new file mode 100644 index 0000000000..77c414b47c --- /dev/null +++ b/core/src/main/java/hudson/security/HudsonFilter.java @@ -0,0 +1,69 @@ +package hudson.security; + +import hudson.model.Hudson; +import hudson.util.spring.BeanBuilder; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import java.io.IOException; + +/** + * {@link Filter} that Hudson uses to implement security support. + * + *

+ * This is the instance the servlet container creates, but + * internally this is just a dispatcher that delegates the request + * to the appropriate filter pipeline based on the current + * configuration. + * + * @author Kohsuke Kawaguchi + */ +public class HudsonFilter implements Filter { + /** + * To be used with {@link SecurityMode#LEGACY}. + */ + private Filter legacy; + /** + * To be used with {@link SecurityMode#SECURED}. + */ + private Filter acegi; + + public void init(FilterConfig filterConfig) throws ServletException { + legacy = new BasicAuthenticationFilter(); + legacy.init(filterConfig); + + BeanBuilder builder = new BeanBuilder(); + builder.parse(getClass().getResourceAsStream("Filters.groovy")); + acegi = (Filter) builder.createApplicationContext().getBean("filter"); + acegi.init(filterConfig); + } + + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + Hudson h = Hudson.getInstance(); + if(h==null) { + // Hudson is starting up. + chain.doFilter(request,response); + return; + } + switch (h.getSecurity()) { + case LEGACY: + legacy.doFilter(request,response,chain); + break; + case SECURED: + acegi.doFilter(request,response,chain); + break; + case UNSECURED: + chain.doFilter(request,response); + break; + } + } + + public void destroy() { + legacy.destroy(); + acegi.destroy(); + } +} diff --git a/core/src/main/java/hudson/security/SecurityMode.java b/core/src/main/java/hudson/security/SecurityMode.java index 2f3bdbc4c2..01a73c1ee8 100644 --- a/core/src/main/java/hudson/security/SecurityMode.java +++ b/core/src/main/java/hudson/security/SecurityMode.java @@ -16,6 +16,9 @@ public enum SecurityMode { * In this model, an user is either admin or not. An admin user * can do anything, and non-admin user can only browse. * Authentication is performed by the container. + *

+ * This is the only secured mode of Hudson up to 1.160. + * This is maintained only for backward compatibility. */ LEGACY, /** diff --git a/war/resources/WEB-INF/web.xml b/war/resources/WEB-INF/web.xml index 358c1b0040..85413a1b5c 100644 --- a/war/resources/WEB-INF/web.xml +++ b/war/resources/WEB-INF/web.xml @@ -28,7 +28,7 @@ authentication-filter - hudson.security.BasicAuthenticationFilter + hudson.security.HudsonFilter