public String getClassName() { return delegate.getClassName(); }
private boolean singleWarDeployment(ServletContext sc) { List<? extends FilterRegistration> monitoringFilters = sc.getFilterRegistrations().values() .stream() .filter(fr -> MonitoringFilter.class.getName().equals(fr.getClassName())) .collect(Collectors.toList()); return monitoringFilters.size() > 1; } }
/** * Detects if given {@link Filter} class has been already registered. * * @param filterClass {@link Filter} implementation class * @param context to search for registration * @return true if given {@link Filter} class has been already registered. */ protected boolean hasFilterMapping(Class<? extends Filter> filterClass, ServletContext context) { Collection<? extends FilterRegistration> filterRegistrations = context.getFilterRegistrations().values(); for (FilterRegistration filterRegistration : filterRegistrations) { if (filterClass.getName().equals(filterRegistration.getClassName())) { return true; } } return false; }
/** * <p> * Detects if the {@link HtmlParserFilter} is installed. In that case, the servlet {@link ServletRegistration registrations} * will be scanned to find which ones serves the resources filtered by the filter. This servlet will be wrapped in * a servlet with the 'async-supported' flag turned to on. In that case, the filter will be able to create asynchronous * tasks since all chained components will support it. * </p> * * @param servletContext the servlet context */ private void detectFilter(final ServletContext servletContext) { FilterRegistration filterRegistration = null; for (final FilterRegistration registration : servletContext.getFilterRegistrations().values()) { if (registration.getClassName().equals(HtmlParserFilter.class.getName())) { filterRegistration = registration; break; } } if (filterRegistration != null) { setAsyncSupported(servletContext, filterRegistration); } }
private Map<String, Object> buildFilterList() { Map<String, Object> filterMap = new HashMap<>(); for (Map.Entry<String, ? extends FilterRegistration> filterRegistrationEntry : servletContext .getFilterRegistrations().entrySet()) { FilterRegistration filterRegistration = filterRegistrationEntry.getValue(); Map<String, Object> filterRegistrationInfo = new HashMap<>(); filterRegistrationInfo.put("class", filterRegistration.getClassName()); filterRegistrationInfo.put("parameters", filterRegistration.getInitParameters()); Collection<String> mappings = filterRegistration.getServletNameMappings(); if (mappings == null) { mappings = new ArrayList<>(); } filterRegistrationInfo.put("servletNameMappings", Sets.newLinkedHashSet(mappings)); Collection<String> patterns = filterRegistration.getUrlPatternMappings(); if (patterns == null) { patterns = new ArrayList<>(); } filterRegistrationInfo.put("urlPatternMappings", Sets.newLinkedHashSet(patterns)); filterMap.put(filterRegistrationEntry.getKey(), filterRegistrationInfo); } return filterMap; }
private Map<String, Object> buildFilterList() { Map<String, Object> filterMap = new HashMap<String, Object>(); for (Map.Entry<String, ? extends FilterRegistration> filterRegistrationEntry : servletContext.getFilterRegistrations().entrySet()) { FilterRegistration filterRegistration = filterRegistrationEntry.getValue(); Map<String, Object> filterRegistrationInfo = new HashMap<String, Object>(); filterRegistrationInfo.put("class", filterRegistration.getClassName()); filterRegistrationInfo.put("parameters", filterRegistration.getInitParameters()); Collection<String> mappings = filterRegistration.getServletNameMappings(); if (mappings == null) { mappings = new ArrayList<String>(); } filterRegistrationInfo.put("servlet-name-mappings", Lists.newArrayList(mappings)); Collection<String> patterns = filterRegistration.getUrlPatternMappings(); if (patterns == null) { patterns = new ArrayList<String>(); } filterRegistrationInfo.put("url-pattern-mappings", Lists.newArrayList(patterns)); filterMap.put(filterRegistrationEntry.getKey(), filterRegistrationInfo); } return filterMap; } }
@Override public void onStartup(final Set<Class<?>> classes, final ServletContext ctx) throws ServletException { if (ctx.getFilterRegistrations().entrySet().stream() .anyMatch(r -> TribestreamSecurityFilter.class.getName().equals(r.getValue().getClassName()))) { return; // already registered probably with a custom mapping or a right ordering so let's not mess up the app } final TribestreamSecurityFilter securityFilter = new TribestreamSecurityFilter() {{ setIdGenerator(idGenerator); setEnforcerService(enforcerService); }}; final FilterRegistration.Dynamic filter = ctx.addFilter("tribestream-security-filter", securityFilter); filter.setAsyncSupported(true); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); }
@RequestMapping("/servlet/filters") public String showFilters( Model model ) { Map<String, ? extends FilterRegistration> filters = servletContext.getFilterRegistrations(); Table table = new Table( "Registered servlet filters" ); for ( Map.Entry<String, ? extends FilterRegistration> entry : filters.entrySet() ) { FilterRegistration filter = entry.getValue(); table.addRow( entry.getKey(), filter.getClassName() ); } model.addAttribute( "filtersTable", table ); Table filterMapsTable = new Table( "Order of registered servlet filters" ); List<String> filterMaps = getFilterMaps(); if ( filterMaps != null ) { model.addAttribute( "filterMaps", filterMapsTable ); int index = 0; for ( String filterMap : filterMaps ) { filterMapsTable.addRow( index++, filterMap ); } } return DebugWeb.VIEW_SERVLET_FILTERS; }
log.info("Collecting servlet mapping do detect which ones are filtered by {}", filterRegistration.getClassName()); final PathMap<ServletRegistration> pathMap = new PathMap<ServletRegistration>(); log.warn("ServletRegistration {} should be an instance of Dynamic.", registration.getClassName()); log.warn("If {} has the async-supported flag turned on, make sure the targeted servlet is in the same state.", filterRegistration.getClassName());
aRow.addCell (aRegistration.getClassName ());
aRow.addCell (aRegistration.getClassName ());
aRow.addCell (aRegistration.getClassName ());