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);
}
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());
}
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);
}
}
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);
}
}
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);
}
Aggregations