1
2
3
4
5
6
7
8
9
10
11 package psiprobe;
12
13 import com.opensymphony.sitemesh.webapp.SiteMeshFilter;
14
15 import jakarta.servlet.DispatcherType;
16 import jakarta.servlet.FilterRegistration;
17 import jakarta.servlet.ServletContext;
18 import jakarta.servlet.ServletException;
19 import jakarta.servlet.ServletRegistration;
20 import jakarta.servlet.SessionTrackingMode;
21
22 import java.util.EnumSet;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.springframework.web.WebApplicationInitializer;
27 import org.springframework.web.context.ContextLoaderListener;
28 import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
29 import org.springframework.web.filter.DelegatingFilterProxy;
30
31
32
33
34 public class ProbeInitializer implements WebApplicationInitializer {
35
36 @Override
37 public void onStartup(ServletContext servletContext) throws ServletException {
38
39
40 try (AnnotationConfigWebApplicationContext rootContext =
41 new AnnotationConfigWebApplicationContext()) {
42 rootContext.register(ProbeConfig.class);
43
44
45 servletContext.addListener(new ContextLoaderListener(rootContext));
46 }
47
48
49 ServletRegistration.Dynamic probe = servletContext.addServlet("probe", ProbeServlet.class);
50
51
52 servletContext.setInitParameter("attribute.value.roles", "ROLE_MANAGER,ROLE_MANAGER-GUI");
53
54
55 Map<String, String> initParameters = new HashMap<>();
56 initParameters.put("contextConfigLocation", "");
57 probe.setInitParameters(initParameters);
58
59
60 probe.setLoadOnStartup(0);
61
62
63 probe.addMapping("*.htm", "*.ajax", "/logs/*", "/chart.png");
64
65
66 FilterRegistration.Dynamic sitemesh =
67 servletContext.addFilter("sitemesh", SiteMeshFilter.class);
68 sitemesh.addMappingForUrlPatterns(
69 EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST, DispatcherType.ERROR), false,
70 "/*");
71
72
73 FilterRegistration.Dynamic security =
74 servletContext.addFilter("filterChainProxy", DelegatingFilterProxy.class);
75 security.addMappingForUrlPatterns(
76 EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST, DispatcherType.ERROR), false,
77 "/*");
78
79
80 servletContext.getSessionCookieConfig().setHttpOnly(true);
81 servletContext.getSessionCookieConfig().setSecure(true);
82
83
84 EnumSet<SessionTrackingMode> trackingMode = EnumSet.of(SessionTrackingMode.COOKIE);
85 servletContext.setSessionTrackingModes(trackingMode);
86 }
87
88 }