Java Code Examples for javax.servlet.ServletContext#setSessionTrackingModes()
The following examples show how to use
javax.servlet.ServletContext#setSessionTrackingModes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebXmlCommon.java From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void initialize(ServletContext servletContext, boolean dev) throws ServletException { FacesInitializer facesInitializer = new FacesInitializer(); servletContext.setInitParameter("primefaces.FONT_AWESOME", "true"); servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true"); if (dev) { servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "0"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development"); } else { servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "-1"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Production"); } servletContext.setSessionTrackingModes(ImmutableSet.of(SessionTrackingMode.COOKIE)); Set<Class<?>> clazz = new HashSet<>(); clazz.add(WebXmlSpringBoot.class); facesInitializer.onStartup(clazz, servletContext); }
Example 2
Source File: WebXmlCommon.java From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void initialize(ServletContext servletContext, boolean dev) throws ServletException { FacesInitializer facesInitializer = new FacesInitializer(); servletContext.setInitParameter("primefaces.FONT_AWESOME", "true"); servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true"); if (dev) { servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "0"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development"); } else { servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "-1"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Production"); } servletContext.setSessionTrackingModes(ImmutableSet.of(SessionTrackingMode.COOKIE)); Set<Class<?>> clazz = new HashSet<>(); clazz.add(WebXmlSpringBoot.class); facesInitializer.onStartup(clazz, servletContext); }
Example 3
Source File: SeedServletContainerInitializer.java From seed with Mozilla Public License 2.0 | 6 votes |
@Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext) { WebConfig webConfig = Seed.baseConfiguration().get(WebConfig.class); servletContext.setSessionTrackingModes(webConfig.sessions().getTrackingModes()); copyConfig(webConfig.sessions().cookie(), servletContext.getSessionCookieConfig()); try { kernel = Seed.createKernel(servletContext, buildKernelConfiguration(servletContext), true); } catch (Exception e) { handleException(e); } servletContext.setAttribute(KERNEL_ATTRIBUTE_NAME, kernel); servletContext.setAttribute(INJECTOR_ATTRIBUTE_NAME, kernel.objectGraph().as(Injector.class)); servletContext.addListener(this); }
Example 4
Source File: SpringWebInitializer.java From Spring-5.0-Cookbook with MIT License | 5 votes |
private void addRootContext(ServletContext container) { // Create the application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringContextConfig.class); // Register application context with ContextLoaderListener container.addListener(new ContextLoaderListener(rootContext)); container.addListener(new AppSessionListener()); container.setInitParameter("contextConfigLocation", "org.packt.secured.mvc.core"); container.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); // if URL, enable sessionManagement URL rewriting }
Example 5
Source File: SpringWebinitializer.java From Spring-5.0-Cookbook with MIT License | 5 votes |
private void addRootContext(ServletContext container) { // Create the application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringContextConfig.class); // Register application context with ContextLoaderListener container.addListener(new ContextLoaderListener(rootContext)); container.setInitParameter("contextConfigLocation", "org.packt.web.reactor.security.config"); container.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); // if URL, enable sessionManagement URL rewriting }
Example 6
Source File: SpringWebinitializer.java From Spring-5.0-Cookbook with MIT License | 5 votes |
private void addRootContext(ServletContext container) { // Create the application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringContextConfig.class); // Register application context with ContextLoaderListener container.addListener(new ContextLoaderListener(rootContext)); container.addListener(new AppSessionListener()); container.setInitParameter("contextConfigLocation", "org.packt.secured.mvc.core"); container.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); // if URL, enable sessionManagement URL rewriting }
Example 7
Source File: AppLauncher.java From VulnerableJavaWebApplication with MIT License | 5 votes |
@SuppressWarnings("deprecation") @Bean public ServletContextInitializer servletContextInitializer() { return new ServletContextInitializer() { @Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE)); SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig(); sessionCookieConfig.setHttpOnly(true); } }; }
Example 8
Source File: CamundaBpmWebappInitializer.java From camunda-bpm-spring-boot-starter with Apache License 2.0 | 5 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { this.servletContext = servletContext; servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE)); servletContext.addListener(new CockpitContainerBootstrap()); servletContext.addListener(new AdminContainerBootstrap()); servletContext.addListener(new TasklistContainerBootstrap()); servletContext.addListener(new WelcomeContainerBootstrap()); servletContext.addListener(new HttpSessionMutexListener()); registerFilter("Authentication Filter", AuthenticationFilter.class, "/api/*", "/app/*"); registerFilter("Security Filter", LazySecurityFilter.class, singletonMap("configFile", properties.getWebapp().getSecurityConfigFile()), "/api/*", "/app/*"); registerFilter("CsrfPreventionFilter", SpringBootCsrfPreventionFilter.class, properties.getWebapp().getCsrf().getInitParams(),"/api/*", "/app/*"); Map<String, String> headerSecurityProperties = properties.getWebapp() .getHeaderSecurity() .getInitParams(); registerFilter("HttpHeaderSecurity", HttpHeaderSecurityFilter.class, headerSecurityProperties,"/api/*", "/app/*"); registerFilter("Engines Filter", LazyProcessEnginesFilter.class, "/api/*", "/app/*"); registerFilter("EmptyBodyFilter", EmptyBodyFilter.class, "/api/*", "/app/*"); registerFilter("CacheControlFilter", CacheControlFilter.class, "/api/*", "/app/*"); registerServlet("Cockpit Api", CockpitApplication.class, "/api/cockpit/*"); registerServlet("Admin Api", AdminApplication.class, "/api/admin/*"); registerServlet("Tasklist Api", TasklistApplication.class, "/api/tasklist/*"); registerServlet("Engine Api", EngineRestApplication.class, "/api/engine/*"); registerServlet("Welcome Api", WelcomeApplication.class, "/api/welcome/*"); }
Example 9
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void beforeStart(final StandardContext standardContext) { if (standardContext.getResources() != null && LazyStopStandardRoot.class.isInstance(standardContext.getResources())) { // reset after reload Reflections.set(standardContext, "resources", LazyStopStandardRoot.class.cast(standardContext.getResources()).getDelegate()); } final ServletContext sc = standardContext.getServletContext(); if (sc != null && !SystemInstance.get().getOptions().get(OPENEJB_JSESSION_ID_SUPPORT, true)) { final Set<SessionTrackingMode> defaultTrackingModes = sc.getEffectiveSessionTrackingModes(); if (defaultTrackingModes.contains(SessionTrackingMode.URL)) { final Set<SessionTrackingMode> newModes = new HashSet<>(); newModes.remove(SessionTrackingMode.URL); sc.setSessionTrackingModes(newModes); } } initContextLoader(standardContext); // used to add custom filters first - our arquillian integration uses it for instance // needs to be done now (= before start event) because of addFilterMapBefore() usage final String filters = SystemInstance.get().getProperty("org.apache.openejb.servlet.filters"); if (filters != null) { final String[] names = filters.split(","); for (final String name : names) { final String[] clazzMapping = name.split("="); final FilterDef filterDef = new FilterDef(); filterDef.setFilterClass(clazzMapping[0]); filterDef.setFilterName(clazzMapping[0]); standardContext.addFilterDef(filterDef); final FilterMap filterMap = new FilterMap(); filterMap.setFilterName(clazzMapping[0]); filterMap.addURLPattern(clazzMapping[1]); standardContext.addFilterMapBefore(filterMap); } } // mainly to get back compatibility with tomcat <= 8.0 final String cookieProcessor = SystemInstance.get().getProperty("tomee.tomcat.cookieProcessor"); if (cookieProcessor != null) { // not that important for now if we use the container loader, we mainly want to be able to access // the legacy one final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { final Class<?> cookieProcessorClass = contextClassLoader.loadClass(cookieProcessor.trim()); standardContext.setCookieProcessor(CookieProcessor.class.cast(cookieProcessorClass.newInstance())); } catch (final Exception e) { throw new IllegalArgumentException("Cannot set CookieProcessor: " + cookieProcessor); } } }
Example 10
Source File: ViewHelper.java From fess with Apache License 2.0 | 4 votes |
@PostConstruct public void init() { if (logger.isDebugEnabled()) { logger.debug("Initialize {}", this.getClass().getSimpleName()); } final FessConfig fessConfig = ComponentUtil.getFessConfig(); escapedHighlightPre = LaFunctions.h(originalHighlightTagPre); escapedHighlightPost = LaFunctions.h(originalHighlightTagPost); highlightTagPre = fessConfig.getQueryHighlightTagPre(); highlightTagPost = fessConfig.getQueryHighlightTagPost(); highlightedFields = fessConfig.getQueryHighlightContentDescriptionFieldsAsArray(); for (final int v : fessConfig.getQueryHighlightTerminalCharsAsArray()) { highlightTerminalCharSet.add(v); } try { final ServletContext servletContext = ComponentUtil.getComponent(ServletContext.class); servletContext.setSessionTrackingModes(fessConfig.getSessionTrackingModesAsSet().stream().map(SessionTrackingMode::valueOf) .collect(Collectors.toSet())); } catch (final Throwable t) { logger.warn("Failed to set SessionTrackingMode.", t); } split(fessConfig.getQueryFacetQueries(), "\n").of(stream -> stream.map(String::trim).filter(StringUtil::isNotEmpty).forEach(s -> { final String[] values = StringUtils.split(s, ":", 2); if (values.length != 2) { return; } final FacetQueryView facetQueryView = new FacetQueryView(); facetQueryView.setTitle(values[0]); split(values[1], "\t").of(subStream -> subStream.map(String::trim).filter(StringUtil::isNotEmpty).forEach(v -> { final String[] facet = StringUtils.split(v, "=", 2); if (facet.length == 2) { facetQueryView.addQuery(facet[0], facet[1]); } })); facetQueryView.init(); facetQueryViewList.add(facetQueryView); if (logger.isDebugEnabled()) { logger.debug("loaded {}", facetQueryView); } })); facetCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(facetCacheDuration, TimeUnit.SECONDS).build(); }
Example 11
Source File: CamundaBpmWebappInitializer.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Override public void onStartup(ServletContext servletContext) { this.servletContext = servletContext; servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE)); servletContext.addListener(new CockpitContainerBootstrap()); servletContext.addListener(new AdminContainerBootstrap()); servletContext.addListener(new TasklistContainerBootstrap()); servletContext.addListener(new WelcomeContainerBootstrap()); servletContext.addListener(new HttpSessionMutexListener()); WebappProperty webapp = properties.getWebapp(); String applicationPath = webapp.getApplicationPath(); ServletContextUtil.setAppPath(applicationPath, servletContext); registerFilter("Authentication Filter", AuthenticationFilter.class, applicationPath + "/api/*", applicationPath + "/app/*"); registerFilter("Security Filter", LazySecurityFilter.class, singletonMap("configFile", webapp.getSecurityConfigFile()), applicationPath + "/api/*", applicationPath + "/app/*"); registerFilter("CsrfPreventionFilter", CsrfPreventionFilter.class, webapp.getCsrf().getInitParams(), applicationPath + "/api/*", applicationPath + "/app/*"); Map<String, String> headerSecurityProperties = webapp .getHeaderSecurity() .getInitParams(); registerFilter("HttpHeaderSecurity", HttpHeaderSecurityFilter.class, headerSecurityProperties, applicationPath + "/api/*", applicationPath + "/app/*"); registerFilter("Engines Filter", LazyProcessEnginesFilter.class, applicationPath + "/api/*", applicationPath + "/app/*"); registerFilter("EmptyBodyFilter", EmptyBodyFilter.class, applicationPath + "/api/*", applicationPath + "/app/*"); registerFilter("CacheControlFilter", CacheControlFilter.class, applicationPath + "/api/*", applicationPath + "/app/*"); registerServlet("Cockpit Api", CockpitApplication.class, applicationPath + "/api/cockpit/*"); registerServlet("Admin Api", AdminApplication.class, applicationPath + "/api/admin/*"); registerServlet("Tasklist Api", TasklistApplication.class, applicationPath + "/api/tasklist/*"); registerServlet("Engine Api", EngineRestApplication.class, applicationPath + "/api/engine/*"); registerServlet("Welcome Api", WelcomeApplication.class, applicationPath + "/api/welcome/*"); }