use of org.motechproject.security.filter.MotechDelegatingFilterProxy in project motech by motech.
the class Activator method serviceAdded.
/**
* Initializes the security chain by fetching the proxy manager,
* registers the security filter and spring dispatcher servlet.
*/
private void serviceAdded(ExtHttpService service) {
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setContextConfigLocation(CONTEXT_CONFIG_LOCATION);
dispatcherServlet.setContextClass(WebSecurityApplicationContext.class);
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
HttpContext httpContext = HttpContextFactory.getHttpContext(service.createDefaultHttpContext(), bundleContext.getBundle());
service.registerServlet(SERVLET_URL_MAPPING, dispatcherServlet, null, null);
service.registerResources(RESOURCE_URL_MAPPING, "/webapp", httpContext);
LOGGER.debug("Servlet registered");
filter = new MotechDelegatingFilterProxy("springSecurityFilterChain", dispatcherServlet.getWebApplicationContext());
MotechProxyManager proxyManager = dispatcherServlet.getWebApplicationContext().getBean(MotechProxyManager.class);
LOGGER.debug("Creating initial proxy chain");
proxyManager.initializeProxyChain();
service.registerFilter(filter, "/.*", null, 0, httpContext);
LOGGER.debug("Filter registered");
} catch (NamespaceException e) {
throw new ServletRegistrationException("Web-security servlet already registered", e);
} catch (ServletException e) {
throw new ServletRegistrationException("Unable to register servlet for web-security", e);
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
Aggregations