private void registerEventListeners(Environment environment) throws ComponentLookupException { // Registering revent listeners implementations against the environment Map<String, EventListener> eventListeners = componentManager.getInstanceMap(EventListener.class); for (Map.Entry<String, EventListener> listener : eventListeners.entrySet()) { environment.servlets().addServletListeners(listener.getValue()); } }
private void initializeShiro(final ShiroConfiguration config, Environment environment) { if (config.isEnabled()) { LOG.debug("Shiro is enabled"); if (config.isDropwizardSessionHandler() && environment.getApplicationContext().getSessionHandler() == null) { LOG.debug("Adding DropWizard SessionHandler to environment."); environment.getApplicationContext().setSessionHandler(new SessionHandler()); } // This line ensure Shiro is configured and its .ini file found in the designated location. // e.g., via the shiroConfigLocations ContextParameter with fall-backs to default locations if that parameter isn't specified. environment.servlets().addServletListeners( new EnvironmentLoaderListener() ); final String filterUrlPattern = config.getSecuredUrlPattern(); LOG.debug("ShiroFilter will check URLs matching '{}'.", filterUrlPattern); environment.servlets().addFilter("shiro-filter", new ShiroFilter()).addMappingForUrlPatterns( EnumSet.allOf(DispatcherType.class), true, filterUrlPattern ); } else { LOG.debug("Shiro is not enabled"); } }
/** * Load filter, servlets or listeners for WebApplicationContext. */ private void loadWebConfigs(Environment environment, SpringConfiguration config, ApplicationContext appCtx) throws ClassNotFoundException { // Load filters. loadFilters(config.getFilters(), environment); // Load servlet listener. environment.servlets().addServletListeners(new RestContextLoaderListener((XmlRestWebApplicationContext) appCtx)); // Load servlets. loadServlets(config.getServlets(), environment); }
@Override public void run(T configuration, Environment environment) throws Exception { // disable annotation scanning environment.servlets().setInitParameter(CONFIG_BASE_PACKAGES, "none"); // set the config attribute environment.getApplicationContext().setAttribute(REWRITE_CONFIG_KEY, narrow(configuration)); environment.servlets().addServletListeners(new RewriteServletRequestListener(), new RewriteServletContextListener()); // load the filter environment.servlets().addFilter("rewrite", RewriteFilter.class) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); } }
/** * Sets up Shiro on the servlet context lifecycle, and establishes a URL pattern to protect. * * @param config The Shiro configuration. * @param environment The DropWizard environment. */ private void initializeShiro(ShiroConfiguration config, Environment environment) { if (config.isEnabled()) { if (config.isDropwizardSessionHandler()) { environment.servlets().setSessionHandler(new SessionHandler()); } environment.servlets().addServletListeners(new EnvironmentLoaderListener()); String filterUrlPattern = config.getSecuredUrlPattern(); environment.servlets() .addFilter("shiro-filter", new ShiroFilter()) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, filterUrlPattern); } } }
@Override public void run(AlertDropWizardConfiguration configuration, Environment environment) throws Exception { if (StringUtils.isNotEmpty(configuration.getApplicationConfPath())) { // setup config if given System.setProperty("config.resource", configuration.getApplicationConfPath()); ConfigFactory.invalidateCaches(); ConfigFactory.load(); } environment.getApplicationContext().setContextPath("/rest"); environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); environment.jersey().register(MetadataResource.class); environment.jersey().register(CoordinatorResource.class); // swagger resources environment.jersey().register(new ApiListingResource()); BeanConfig swaggerConfig = new BeanConfig(); swaggerConfig.setTitle("Alert engine service: metadata and coordinator"); swaggerConfig.setVersion("v1.2"); swaggerConfig.setBasePath("/rest"); swaggerConfig .setResourcePackage("org.apache.eagle.alert.coordinator.resource,org.apache.eagle.service.metadata.resource"); swaggerConfig.setScan(true); // simple CORS filter environment.servlets().addFilter("corsFilter", new SimpleCORSFiler()) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); // context listener environment.servlets().addServletListeners(new CoordinatorListener()); }
@Override public void run(T configuration, Environment environment) { ShiroConfiguration shiroConfig = narrow(configuration); if (shiroConfig == null) { shiroConfig = new ShiroConfiguration(); } ResourceConfig resourceConfig = environment.jersey().getResourceConfig(); resourceConfig.register(StormpathShiroFeature.class); // This listener will configure Shiro and Stormpath environment.servlets().addServletListeners(new StormpathShiroEnvironmentLoaderListener()); environment.servlets() .addServlet("default", DefaultServlet.class) .addMapping("/"); // The Stormpath API requires the 'default' servlet environment.servlets() .addFilter("ShiroFilter", ShiroFilter.class) // setup the Shiro Filter .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, shiroConfig.filterUrlPattern()); }
environment.servlets().addServletListeners(new SundialInitializerListener());