Search in sources :

Example 26 with ServletInfo

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

the class SaveOriginalPostRequestTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo securedRequestDumper = new ServletInfo("SecuredRequestDumperServlet", RequestDumper.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/secured/dumpRequest");
    ServletInfo securedIndexRequestDumper = new ServletInfo("SecuredIndexRequestDumperServlet", RequestDumper.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/index.html");
    ServletInfo unsecuredRequestDumper = new ServletInfo("UnsecuredRequestDumperServlet", RequestDumper.class).addMapping("/dumpRequest");
    ServletInfo loginFormServlet = 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).addWelcomePage("index.html").setResourceManager(new TestResourceLoader(SaveOriginalPostRequestTestCase.class)).setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html")).addServlets(securedRequestDumper, unsecuredRequestDumper, loginFormServlet, securedIndexRequestDumper);
    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) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) 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) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) BeforeClass(org.junit.BeforeClass)

Example 27 with ServletInfo

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

the class ServletFormAuthURLRewriteTestCase 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 echo = new ServletInfo("echo", EchoServlet.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/secured/echo");
    ServletInfo echoParam = new ServletInfo("echoParam", RequestParamEchoServlet.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/secured/echoParam");
    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().setServletSessionConfig(new ServletSessionConfig().setSessionTrackingModes(Collections.singleton(SessionTrackingMode.URL))).setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setAuthenticationMode(AuthenticationMode.CONSTRAINT_DRIVEN).setIdentityManager(identityManager).setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html")).addServlets(s, s1, echo, echoParam);
    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) ServletSessionConfig(io.undertow.servlet.api.ServletSessionConfig) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) BeforeClass(org.junit.BeforeClass)

Example 28 with ServletInfo

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

the class ErrorPageTestCase method setup.

@BeforeClass
public static void setup() throws IOException, ServletException {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    final PathHandler root = new PathHandler();
    DefaultServer.setRootHandler(root);
    DeploymentInfo builder1 = new DeploymentInfo();
    builder1.addServlet(new ServletInfo("error", ErrorServlet.class).addMapping("/error"));
    builder1.addServlet(new ServletInfo("path", PathServlet.class).addMapping("/*"));
    builder1.addErrorPage(new ErrorPage("/defaultErrorPage"));
    builder1.addErrorPage(new ErrorPage("/404", StatusCodes.NOT_FOUND));
    builder1.addErrorPage(new ErrorPage("/parentException", ParentException.class));
    builder1.addErrorPage(new ErrorPage("/childException", ChildException.class));
    builder1.addErrorPage(new ErrorPage("/runtimeException", RuntimeException.class));
    builder1.setExceptionHandler(LoggingExceptionHandler.builder().add(ParentException.class, "io.undertow", Logger.Level.DEBUG).add(ChildException.class, "io.undertow", Logger.Level.DEBUG).add(RuntimeException.class, "io.undertow", Logger.Level.DEBUG).add(ServletException.class, "io.undertow", Logger.Level.DEBUG).build());
    builder1.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ErrorPageTestCase.class.getClassLoader()).setContextPath("/servletContext1").setServletStackTraces(ServletStackTraces.NONE).setDeploymentName("servletContext1.war");
    final DeploymentManager manager1 = container.addDeployment(builder1);
    manager1.deploy();
    root.addPrefixPath(builder1.getContextPath(), manager1.start());
    DeploymentInfo builder2 = new DeploymentInfo();
    builder2.addServlet(new ServletInfo("error", ErrorServlet.class).addMapping("/error"));
    builder2.addServlet(new ServletInfo("path", PathServlet.class).addMapping("/*"));
    builder2.addErrorPage(new ErrorPage("/404", StatusCodes.NOT_FOUND));
    builder2.addErrorPage(new ErrorPage("/501", StatusCodes.NOT_IMPLEMENTED));
    builder2.addErrorPage(new ErrorPage("/parentException", ParentException.class));
    builder2.addErrorPage(new ErrorPage("/childException", ChildException.class));
    builder2.addErrorPage(new ErrorPage("/runtimeException", RuntimeException.class));
    builder2.setExceptionHandler(LoggingExceptionHandler.builder().add(ParentException.class, "io.undertow", Logger.Level.DEBUG).add(ChildException.class, "io.undertow", Logger.Level.DEBUG).add(RuntimeException.class, "io.undertow", Logger.Level.DEBUG).add(ServletException.class, "io.undertow", Logger.Level.DEBUG).build());
    builder2.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ErrorPageTestCase.class.getClassLoader()).setContextPath("/servletContext2").setServletStackTraces(ServletStackTraces.NONE).setDeploymentName("servletContext2.war");
    final DeploymentManager manager2 = container.addDeployment(builder2);
    manager2.deploy();
    root.addPrefixPath(builder2.getContextPath(), manager2.start());
    DeploymentInfo builder3 = new DeploymentInfo();
    builder3.addServlet(new ServletInfo("error", ErrorServlet.class).addMapping("/error"));
    builder3.addServlet(new ServletInfo("path", PathServlet.class).addMapping("/*"));
    builder3.addErrorPage(new ErrorPage("/defaultErrorPage"));
    builder3.addErrorPage(new ErrorPage("/404", StatusCodes.NOT_FOUND));
    builder3.addErrorPage(new ErrorPage("/500", StatusCodes.INTERNAL_SERVER_ERROR));
    builder3.addErrorPage(new ErrorPage("/parentException", ParentException.class));
    builder3.addErrorPage(new ErrorPage("/childException", ChildException.class));
    builder3.addErrorPage(new ErrorPage("/runtimeException", RuntimeException.class));
    builder3.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ErrorPageTestCase.class.getClassLoader()).setContextPath("/servletContext3").setServletStackTraces(ServletStackTraces.NONE).setDeploymentName("servletContext3.war");
    builder3.setExceptionHandler(LoggingExceptionHandler.builder().add(ParentException.class, "io.undertow", Logger.Level.DEBUG).add(ChildException.class, "io.undertow", Logger.Level.DEBUG).add(RuntimeException.class, "io.undertow", Logger.Level.DEBUG).add(ServletException.class, "io.undertow", Logger.Level.DEBUG).build());
    final DeploymentManager manager3 = container.addDeployment(builder3);
    manager3.deploy();
    root.addPrefixPath(builder3.getContextPath(), manager3.start());
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ErrorPage(io.undertow.servlet.api.ErrorPage) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 29 with ServletInfo

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

