Search in sources :

Example 71 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class ComplianceViolations2616Test method startServer.

@BeforeClass
public static void startServer() throws Exception {
    server = new Server();
    HttpConfiguration config = new HttpConfiguration();
    config.setSendServerVersion(false);
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(config, HttpCompliance.RFC2616);
    httpConnectionFactory.setRecordHttpComplianceViolations(true);
    connector = new LocalConnector(server, null, null, null, -1, httpConnectionFactory);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.setWelcomeFiles(new String[] { "index.html", "index.jsp", "index.htm" });
    context.addServlet(DumpRequestHeadersServlet.class, "/dump/*");
    context.addFilter(ReportViolationsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    server.setHandler(context);
    server.addConnector(connector);
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) BeforeClass(org.junit.BeforeClass)

Example 72 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class ConstraintSecurityHandler method checkUserDataPermissions.

@Override
protected boolean checkUserDataPermissions(String pathInContext, Request request, Response response, RoleInfo roleInfo) throws IOException {
    if (roleInfo == null)
        return true;
    if (roleInfo.isForbidden())
        return false;
    UserDataConstraint dataConstraint = roleInfo.getUserDataConstraint();
    if (dataConstraint == null || dataConstraint == UserDataConstraint.None)
        return true;
    HttpConfiguration httpConfig = Request.getBaseRequest(request).getHttpChannel().getHttpConfiguration();
    if (dataConstraint == UserDataConstraint.Confidential || dataConstraint == UserDataConstraint.Integral) {
        if (request.isSecure())
            return true;
        if (httpConfig.getSecurePort() > 0) {
            String scheme = httpConfig.getSecureScheme();
            int port = httpConfig.getSecurePort();
            String url = URIUtil.newURI(scheme, request.getServerName(), port, request.getRequestURI(), request.getQueryString());
            response.setContentLength(0);
            response.sendRedirect(url);
        } else
            response.sendError(HttpStatus.FORBIDDEN_403, "!Secure");
        request.setHandled(true);
        return false;
    } else {
        throw new IllegalArgumentException("Invalid dataConstraint value: " + dataConstraint);
    }
}
Also used : HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Constraint(org.eclipse.jetty.util.security.Constraint)

Example 73 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class ProxyServletLoadTest method startProxy.

private void startProxy() throws Exception {
    QueuedThreadPool proxyPool = new QueuedThreadPool();
    proxyPool.setName("proxy");
    proxy = new Server(proxyPool);
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.setSendDateHeader(false);
    configuration.setSendServerVersion(false);
    proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
    proxy.addConnector(proxyConnector);
    ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
    ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
    proxyContext.addServlet(proxyServletHolder, "/*");
    proxy.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 74 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class ReverseProxyTest method startProxy.

private void startProxy(Map<String, String> params) throws Exception {
    proxy = new Server();
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.setSendDateHeader(false);
    configuration.setSendServerVersion(false);
    proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
    proxy.addConnector(proxyConnector);
    ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
    ServletHolder proxyServletHolder = new ServletHolder(new AsyncMiddleManServlet() {

        @Override
        protected String rewriteTarget(HttpServletRequest clientRequest) {
            StringBuilder builder = new StringBuilder();
            builder.append(clientRequest.getScheme()).append("://127.0.0.1:");
            builder.append(serverConnector.getLocalPort());
            builder.append(clientRequest.getRequestURI());
            String query = clientRequest.getQueryString();
            if (query != null)
                builder.append("?").append(query);
            return builder.toString();
        }
    });
    if (params != null)
        proxyServletHolder.setInitParameters(params);
    proxyContext.addServlet(proxyServletHolder, "/*");
    proxy.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 75 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class AbstractTest method start.

protected void start(ServerSessionListener listener) throws Exception {
    prepareServer(new RawHTTP2ServerConnectionFactory(new HttpConfiguration(), listener));
    server.start();
    prepareClient();
    client.start();
}
Also used : RawHTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.RawHTTP2ServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Aggregations

HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)99 ServerConnector (org.eclipse.jetty.server.ServerConnector)71 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)70 Server (org.eclipse.jetty.server.Server)55 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)40 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)40 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)36 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)25 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)19 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Connector (org.eclipse.jetty.server.Connector)11 IOException (java.io.IOException)10 File (java.io.File)9 ServletException (javax.servlet.ServletException)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)8 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)7 Request (org.eclipse.jetty.server.Request)7