use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class TestSecurityAnnotationConversions method testRolesAllowedWithTransportGuarantee.
@Test
public void testRolesAllowedWithTransportGuarantee() throws Exception {
//Assume we found 1 servlet with annotation with roles defined and
//and a TransportGuarantee
WebAppContext wac = makeWebAppContext(RolesServlet.class.getCanonicalName(), "rolesServlet", new String[] { "/foo/*", "*.foo" });
ServletSecurityAnnotationHandler annotationHandler = new ServletSecurityAnnotationHandler(wac);
AnnotationIntrospector introspector = new AnnotationIntrospector();
introspector.registerHandler(annotationHandler);
//set up the expected outcomes:compareResults
//1 ConstraintMapping per ServletMapping
Constraint expectedConstraint = new Constraint();
expectedConstraint.setAuthenticate(true);
expectedConstraint.setRoles(new String[] { "tom", "dick", "harry" });
expectedConstraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
ConstraintMapping[] expectedMappings = new ConstraintMapping[2];
expectedMappings[0] = new ConstraintMapping();
expectedMappings[0].setConstraint(expectedConstraint);
expectedMappings[0].setPathSpec("/foo/*");
expectedMappings[1] = new ConstraintMapping();
expectedMappings[1].setConstraint(expectedConstraint);
expectedMappings[1].setPathSpec("*.foo");
introspector.introspect(RolesServlet.class);
compareResults(expectedMappings, ((ConstraintAware) wac.getSecurityHandler()).getConstraintMappings());
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class TestServletAnnotations method testWebServletAnnotationNoMappings.
@Test
public void testWebServletAnnotationNoMappings() throws Exception {
//an existing servlet OF THE SAME NAME has no mappings, therefore all mappings in the annotation
//should be accepted
WebAppContext wac = new WebAppContext();
ServletHolder servlet = new ServletHolder();
servlet.setName("foo");
wac.getServletHandler().addServlet(servlet);
WebServletAnnotation annotation = new WebServletAnnotation(wac, "org.eclipse.jetty.annotations.ServletD", null);
annotation.apply();
ServletMapping[] resultMappings = wac.getServletHandler().getServletMappings();
assertEquals(1, resultMappings.length);
assertEquals(2, resultMappings[0].getPathSpecs().length);
for (String s : resultMappings[0].getPathSpecs()) {
if (!s.equals("/") && !s.equals("/bah/*"))
fail("Unexpected path mapping");
}
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class TestServletAnnotations method testWebServletAnnotationNotOverride.
@Test
public void testWebServletAnnotationNotOverride() throws Exception {
//if the existing servlet mapping TO A DIFFERENT SERVLET IS NOT from a default descriptor we
//DO NOT allow the annotation to replace the mapping
WebAppContext wac = new WebAppContext();
ServletHolder servlet = new ServletHolder();
servlet.setClassName("org.eclipse.jetty.servlet.FooServlet");
servlet.setName("foo");
wac.getServletHandler().addServlet(servlet);
ServletMapping m = new ServletMapping();
m.setPathSpec("/");
m.setServletName("foo");
wac.getServletHandler().addServletMapping(m);
WebServletAnnotation annotation = new WebServletAnnotation(wac, "org.eclipse.jetty.annotations.ServletD", null);
annotation.apply();
ServletMapping[] resultMappings = wac.getServletHandler().getServletMappings();
assertEquals(2, resultMappings.length);
for (ServletMapping r : resultMappings) {
if (r.getServletName().equals("DServlet")) {
assertEquals(2, r.getPathSpecs().length);
} else if (r.getServletName().equals("foo")) {
assertEquals(1, r.getPathSpecs().length);
} else
fail("Unexpected servlet name");
}
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class WeldDeploymentBinding method processBinding.
public void processBinding(Node node, App app) throws Exception {
ContextHandler handler = app.getContextHandler();
if (handler == null) {
throw new NullPointerException("No Handler created for App: " + app);
}
if (handler instanceof WebAppContext) {
// Do webapp specific init
WebAppContext webapp = (WebAppContext) handler;
JettyWeldInitializer.initWebApp(webapp);
} else {
// Do general init
JettyWeldInitializer.initContext(handler);
}
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class JettyRunTask method execute.
/**
* Executes this Ant task. The build flow is being stopped until Jetty
* server stops.
*
* @throws BuildException if unable to build
*/
public void execute() throws BuildException {
TaskLog.log("Configuring Jetty for project: " + getProject().getName());
setSystemProperties();
List<Connector> connectorsList = null;
if (connectors != null)
connectorsList = connectors.getConnectors();
else
connectorsList = new Connectors(jettyPort, 30000).getDefaultConnectors();
List<LoginService> loginServicesList = (loginServices != null ? loginServices.getLoginServices() : new ArrayList<LoginService>());
ServerProxyImpl server = new ServerProxyImpl();
server.setConnectors(connectorsList);
server.setLoginServices(loginServicesList);
server.setRequestLog(requestLog);
server.setJettyXml(jettyXml);
server.setDaemon(daemon);
server.setStopPort(stopPort);
server.setStopKey(stopKey);
server.setContextHandlers(contextHandlers);
server.setTempDirectory(tempDirectory);
server.setScanIntervalSecs(scanIntervalSeconds);
try {
for (WebAppContext webapp : webapps) {
server.addWebApplication((AntWebAppContext) webapp);
}
} catch (Exception e) {
throw new BuildException(e);
}
server.start();
}
Aggregations