Search in sources :

Example 1 with Deployment

use of io.undertow.servlet.api.Deployment in project wildfly by wildfly.

the class UndertowHostTestCase method findContext.

@Test
public void findContext() {
    Deployment deployment = mock(Deployment.class);
    DeploymentInfo info = new DeploymentInfo();
    String expectedPath = "";
    info.setContextPath(expectedPath);
    HttpHandler handler = mock(HttpHandler.class);
    when(deployment.getDeploymentInfo()).thenReturn(info);
    this.undertowHost.registerDeployment(deployment, handler);
    Context result = this.host.findContext(expectedPath);
    assertSame(this.host, result.getHost());
    assertSame(expectedPath, result.getPath());
    result = this.host.findContext("unknown");
    assertNull(result);
}
Also used : Context(org.jboss.modcluster.container.Context) HttpHandler(io.undertow.server.HttpHandler) Deployment(io.undertow.servlet.api.Deployment) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Test(org.junit.Test)

Example 2 with Deployment

use of io.undertow.servlet.api.Deployment in project wildfly by wildfly.

the class UndertowHostTestCase method getContexts.

@Test
public void getContexts() {
    Deployment deployment = mock(Deployment.class);
    DeploymentInfo info = new DeploymentInfo();
    String expectedPath = "";
    info.setContextPath(expectedPath);
    HttpHandler handler = mock(HttpHandler.class);
    when(deployment.getDeploymentInfo()).thenReturn(info);
    this.undertowHost.registerDeployment(deployment, handler);
    Iterator<Context> result = this.host.getContexts().iterator();
    assertTrue(result.hasNext());
    Context context = result.next();
    assertSame(this.host, context.getHost());
    assertSame(expectedPath, context.getPath());
    assertFalse(result.hasNext());
}
Also used : Context(org.jboss.modcluster.container.Context) HttpHandler(io.undertow.server.HttpHandler) Deployment(io.undertow.servlet.api.Deployment) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Test(org.junit.Test)

Example 3 with Deployment

use of io.undertow.servlet.api.Deployment in project wildfly by wildfly.

the class UndertowDeploymentService method stopContext.

public void stopContext() {
    final ClassLoader old = Thread.currentThread().getContextClassLoader();
    DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue();
    Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader());
    try {
        if (deploymentManager != null) {
            Deployment deployment = deploymentManager.getDeployment();
            try {
                host.getValue().unregisterDeployment(deployment);
                deploymentManager.stop();
            } catch (ServletException e) {
                throw new RuntimeException(e);
            }
            deploymentManager.undeploy();
            container.getValue().getServletContainer().removeDeployment(deploymentInfoInjectedValue.getValue());
        }
        recursiveDelete(deploymentInfoInjectedValue.getValue().getTempDir());
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
}
Also used : ServletException(javax.servlet.ServletException) Deployment(io.undertow.servlet.api.Deployment) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 4 with Deployment

use of io.undertow.servlet.api.Deployment in project wildfly by wildfly.

the class UndertowDeploymentService method startContext.

public void startContext() throws ServletException {
    final ClassLoader old = Thread.currentThread().getContextClassLoader();
    DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue();
    Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader());
    try {
        StartupContext.setInjectionContainer(webInjectionContainer);
        try {
            deploymentManager = container.getValue().getServletContainer().addDeployment(deploymentInfo);
            deploymentManager.deploy();
            HttpHandler handler = deploymentManager.start();
            Deployment deployment = deploymentManager.getDeployment();
            host.getValue().registerDeployment(deployment, handler);
        } finally {
            StartupContext.setInjectionContainer(null);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
}
Also used : HttpHandler(io.undertow.server.HttpHandler) Deployment(io.undertow.servlet.api.Deployment) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 5 with Deployment

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

the class HttpServletRequestImpl method isUserInRole.

@Override
public boolean isUserInRole(final String role) {
    if (role == null) {
        return false;
    }
    //according to the servlet spec this aways returns false
    if (role.equals("*")) {
        return false;
    }
    SecurityContext sc = exchange.getSecurityContext();
    Account account = sc.getAuthenticatedAccount();
    if (account == null) {
        return false;
    }
    ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    if (role.equals("**")) {
        Set<String> roles = servletRequestContext.getDeployment().getDeploymentInfo().getSecurityRoles();
        if (!roles.contains("**")) {
            return true;
        }
    }
    final ServletChain servlet = servletRequestContext.getCurrentServlet();
    final Deployment deployment = servletContext.getDeployment();
    final AuthorizationManager authorizationManager = deployment.getDeploymentInfo().getAuthorizationManager();
    return authorizationManager.isUserInRole(role, account, servlet.getManagedServlet().getServletInfo(), this, deployment);
}
Also used : Account(io.undertow.security.idm.Account) ServletChain(io.undertow.servlet.handlers.ServletChain) SecurityContext(io.undertow.security.api.SecurityContext) ServletRequestContext(io.undertow.servlet.handlers.ServletRequestContext) Deployment(io.undertow.servlet.api.Deployment) HttpString(io.undertow.util.HttpString) AuthorizationManager(io.undertow.servlet.api.AuthorizationManager)

Aggregations

Deployment (io.undertow.servlet.api.Deployment)8 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)4 HttpHandler (io.undertow.server.HttpHandler)3 Test (org.junit.Test)3 HttpServerExchange (io.undertow.server.HttpServerExchange)2 Context (org.jboss.modcluster.container.Context)2 SecurityContext (io.undertow.security.api.SecurityContext)1 Account (io.undertow.security.idm.Account)1 Session (io.undertow.server.session.Session)1 SessionListener (io.undertow.server.session.SessionListener)1 SessionListeners (io.undertow.server.session.SessionListeners)1 AuthorizationManager (io.undertow.servlet.api.AuthorizationManager)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 ServletContainer (io.undertow.servlet.api.ServletContainer)1 ServletChain (io.undertow.servlet.handlers.ServletChain)1 ServletPathMatch (io.undertow.servlet.handlers.ServletPathMatch)1 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)1 HttpString (io.undertow.util.HttpString)1 ArrayDeque (java.util.ArrayDeque)1 Deque (java.util.Deque)1