Search in sources :

Example 6 with WebAppContext

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());
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) HttpConstraint(javax.servlet.annotation.HttpConstraint) HttpMethodConstraint(javax.servlet.annotation.HttpMethodConstraint) Constraint(org.eclipse.jetty.util.security.Constraint) Test(org.junit.Test)

Example 7 with WebAppContext

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");
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Test(org.junit.Test)

Example 8 with WebAppContext

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");
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Test(org.junit.Test)

Example 9 with WebAppContext

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);
    }
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext)

Example 10 with WebAppContext

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();
}
Also used : Connectors(org.eclipse.jetty.ant.types.Connectors) Connector(org.eclipse.jetty.ant.types.Connector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) LoginService(org.eclipse.jetty.security.LoginService) BuildException(org.apache.tools.ant.BuildException)

Aggregations

WebAppContext (org.eclipse.jetty.webapp.WebAppContext)291 Server (org.eclipse.jetty.server.Server)108 File (java.io.File)74 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)38 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)35 IOException (java.io.IOException)31 ServerConnector (org.eclipse.jetty.server.ServerConnector)31 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)31 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)22 URL (java.net.URL)21 URISyntaxException (java.net.URISyntaxException)20 Handler (org.eclipse.jetty.server.Handler)17 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)17 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)15 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)15 WebXmlConfiguration (org.eclipse.jetty.webapp.WebXmlConfiguration)15 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)14 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)14 Resource (org.eclipse.jetty.util.resource.Resource)13