Index: login-tool/tool/src/java/org/sakaiproject/login/springframework/SakaiHomeContextLoaderListener.java =================================================================== --- login-tool/tool/src/java/org/sakaiproject/login/springframework/SakaiHomeContextLoaderListener.java (revision 0) +++ login-tool/tool/src/java/org/sakaiproject/login/springframework/SakaiHomeContextLoaderListener.java (revision 119345) @@ -0,0 +1,22 @@ +package org.sakaiproject.login.springframework; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.sakaiproject.util.ContextLoaderListener; + +/** + * Created with IntelliJ IDEA. + * User: jbush + * Date: 1/29/13 + * Time: 11:56 AM + * To change this template use File | Settings | File Templates. + */ +public class SakaiHomeContextLoaderListener extends ContextLoaderListener { + private static final Log log = LogFactory.getLog(SakaiHomeContextLoaderListener.class); + + protected org.springframework.web.context.ContextLoader createContextLoader() + { + return new SakaiHomeContextLoader(); + } + +} Property changes on: login-tool/tool/src/java/org/sakaiproject/login/springframework/SakaiHomeContextLoaderListener.java ___________________________________________________________________ Added: svn:keywords + Date Revision Author HeadURL Id Added: svn:eol-style + native Index: login-tool/tool/src/java/org/sakaiproject/login/springframework/SafeDelegatingFilterProxy.java =================================================================== --- login-tool/tool/src/java/org/sakaiproject/login/springframework/SafeDelegatingFilterProxy.java (revision 0) +++ login-tool/tool/src/java/org/sakaiproject/login/springframework/SafeDelegatingFilterProxy.java (revision 119345) @@ -0,0 +1,79 @@ +package org.sakaiproject.login.springframework; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.filter.DelegatingFilterProxy; + +import javax.servlet.*; +import java.io.IOException; + +/** + * Extends the ootb Spring proxy by becoming a no op in the situation where + * the targetBean can not be found in the context. The ootb behavior is to + * blow up the webapp. This allows us to drop in context files into the sakai.home + * directory. If they are found we can wire up some filters, if they aren't found + * we just go on safely about our business. + *

+ * Created with IntelliJ IDEA. + * User: jbush + * Date: 1/29/13 + * Time: 11:01 PM + * To change this template use File | Settings | File Templates. + */ +public class SafeDelegatingFilterProxy extends DelegatingFilterProxy { + private static Log log = LogFactory.getLog(SafeDelegatingFilterProxy.class); + + private final Object delegateMonitor = new Object(); + private boolean enabled = false; + + protected void initFilterBean() throws ServletException { + // If no target bean name specified, use filter name. + if (getTargetBeanName() == null) { + setTargetBeanName(getFilterName()); + } + + // make sure context is valid and bean exists before enabling this filter + synchronized (this.delegateMonitor) { + WebApplicationContext wac = findWebApplicationContext(); + if (validContext(wac)) { + super.initFilterBean(); + enabled = true; + } else { + log.info("can't find a valid Spring context or a bean with name: " + getTargetBeanName() + + " so no servlet filter proxying for you!"); + } + } + } + + private boolean validContext(WebApplicationContext wac) { + if (wac != null) { + try { + wac.getBean(getTargetBeanName(), Filter.class); + log.debug("setup checks out, enabling servlet filter proxing"); + return true; + } catch (Exception e) { + log.debug(e.getMessage(), e); + } + } + return false; + } + + public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + if (enabled) { + super.doFilter(request, response, filterChain); + return; + } + + filterChain.doFilter(request, response); + + } + + @Override + public void destroy() { + if (enabled) { + super.destroy(); + } + } +} Property changes on: login-tool/tool/src/java/org/sakaiproject/login/springframework/SafeDelegatingFilterProxy.java ___________________________________________________________________ Added: svn:keywords + Date Revision Author HeadURL Id Added: svn:eol-style + native Index: login-tool/tool/src/java/org/sakaiproject/login/springframework/SakaiHomeContextLoader.java =================================================================== --- login-tool/tool/src/java/org/sakaiproject/login/springframework/SakaiHomeContextLoader.java (revision 0) +++ login-tool/tool/src/java/org/sakaiproject/login/springframework/SakaiHomeContextLoader.java (revision 119345) @@ -0,0 +1,86 @@ +package org.sakaiproject.login.springframework; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.sakaiproject.component.cover.ServerConfigurationService; +import org.sakaiproject.component.impl.ContextLoader; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.io.FileSystemResource; +import org.springframework.util.StringUtils; +import org.springframework.web.context.ConfigurableWebApplicationContext; +import org.springframework.web.context.WebApplicationContext; + +import javax.servlet.ServletContext; +import java.io.File; + +/** + * Created with IntelliJ IDEA. + * User: jbush + * Date: 1/29/13 + * Time: 12:02 PM + * To change this template use File | Settings | File Templates. + */ +public class SakaiHomeContextLoader extends ContextLoader { + + /** + * Our logger. + */ + private static Log M_log = LogFactory.getLog(SakaiHomeContextLoader.class); + + /** + * Name of servlet context parameter that can specify the config location for loading into the shared component set. + * The path will be relative to the sakai.home directory. + */ + public static final String SAKAI_HOME_LOCATION_PARAM = "sakaiHomeContextLocation"; + + public static final String SAKAI_HOME_CONTEXT_SUFFIX = "-context.xml"; + + /** + * Initialize the local ApplicationContext, link it to the shared context, and load shared definitions into the shared context. + * + * @param servletContext current servlet context + * @return the new WebApplicationContext + * @throws org.springframework.beans.BeansException + * if the context couldn't be initialized + */ + public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws BeansException { + + WebApplicationContext rv = super.initWebApplicationContext(servletContext); + ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) rv; + + if (configurableApplicationContext != null) { + String sakaiHomeLocation = servletContext.getInitParameter(SAKAI_HOME_LOCATION_PARAM); + String servletContextName = rv.getServletContext().getServletContextName(); + if (sakaiHomeLocation == null || sakaiHomeLocation.length() == 0) { + sakaiHomeLocation = servletContextName + SAKAI_HOME_CONTEXT_SUFFIX; + } + if (sakaiHomeLocation != null) { + final String sakaiHomePath = ServerConfigurationService.getSakaiHomePath(); + + String[] locations = StringUtils.tokenizeToStringArray(sakaiHomeLocation, + ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS); + if (locations != null) { + + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory()); + + for (int i = 0; i < locations.length; i++) { + String resourcePath = sakaiHomePath + locations[i]; + M_log.debug(servletContextName + " is attempting to load Spring beans from: " + resourcePath); + if (new File(resourcePath).exists()) { + reader.loadBeanDefinitions(new FileSystemResource(resourcePath)); + } else { + M_log.info(servletContext + " startup is skipping introspection of the resource: " + resourcePath + + " because it does not exist."); + } + } + } + } + } + + return rv; + } + +} Property changes on: login-tool/tool/src/java/org/sakaiproject/login/springframework/SakaiHomeContextLoader.java ___________________________________________________________________ Added: svn:keywords + Date Revision Author HeadURL Id Added: svn:eol-style + native Index: login-tool/tool/src/webapp/WEB-INF/applicationContext.xml =================================================================== --- login-tool/tool/src/webapp/WEB-INF/applicationContext.xml (revision 0) +++ login-tool/tool/src/webapp/WEB-INF/applicationContext.xml (revision 119345) @@ -0,0 +1,6 @@ + + + + + Property changes on: login-tool/tool/src/webapp/WEB-INF/applicationContext.xml ___________________________________________________________________ Added: svn:eol-style + native Index: login-tool/tool/src/webapp/WEB-INF/web.xml =================================================================== --- login-tool/tool/src/webapp/WEB-INF/web.xml (revision 119344) +++ login-tool/tool/src/webapp/WEB-INF/web.xml (revision 119345) @@ -31,9 +31,22 @@ - + + Spring Delegated Filter + org.sakaiproject.login.springframework.SafeDelegatingFilterProxy + + targetBeanName + org.springframework.security.util.FilterChainProxy + + - + + Spring Delegated Filter + /container + REQUEST + FORWARD + INCLUDE + sakai.request @@ -83,13 +96,18 @@ /container/* - + + sakai.login + /* + org.sakaiproject.util.ToolListener - + + org.sakaiproject.login.springframework.SakaiHomeContextLoaderListener +