private void initFilterPathFromWebXml(FilterConfig filterConfig) { String filterName = filterConfig.getFilterName(); FilterRegistration filterRegistration = filterConfig.getServletContext().getFilterRegistration(filterName); Collection<String> mappings = filterRegistration.getUrlPatternMappings(); int size = mappings.size(); if (size > 1) { throw new PippoRuntimeException( "Expected one filter path for '{}' but found multiple", filterName); } if (size == 1) { String urlPattern = mappings.iterator().next(); initFilterPath(urlPattern); } }
@Override protected void doAdditionalModuleStartLogic() throws Exception { if (StringUtils.isNotBlank(dispatchServletName)) { DispatcherServlet loaderServlet = new DispatcherServlet( (WebApplicationContext) ((SpringResourceLoader) rootResourceLoader.getResourceLoaders().get(0)) .getContext()); ServletRegistration registration = getServletContext().addServlet(dispatchServletName, loaderServlet); registration.addMapping("/" + dispatchServletName + "/*"); if (dispatchServletMappings != null) { dispatchServletMappings .stream() .map(mapping -> "/" + mapping + "/*") .forEach(registration::addMapping); } if (mapFilters) { for (String filterName : filtersToMap) { FilterRegistration filter = getServletContext().getFilterRegistration(filterName); filter.addMappingForServletNames(null, true, dispatchServletName); } } if (enableSpringSecurity) { DelegatingFilterProxy filterProxy = new DelegatingFilterProxy( SPRING_SECURITY_FILTER_CHAIN, (WebApplicationContext) ((SpringResourceLoader) rootResourceLoader.getResourceLoaders().get(0)) .getContext()); FilterRegistration.Dynamic securityFilter = getServletContext() .addFilter(KC_PREFIX + getModuleName() + SPRING_SECURITY_FILTER_PROXY, filterProxy); securityFilter.addMappingForServletNames(null, true, dispatchServletName); } } }