1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.springframework.security.oauth.examples.sparklr.config;
15
16 import javax.servlet.ServletContext;
17 import javax.servlet.ServletException;
18
19 import org.springframework.util.ClassUtils;
20 import org.springframework.web.context.WebApplicationContext;
21 import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
22 import org.springframework.web.filter.DelegatingFilterProxy;
23 import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
24
25
26
27
28
29 public class ServletInitializer extends AbstractDispatcherServletInitializer {
30
31 @Override
32 protected WebApplicationContext createServletApplicationContext() {
33 AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
34 context.scan(ClassUtils.getPackageName(getClass()));
35 return context;
36 }
37
38 @Override
39 protected String[] getServletMappings() {
40 return new String[] { "/" };
41 }
42
43 @Override
44 protected WebApplicationContext createRootApplicationContext() {
45 return null;
46 }
47
48 @Override
49 public void onStartup(ServletContext servletContext) throws ServletException {
50 super.onStartup(servletContext);
51 DelegatingFilterProxy filter = new DelegatingFilterProxy("springSecurityFilterChain");
52 filter.setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher");
53 servletContext.addFilter("springSecurityFilterChain", filter).addMappingForUrlPatterns(null, false, "/*");
54 }
55
56 }