Search in sources :

Example 11 with FilterInfo

use of io.undertow.servlet.api.FilterInfo in project undertow by undertow-io.

the class FilterPathMappingTestCase method test_WFLY_1935.

@Test
public void test_WFLY_1935() throws IOException, ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    builder.addServlet(new ServletInfo("*.a", PathMappingServlet.class).addMapping("*.a"));
    builder.addFilter(new FilterInfo("/*", PathFilter.class));
    builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST);
    //non standard, but we still support it
    builder.addFilter(new FilterInfo("/SimpleServlet.a", PathFilter.class));
    builder.addFilterUrlMapping("/SimpleServlet.a", "/SimpleServlet.a", DispatcherType.REQUEST);
    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(FilterPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war");
    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "SimpleServlet.a", "*.a - /SimpleServlet.a - null", "/*", "/SimpleServlet.a");
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 12 with FilterInfo

use of io.undertow.servlet.api.FilterInfo in project undertow by undertow-io.

the class FilterPathMappingTestCase method testExtensionMatchServletWithGlobalFilter.

@Test
public void testExtensionMatchServletWithGlobalFilter() throws IOException, ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class).addMapping("*.jsp"));
    builder.addFilter(new FilterInfo("/*", PathFilter.class));
    builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST);
    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(FilterPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war");
    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "aa.jsp", "*.jsp - /aa.jsp - null", "/*");
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 13 with FilterInfo

use of io.undertow.servlet.api.FilterInfo in project undertow by undertow-io.

the class FilterPathMappingTestCase method testBasicFilterMappings.

