Search in sources :

Example 26 with DeploymentManager

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

the class WebsocketStressTestCase method setup.

@BeforeClass
public static void setup() throws Exception {
    executor = Executors.newFixedThreadPool(NUM_THREADS);
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(WebsocketStressTestCase.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(WebsocketStressTestCase.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addEndpoint(StressEndpoint.class).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {

        @Override
        public void ready(ServerWebSocketContainer container) {
            deployment = container;
        }
    })).setDeploymentName("servletContext.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", manager.start()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 27 with DeploymentManager

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

the class ServletClientCertAuthTestCase method setup.

@BeforeClass
public static void setup() throws ServletException, IOException {
    DefaultServer.startSSLServer();
    clientSSLContext = DefaultServer.getClientSSLContext();
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo usernameServlet = new ServletInfo("Username Servlet", SendUsernameServlet.class).addMapping("/secured/username");
    ServletInfo authTypeServlet = new ServletInfo("Auth Type Servlet", SendAuthTypeServlet.class).addMapping("/secured/authType");
    LoginConfig loginConfig = new LoginConfig(REALM_NAME);
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("CLIENT_CERT"));
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(loginConfig).addServlets(usernameServlet, authTypeServlet);
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*")).addRoleAllowed("role1").setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(path);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) SendUsernameServlet(io.undertow.servlet.test.security.SendUsernameServlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SendAuthTypeServlet(io.undertow.servlet.test.security.SendAuthTypeServlet) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) BeforeClass(org.junit.BeforeClass)

Example 28 with DeploymentManager

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

the class EmptyRoleSemanticTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("servlet", AuthenticationMessageServlet.class).addInitParam(MessageServlet.MESSAGE, HELLO_WORLD).addMapping("/permit").addMapping("/deny").addMapping("/authenticate");
    ServletIdentityManager identityManager = new ServletIdentityManager();
    // Just one role less user.
    identityManager.addUser("user1", "password1");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(new LoginConfig("BASIC", "Test Realm")).addServlet(s);
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/permit")).setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/deny")).setEmptyRoleSemantic(EmptyRoleSemantic.DENY));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/authenticate")).setEmptyRoleSemantic(EmptyRoleSemantic.AUTHENTICATE));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) BeforeClass(org.junit.BeforeClass)

Example 29 with DeploymentManager

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

the class SecurityConstraintUrlMappingTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("servlet", AuthenticationMessageServlet.class).addInitParam(MessageServlet.MESSAGE, HELLO_WORLD).addMapping("/role1").addMapping("/role2").addMapping("/starstar").addMapping("/secured/role2/*").addMapping("/secured/1/2/*").addMapping("/public/*").addMapping("/extension/*");
    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    identityManager.addUser("user2", "password2", "role2", "**");
    identityManager.addUser("user3", "password3", "role1", "role2");
    identityManager.addUser("user4", "password4", "badRole");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(new LoginConfig("BASIC", "Test Realm")).addServlet(s);
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/role1")).addRoleAllowed("role1"));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/starstar")).addRoleAllowed("**"));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*")).addRoleAllowed("role2"));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*")).addRoleAllowed("role2"));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/1/*")).addRoleAllowed("role1"));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/1/2/*")).addRoleAllowed("role2"));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("*.html")).addRoleAllowed("role2"));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/public/*")).setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/public/postSecured/*").addHttpMethod("POST")).addRoleAllowed("role1"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/star").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(new LoginConfig("BASIC", "Test Realm")).addSecurityRole("**").addServlet(s);
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/starstar")).addRoleAllowed("**"));
    manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) BeforeClass(org.junit.BeforeClass)

Example 30 with DeploymentManager

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

the class ServletCustomAuthTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("servlet", SendUsernameServlet.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/secured/*");
    ServletInfo s1 = new ServletInfo("loginPage", FormLoginServlet.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("group1")).addMapping("/FormLoginServlet");
    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html")).addServlets(s, s1).addAuthenticationMechanism("FORM", CustomAuthenticationMechanism.FACTORY);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(path);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ServletSecurityInfo(io.undertow.servlet.api.ServletSecurityInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) BeforeClass(org.junit.BeforeClass)

Aggregations

DeploymentManager (io.undertow.servlet.api.DeploymentManager)78 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)72 ServletContainer (io.undertow.servlet.api.ServletContainer)68 PathHandler (io.undertow.server.handlers.PathHandler)57 BeforeClass (org.junit.BeforeClass)53 ServletInfo (io.undertow.servlet.api.ServletInfo)50 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 FilterInfo (io.undertow.servlet.api.FilterInfo)16 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)16 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)13 LoginConfig (io.undertow.servlet.api.LoginConfig)12 ServletException (javax.servlet.ServletException)12 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)10 ListenerInfo (io.undertow.servlet.api.ListenerInfo)8 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)8 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)8 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)8 Test (org.junit.Test)8 TestHttpClient (io.undertow.testutils.TestHttpClient)7 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)5