コード例 #1
0
  @BeforeClass
  public static void setup() throws Exception {
    js =
        UndertowJS.builder()
            .addResources(
                new ClassPathResourceManager(
                    JavascriptSecurityTestCase.class.getClassLoader(),
                    JavascriptSecurityTestCase.class.getPackage()),
                "security.js")
            .build();
    js.start();

    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "admin");
    identityManager.addUser("user2", "password2", "user");

    DeploymentInfo builder =
        new DeploymentInfo()
            .setClassLoader(JavascriptSecurityTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("BASIC", "Test Realm"))
            .addInnerHandlerChainWrapper(
                new HandlerWrapper() {
                  @Override
                  public HttpHandler wrap(HttpHandler handler) {
                    return js.getHandler(handler);
                  }
                });

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    PathHandler root = new PathHandler();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
  }
コード例 #2
0
 @AfterClass
 public static void after() {
   js.stop();
 }