the class SecurityErrorPageTestCase method setup.

@BeforeClass
public static void setup() throws IOException, ServletException {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    final PathHandler root = new PathHandler();
    DefaultServer.setRootHandler(root);
    DeploymentInfo builder = new DeploymentInfo();
    builder.addServlet(new ServletInfo("secure", SecureServlet.class).addMapping("/secure")).addSecurityConstraint(Servlets.securityConstraint().addRoleAllowed("user").addWebResourceCollection(Servlets.webResourceCollection().addUrlPattern("/*")));
    builder.addServlet(new ServletInfo("path", PathServlet.class).addMapping("/*"));
    builder.addErrorPage(new ErrorPage("/401", StatusCodes.UNAUTHORIZED));
    ServletIdentityManager identityManager = new ServletIdentityManager();
    // Just one role less user.
    identityManager.addUser("user1", "password1");
    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ErrorPageTestCase.class.getClassLoader()).setContextPath("/servletContext").setServletStackTraces(ServletStackTraces.NONE).setIdentityManager(identityManager).setLoginConfig(Servlets.loginConfig("BASIC", "Test Realm")).setDeploymentName("servletContext.war");
    final DeploymentManager manager1 = container.addDeployment(builder);
    manager1.deploy();
    root.addPrefixPath(builder.getContextPath(), manager1.start());
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ErrorPage(io.undertow.servlet.api.ErrorPage) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) BeforeClass(org.junit.BeforeClass)

Example 30 with ServletInfo

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

the class ServletBasicAuthTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    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");
    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    identityManager.addUser("charsetUser", "password-ΓΌ", "role1");
    LoginConfig loginConfig = new LoginConfig(REALM_NAME);
    Map<String, String> props = new HashMap<>();
    props.put("charset", "ISO_8859_1");
    props.put("user-agent-charsets", "Chrome,UTF-8,OPR,UTF-8");
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("BASIC", props));
    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 : WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) HashMap(java.util.HashMap) DeploymentManager(io.undertow.servlet.api.DeploymentManager) PathHandler(io.undertow.server.handlers.PathHandler) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) ServletInfo(io.undertow.servlet.api.ServletInfo) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) SendUsernameServlet(io.undertow.servlet.test.security.SendUsernameServlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SendAuthTypeServlet(io.undertow.servlet.test.security.SendAuthTypeServlet) BeforeClass(org.junit.BeforeClass)

Aggregations

ServletInfo (io.undertow.servlet.api.ServletInfo)67 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)58 ServletContainer (io.undertow.servlet.api.ServletContainer)51 DeploymentManager (io.undertow.servlet.api.DeploymentManager)50 PathHandler (io.undertow.server.handlers.PathHandler)49 BeforeClass (org.junit.BeforeClass)43 FilterInfo (io.undertow.servlet.api.FilterInfo)15 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)14 LoginConfig (io.undertow.servlet.api.LoginConfig)13 ListenerInfo (io.undertow.servlet.api.ListenerInfo)11 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)11 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)10 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)9 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)9 Test (org.junit.Test)9 TestHttpClient (io.undertow.testutils.TestHttpClient)8 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)7 MessageServlet (io.undertow.servlet.test.util.MessageServlet)6 Servlet (javax.servlet.Servlet)6 ServletException (javax.servlet.ServletException)6