@Test
public void testBasicFilterMappings() throws IOException, ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    builder.addServlet(new ServletInfo("/a/*", PathMappingServlet.class).addMapping("/a/*"));
    builder.addServlet(new ServletInfo("/aa", PathMappingServlet.class).addMapping("/aa"));
    builder.addServlet(new ServletInfo("/", PathMappingServlet.class).addMapping("/"));
    builder.addServlet(new ServletInfo("contextRoot", PathMappingServlet.class).addMapping(""));
    builder.addServlet(new ServletInfo("/myservlet/*", PathMappingServlet.class).addMapping("/myservlet/*"));
    builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class).addMapping("*.jsp"));
    builder.addServlet(new ServletInfo("/hello/*", PathMappingServlet.class).addMapping("/hello/*"));
    builder.addServlet(new ServletInfo("/test/*", PathMappingServlet.class).addMapping("/test/*"));
    builder.addFilter(new FilterInfo("/*", PathFilter.class));
    builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST);
    //non standard, but we still support it
    builder.addFilter(new FilterInfo("*", PathFilter.class));
    builder.addFilterUrlMapping("*", "*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/a/*", PathFilter.class));
    builder.addFilterUrlMapping("/a/*", "/a/*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/aa", PathFilter.class));
    builder.addFilterUrlMapping("/aa", "/aa", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("*.bop", PathFilter.class));
    builder.addFilterUrlMapping("*.bop", "*.bop", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/myservlet/myfilter/*", PathFilter.class));
    builder.addFilterUrlMapping("/myservlet/myfilter/*", "/myservlet/myfilter/*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/myfilter/*", PathFilter.class));
    builder.addFilterUrlMapping("/myfilter/*", "/myfilter/*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("contextRoot", PathFilter.class));
    builder.addFilterServletNameMapping("contextRoot", "contextRoot", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("defaultName", PathFilter.class));
    builder.addFilterServletNameMapping("defaultName", "/", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/helloworld/index.html", PathFilter.class));
    builder.addFilterUrlMapping("/helloworld/index.html", "/helloworld/index.html", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/test", PathFilter.class));
    builder.addFilterUrlMapping("/test", "/test", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("allByName", PathFilter.class));
    builder.addFilterServletNameMapping("allByName", "*", DispatcherType.REQUEST);
    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(FilterPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war");
    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "test", "/test/* - /test - null", "/*", "*", "/test", "allByName");
        runTest(client, "aa", "/aa - /aa - null", "/*", "*", "/aa", "allByName");
        runTest(client, "a/c", "/a/* - /a - /c", "/*", "*", "/a/*", "allByName");
        runTest(client, "a", "/a/* - /a - null", "/*", "*", "/a/*", "allByName");
        runTest(client, "aa/b", "/ - /aa/b - null", "/*", "*", "defaultName", "allByName");
        runTest(client, "a/b/c/d", "/a/* - /a - /b/c/d", "/*", "*", "/a/*", "allByName");
        runTest(client, "defaultStuff", "/ - /defaultStuff - null", "/*", "*", "defaultName", "allByName");
        runTest(client, "", "contextRoot - / - null", "/*", "*", "contextRoot", "allByName");
        runTest(client, "yyyy.bop", "/ - /yyyy.bop - null", "/*", "*", "*.bop", "defaultName", "allByName");
        runTest(client, "a/yyyy.bop", "/a/* - /a - /yyyy.bop", "/*", "*", "*.bop", "/a/*", "allByName");
        runTest(client, "myservlet/myfilter/file.dat", "/myservlet/* - /myservlet - /myfilter/file.dat", "/*", "*", "/myservlet/myfilter/*", "allByName");
        runTest(client, "myservlet/myfilter/file.jsp", "/myservlet/* - /myservlet - /myfilter/file.jsp", "/*", "*", "/myservlet/myfilter/*", "allByName");
        runTest(client, "otherservlet/myfilter/file.jsp", "*.jsp - /otherservlet/myfilter/file.jsp - null", "/*", "*", "allByName");
        runTest(client, "myfilter/file.jsp", "*.jsp - /myfilter/file.jsp - null", "/*", "*", "/myfilter/*", "allByName");
        runTest(client, "helloworld/index.html", "/ - /helloworld/index.html - null", "/*", "*", "/helloworld/index.html", "defaultName", "allByName");
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 14 with FilterInfo

use of io.undertow.servlet.api.FilterInfo in project indy by Commonjava.

the class DeploymentInfoUtils method merge.

public static void merge(final DeploymentInfo into, final DeploymentInfo from) {
    final Map<String, AuthenticationMechanismFactory> authMechs = from.getAuthenticationMechanisms();
    if (authMechs != null) {
        for (final Map.Entry<String, AuthenticationMechanismFactory> entry : authMechs.entrySet()) {
            into.addAuthenticationMechanism(entry.getKey(), entry.getValue());
        }
    }
    if (from.getAuthorizationManager() != null) {
        into.setAuthorizationManager(from.getAuthorizationManager());
    }
    if (from.getConfidentialPortManager() != null) {
        into.setConfidentialPortManager(from.getConfidentialPortManager());
    }
    final List<ErrorPage> errorPages = from.getErrorPages();
    if (errorPages != null) {
        into.addErrorPages(errorPages);
    }
    if (from.getExceptionHandler() != null) {
        into.setExceptionHandler(from.getExceptionHandler());
    }
    final List<FilterMappingInfo> filterMappings = from.getFilterMappings();
    if (filterMappings != null) {
        for (final FilterMappingInfo fmi : filterMappings) {
            switch(fmi.getMappingType()) {
                case SERVLET:
                    {
                        into.addFilterServletNameMapping(fmi.getFilterName(), fmi.getMapping(), fmi.getDispatcher());
                        break;
                    }
                default:
                    {
                        into.addFilterUrlMapping(fmi.getFilterName(), fmi.getMapping(), fmi.getDispatcher());
                    }
            }
        }
    }
    final Map<String, FilterInfo> filterInfos = from.getFilters();
    if (filterInfos != null) {
        into.addFilters(filterInfos.values());
    }
    if (from.getIdentityManager() != null) {
        into.setIdentityManager(from.getIdentityManager());
    }
    final Map<String, String> initParameters = from.getInitParameters();
    if (initParameters != null) {
        for (final Map.Entry<String, String> entry : initParameters.entrySet()) {
            logger.debug("Init-Param: {} = {} from: {}", entry.getKey(), entry.getValue(), from);
            into.addInitParameter(entry.getKey(), entry.getValue());
        }
    }
    final List<LifecycleInterceptor> lifecycleInterceptors = from.getLifecycleInterceptors();
    if (lifecycleInterceptors != null) {
        for (final LifecycleInterceptor lifecycleInterceptor : lifecycleInterceptors) {
            into.addLifecycleInterceptor(lifecycleInterceptor);
        }
    }
    final List<ListenerInfo> listeners = from.getListeners();
    if (listeners != null) {
        into.addListeners(listeners);
    }
    if (from.getMetricsCollector() != null) {
        into.setMetricsCollector(from.getMetricsCollector());
    }
    final List<MimeMapping> mimeMappings = from.getMimeMappings();
    if (mimeMappings != null) {
        into.addMimeMappings(mimeMappings);
    }
    final List<NotificationReceiver> notificationReceivers = from.getNotificationReceivers();
    if (notificationReceivers != null) {
        into.addNotificationReceivers(notificationReceivers);
    }
    final Map<String, Set<String>> principalVersusRolesMap = from.getPrincipalVersusRolesMap();
    if (principalVersusRolesMap != null) {
        for (final Map.Entry<String, Set<String>> entry : principalVersusRolesMap.entrySet()) {
            into.addPrincipalVsRoleMappings(entry.getKey(), entry.getValue());
        }
    }
    final List<SecurityConstraint> securityConstraints = from.getSecurityConstraints();
    if (securityConstraints != null) {
        if (logger.isDebugEnabled()) {
            for (final SecurityConstraint sc : securityConstraints) {
                logger.debug("Security Constraint: {} from: {}", sc, from);
            }
        }
        into.addSecurityConstraints(securityConstraints);
    }
    final LoginConfig loginConfig = from.getLoginConfig();
    if (loginConfig != null) {
        logger.debug("Login Config with realm: {} and mechanism: {} from: {}", loginConfig.getRealmName(), loginConfig.getAuthMethods(), from);
        if (into.getLoginConfig() != null) {
            throw new IllegalStateException("Two or more deployment providers are attempting to provide login configurations! Enable debug logging to see more.");
        }
        into.setLoginConfig(loginConfig);
    }
    if (from.getSecurityContextFactory() != null) {
        into.setSecurityContextFactory(from.getSecurityContextFactory());
    }
    final Set<String> securityRoles = from.getSecurityRoles();
    if (securityRoles != null) {
        into.addSecurityRoles(securityRoles);
    }
    final List<ServletContainerInitializerInfo> servletContainerInitializers = from.getServletContainerInitializers();
    if (servletContainerInitializers != null) {
        into.addServletContainerInitalizers(servletContainerInitializers);
    }
    final Map<String, Object> servletContextAttributes = from.getServletContextAttributes();
    if (servletContextAttributes != null) {
        for (final Map.Entry<String, Object> entry : servletContextAttributes.entrySet()) {
            into.addServletContextAttribute(entry.getKey(), entry.getValue());
        }
    }
    final List<ServletExtension> servletExtensions = from.getServletExtensions();
    if (servletExtensions != null) {
        for (final ServletExtension servletExtension : servletExtensions) {
            into.addServletExtension(servletExtension);
        }
    }
    final Map<String, ServletInfo> servletInfos = from.getServlets();
    if (servletInfos != null) {
        into.addServlets(servletInfos.values());
    }
    final List<SessionListener> sessionListeners = from.getSessionListeners();
    if (sessionListeners != null) {
        for (final SessionListener sessionListener : sessionListeners) {
            into.addSessionListener(sessionListener);
        }
    }
    if (from.getSessionManagerFactory() != null) {
        into.setSessionManagerFactory(from.getSessionManagerFactory());
    }
    if (from.getSessionPersistenceManager() != null) {
        into.setSessionPersistenceManager(from.getSessionPersistenceManager());
    }
    if (from.getTempDir() != null) {
        into.setTempDir(from.getTempDir());
    }
    final List<String> welcomePages = from.getWelcomePages();
    if (welcomePages != null) {
        into.addWelcomePages(welcomePages);
    }
    final List<HandlerWrapper> initWrappers = from.getInitialHandlerChainWrappers();
    if (initWrappers != null) {
        for (final HandlerWrapper wrapper : initWrappers) {
            into.addInitialHandlerChainWrapper(wrapper);
        }
    }
    final List<HandlerWrapper> outerWrappers = from.getOuterHandlerChainWrappers();
    if (outerWrappers != null) {
        for (final HandlerWrapper wrapper : outerWrappers) {
            into.addOuterHandlerChainWrapper(wrapper);
        }
    }
    final List<HandlerWrapper> innerWrappers = from.getInnerHandlerChainWrappers();
    if (innerWrappers != null) {
        for (final HandlerWrapper wrapper : innerWrappers) {
            into.addInnerHandlerChainWrapper(wrapper);
        }
    }
}
Also used : ErrorPage(io.undertow.servlet.api.ErrorPage) FilterMappingInfo(io.undertow.servlet.api.FilterMappingInfo) Set(java.util.Set) HandlerWrapper(io.undertow.server.HandlerWrapper) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) LifecycleInterceptor(io.undertow.servlet.api.LifecycleInterceptor) ServletInfo(io.undertow.servlet.api.ServletInfo) LoginConfig(io.undertow.servlet.api.LoginConfig) FilterInfo(io.undertow.servlet.api.FilterInfo) MimeMapping(io.undertow.servlet.api.MimeMapping) ServletContainerInitializerInfo(io.undertow.servlet.api.ServletContainerInitializerInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) NotificationReceiver(io.undertow.security.api.NotificationReceiver) SessionListener(io.undertow.server.session.SessionListener) AuthenticationMechanismFactory(io.undertow.security.api.AuthenticationMechanismFactory) Map(java.util.Map) ServletExtension(io.undertow.servlet.ServletExtension)

Example 15 with FilterInfo

use of io.undertow.servlet.api.FilterInfo in project indy by Commonjava.

the class IndyDeployment method getDeployment.

public DeploymentInfo getDeployment(final String contextRoot) {
    final ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplication(this);
    deployment.setInjectorFactoryClass(CdiInjectorFactoryImpl.class.getName());
    final ServletInfo resteasyServlet = Servlets.servlet("REST", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(1).addMapping("/api*").addMapping("/api/*").addMapping("/api-docs*").addMapping("/api-docs/*").addMapping("/swagger.json").addMapping("/swagger.yaml");
    final BeanConfig beanConfig = new BeanConfig();
    beanConfig.setResourcePackage("org.commonjava.indy");
    beanConfig.setBasePath("/");
    beanConfig.setLicense("ASLv2");
    beanConfig.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0");
    beanConfig.setScan(true);
    beanConfig.setVersion(versioning.getApiVersion());
    final FilterInfo resourceManagementFilter = Servlets.filter("Naming and Resource Management", ResourceManagementFilter.class, new ImmediateInstanceFactory<ResourceManagementFilter>(this.resourceManagementFilter));
    final DeploymentInfo di = new DeploymentInfo().addListener(Servlets.listener(RequestScopeListener.class)).setContextPath(contextRoot).addServletContextAttribute(ResteasyDeployment.class.getName(), deployment).addServlet(resteasyServlet).addFilter(resourceManagementFilter).addFilterUrlMapping(resourceManagementFilter.getName(), "/api/*", DispatcherType.REQUEST).setDeploymentName("Indy").setClassLoader(ClassLoader.getSystemClassLoader()).addOuterHandlerChainWrapper(new HeaderDebugger.Wrapper());
    if (deploymentProviders != null) {
        DeploymentInfoUtils.mergeFromProviders(di, deploymentProviders);
    }
    // Add UI servlet at the end so its mappings don't obscure any from add-ons.
    final ServletInfo uiServlet = Servlets.servlet("UI", UIServlet.class).setAsyncSupported(true).setLoadOnStartup(99).addMappings(UIServlet.PATHS);
    uiServlet.setInstanceFactory(new ImmediateInstanceFactory<Servlet>(ui));
    di.addServlet(uiServlet);
    return di;
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) ServletInfo(io.undertow.servlet.api.ServletInfo) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Servlet(javax.servlet.Servlet) UIServlet(org.commonjava.indy.bind.jaxrs.ui.UIServlet) RequestScopeListener(org.commonjava.indy.bind.jaxrs.util.RequestScopeListener) UIServlet(org.commonjava.indy.bind.jaxrs.ui.UIServlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) CdiInjectorFactoryImpl(org.commonjava.indy.bind.jaxrs.util.CdiInjectorFactoryImpl)

Aggregations

FilterInfo (io.undertow.servlet.api.FilterInfo)24 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)19 DeploymentManager (io.undertow.servlet.api.DeploymentManager)16 ServletContainer (io.undertow.servlet.api.ServletContainer)16 ServletInfo (io.undertow.servlet.api.ServletInfo)15 PathHandler (io.undertow.server.handlers.PathHandler)14 BeforeClass (org.junit.BeforeClass)6 Test (org.junit.Test)6 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)5 TestHttpClient (io.undertow.testutils.TestHttpClient)5 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)4 LoginConfig (io.undertow.servlet.api.LoginConfig)3 PerMessageDeflateHandshake (io.undertow.websockets.extensions.PerMessageDeflateHandshake)3 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)2 HandlerWrapper (io.undertow.server.HandlerWrapper)2 HttpHandler (io.undertow.server.HttpHandler)2 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)2 ServletExtension (io.undertow.servlet.ServletExtension)2 ErrorPage (io.undertow.servlet.api.ErrorPage)2 ListenerInfo (io.undertow.servlet.api.ListenerInfo)2