/** * 注册单点登出listener * @return */ @Bean public ServletListenerRegistrationBean singleSignOutHttpSessionListener(){ ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(); bean.setListener(new SingleSignOutHttpSessionListener()); // bean.setName(""); //默认为bean name bean.setEnabled(true); //bean.setOrder(Ordered.HIGHEST_PRECEDENCE); //设置优先级 return bean; }
/** * 注册单点登出的listener * * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Bean public ServletListenerRegistrationBean<?> singleSignOutHttpSessionListener() { ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(); bean.setListener(new SingleSignOutHttpSessionListener()); bean.setEnabled(true); return bean; }
@Bean public ServletListenerRegistrationBean log4jServletContextListener() { final ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(); bean.setEnabled(true); bean.setName("log4jServletContextListener"); bean.setListener(new Log4jServletContextListener()); return bean; }
@Bean public ServletListenerRegistrationBean myListener(){ ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean(); servletListenerRegistrationBean.setListener(new MyListener()); servletListenerRegistrationBean.setName("myListener"); return servletListenerRegistrationBean; }
@Bean public ServletListenerRegistrationBean log4jServletContextListener() { ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(); bean.setEnabled(true); bean.setName("log4jServletContextListener"); bean.setListener(new Log4jServletContextListener()); return bean; }
/** * For single point logout */ @Bean public ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> singleSignOutHttpSessionListener() { ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> listener = new ServletListenerRegistrationBean<>(); listener.setEnabled(true); listener.setListener(new SingleSignOutHttpSessionListener()); listener.setOrder(1); return listener; }
private void registeredServletContextListenerBeanIsCalled(Class<?> configuration) { AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext( ServletListenerRegistrationBeanConfiguration.class, configuration); ServletContextListener servletContextListener = (ServletContextListener) context .getBean("registration", ServletListenerRegistrationBean.class) .getListener(); verify(servletContextListener).contextInitialized(any(ServletContextEvent.class)); context.close(); }
@Bean public ServletListenerRegistrationBean<BootstrapperContextListener> bootstrapperContextListener() { String listenerName = "bootstrapperContextListener"; ServletListenerRegistrationBean<BootstrapperContextListener> registrationBean = new ServletListenerRegistrationBean<BootstrapperContextListener>(); BootstrapperContextListener listener = new BootstrapperContextListener(); registrationBean.setListener(listener); registrationBean.setName(listenerName); return registrationBean; }
/** * Registers the JavaMelody {@link SessionListener}. * @param servletContext ServletContext * @return ServletListenerRegistrationBean */ @Bean public ServletListenerRegistrationBean<EventListener> monitoringSessionListener( ServletContext servletContext) { final ServletListenerRegistrationBean<EventListener> servletListenerRegistrationBean = new ServletListenerRegistrationBean<EventListener>( new SessionListener()); if (servletContext.getFilterRegistration("javamelody") != null) { // if webapp deployed as war in a container with MonitoringFilter and SessionListener already added by web-fragment.xml, // do not add again servletListenerRegistrationBean.setEnabled(false); } return servletListenerRegistrationBean; }
@Bean public ServletListenerRegistrationBean<HttpSessionListener> sessionListener() { return new ServletListenerRegistrationBean<HttpSessionListener>(new SessionListener()); }
@SuppressWarnings("unchecked") @Bean public static ServletListenerRegistrationBean httpSessionEventPublisher() { return new ServletListenerRegistrationBean(new HttpSessionEventPublisher()); }
@Bean public ServletListenerRegistrationBean<ServletContextListener> registration() { return new ServletListenerRegistrationBean<ServletContextListener>( mock(ServletContextListener.class)); }
@Bean ServletListenerRegistrationBean<KeycloakSessionDestroyListener> keycloakSessionDestroyListener() { return new ServletListenerRegistrationBean<>(new KeycloakSessionDestroyListener()); }
@Bean public ServletListenerRegistrationBean<JsfApplicationObjectConfigureListener> jsfConfigureListener() { return new ServletListenerRegistrationBean<>( new JsfApplicationObjectConfigureListener()); }
@Bean public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() { return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener()); }
/** * test. */ @SuppressWarnings("unchecked") @Test public void testJavaMelodyAutoConfigurationIsCreated() { // It should create a session listener. final ServletListenerRegistrationBean<EventListener> sessionListenerRegistrationBean = context .getBean(ServletListenerRegistrationBean.class); assertThat(sessionListenerRegistrationBean).isNotNull(); // It should create a registration bean named "javamelody-registration". final Object registrationBean = context .getBean(JavaMelodyAutoConfiguration.REGISTRATION_BEAN_NAME); assertThat(registrationBean).isNotNull(); assertThat(registrationBean).isInstanceOf(FilterRegistrationBean.class); // It should create a filter registration bean with the appropriately configured monitoring filter. final FilterRegistrationBean filterRegistrationBean = (FilterRegistrationBean) registrationBean; assertThat(filterRegistrationBean.getFilter()).isNotNull(); assertThat(filterRegistrationBean.getFilter()).isInstanceOf(MonitoringFilter.class); assertThat(filterRegistrationBean.getInitParameters()).containsEntry("log", "true"); assertThat(filterRegistrationBean.getInitParameters()).containsEntry("monitoring-path", "/test/path"); assertThat(filterRegistrationBean.getUrlPatterns()).containsExactly("/*"); // It should create the monitoring filter with the application type "Spring Boot". final MonitoringFilter monitoringFilter = (MonitoringFilter) filterRegistrationBean .getFilter(); assertThat(monitoringFilter.getApplicationType()).isEqualTo("Spring Boot"); // It should create an auto-proxy creator. final DefaultAdvisorAutoProxyCreator autoProxyCreator = context .getBean(DefaultAdvisorAutoProxyCreator.class); assertThat(autoProxyCreator).isNotNull(); // It should create a bean post-processor for data sources. final SpringDataSourceBeanPostProcessor dataSourcePostProcessor = context .getBean(SpringDataSourceBeanPostProcessor.class); assertThat(dataSourcePostProcessor).isNotNull(); // Cannot test excluded data sources since there is no public accessor for that. // It should create interceptors to monitor Spring services and controllers. final Map<String, MonitoringSpringAdvisor> springAdvisors = context .getBeansOfType(MonitoringSpringAdvisor.class); boolean monitoredWithAdvisorFound = false; int stereotypeAdvisorsCount = 0; for (final MonitoringSpringAdvisor springAdvisor : springAdvisors.values()) { if (springAdvisor.getPointcut() instanceof MonitoredWithAnnotationPointcut) { monitoredWithAdvisorFound = true; } else if (springAdvisor.getPointcut() instanceof AnnotationMatchingPointcut) { stereotypeAdvisorsCount++; // Maybe use synthetic @Service, @Controller and @RestController classes to check if point cuts match. } } assertThat(monitoredWithAdvisorFound).isTrue(); assertThat(stereotypeAdvisorsCount).isEqualTo(3); // It should create a bean post-processor for rest templates. final SpringRestTemplateBeanPostProcessor restTemplatePostProcessor = context .getBean(SpringRestTemplateBeanPostProcessor.class); assertThat(restTemplatePostProcessor).isNotNull(); }
@Bean public ServletListenerRegistrationBean requestContextListener() { return new ServletListenerRegistrationBean(new RequestContextListener()); }
@Bean ServletListenerRegistrationBean<SessionSupport> atmosphereSessionSupport() { return new ServletListenerRegistrationBean<SessionSupport>(new SessionSupport()); }
@Bean public ServletListenerRegistrationBean httpSessionEventPublisher() { return new ServletListenerRegistrationBean(new HttpSessionEventPublisher()); }
/** * Listener to redirect to login page after session timeout. Close the * vaadin session, because it's is not possible to redirect in * atmospehere. * * @return the servlet listener. */ @Bean public ServletListenerRegistrationBean<HttpSessionEventPublisher> httpSessionEventPublisher() { return new ServletListenerRegistrationBean<>(new HttpSessionEventPublisher()); }