use of io.undertow.servlet.test.security.constraint.ServletIdentityManager 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());
}
use of io.undertow.servlet.test.security.constraint.ServletIdentityManager 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);
}
use of io.undertow.servlet.test.security.constraint.ServletIdentityManager in project undertow by undertow-io.
the class ServletLoginTestCase 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).addMapping("/*");
ServletIdentityManager identityManager = new ServletIdentityManager();
identityManager.addUser("user1", "password1", "role1");
identityManager.addUser("user2", "password2", "role2");
identityManager.addUser("user3", "password3", "role3");
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).addFilter(new FilterInfo("LoginFilter", LoginFilter.class)).addFilterServletNameMapping("LoginFilter", "servlet", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
path.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(path);
}
use of io.undertow.servlet.test.security.constraint.ServletIdentityManager 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);
}
use of io.undertow.servlet.test.security.constraint.ServletIdentityManager 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);
}
Aggregations