Search in sources :

Example 16 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler in project airlift by airlift.

the class HttpServer method createServletContext.

private static ServletContextHandler createServletContext(Servlet theServlet, Set<HttpResourceBinding> resources, Map<String, String> parameters, Set<Filter> filters, TraceTokenManager tokenManager, LoginService loginService, String... connectorNames) {
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.addFilter(new FilterHolder(new TimingFilter()), "/*", null);
    if (tokenManager != null) {
        context.addFilter(new FilterHolder(new TraceTokenFilter(tokenManager)), "/*", null);
    }
    // -- security handler
    if (loginService != null) {
        SecurityHandler securityHandler = createSecurityHandler(loginService);
        context.setSecurityHandler(securityHandler);
    }
    // -- user provided filters
    for (Filter filter : filters) {
        context.addFilter(new FilterHolder(filter), "/*", null);
    }
    // -- static resources
    for (HttpResourceBinding resource : resources) {
        ClassPathResourceFilter servlet = new ClassPathResourceFilter(resource.getBaseUri(), resource.getClassPathResourceBase(), resource.getWelcomeFiles());
        context.addFilter(new FilterHolder(servlet), servlet.getBaseUri() + "/*", null);
    }
    // -- gzip handler
    context.setGzipHandler(new GzipHandler());
    // -- the servlet
    ServletHolder servletHolder = new ServletHolder(theServlet);
    servletHolder.setInitParameters(ImmutableMap.copyOf(parameters));
    context.addServlet(servletHolder, "/*");
    // Starting with Jetty 9 there is no way to specify connectors directly, but
    // there is this wonky @ConnectorName virtual hosts automatically added
    String[] virtualHosts = new String[connectorNames.length];
    for (int i = 0; i < connectorNames.length; i++) {
        virtualHosts[i] = "@" + connectorNames[i];
    }
    context.setVirtualHosts(virtualHosts);
    return context;
}
Also used : ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpResourceBinding(io.airlift.http.server.HttpServerBinder.HttpResourceBinding) Constraint(org.eclipse.jetty.util.security.Constraint) Filter(javax.servlet.Filter) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 17 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler in project jena by apache.

the class TestRemoteEndpointResultsWithAuth method setup.

/**
 * Setup for the tests by allocating a Fuseki instance to work with
 *
 * @throws SQLException
 * @throws IOException
 */
@BeforeClass
public static void setup() throws SQLException, IOException {
    SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD);
    FusekiTestAuth.setupServer(true, sh);
    client = HttpClient.newBuilder().authenticator(AuthLib.authenticator(USER, PASSWORD)).build();
    connection = new RemoteEndpointConnection(FusekiTestAuth.serviceQuery(), FusekiTestAuth.serviceUpdate(), null, null, null, null, client, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null, null);
    connection.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) RemoteEndpointConnection(org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection) BeforeClass(org.junit.BeforeClass)

Example 18 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler in project jena by apache.

the class EnvTest method startServer.

private static FusekiServer startServer(String dsName, DatasetGraph dsg, StringHolderServlet holder, boolean verbose, String user, String password) {
    if (user != null && password == null)
        throw new IllegalArgumentException("User, not null, but  password null");
    if (user != null) {
    }
    String data = "/data";
    FusekiServer.Builder builder = FusekiServer.create().port(0).verbose(verbose).enablePing(true).auth(AuthScheme.BASIC).addServlet(data, holder).add(dsName, dsg);
    if (user != null) {
        UserStore userStore = JettyLib.makeUserStore(user, password);
        SecurityHandler sh = JettyLib.makeSecurityHandler("TripleStore", userStore, AuthScheme.BASIC);
        builder.securityHandler(sh).serverAuthPolicy(Auth.policyAllowSpecific(user));
    }
    FusekiServer server = builder.build();
    server.start();
    return server;
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) UserStore(org.eclipse.jetty.security.UserStore) FusekiServer(org.apache.jena.fuseki.main.FusekiServer)

Example 19 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler in project jena by apache.

the class ExFusekiMain_1_Servlet_AddFilter method main.

public static void main(String... a) {
    try {
        FusekiLogging.setLogging();
        UserStore userStore = JettyLib.makeUserStore("u", "p");
        SecurityHandler sh = JettyLib.makeSecurityHandler("TripleStore", userStore, AuthScheme.BASIC);
        FusekiServer server = FusekiServer.create().add("/ds", DatasetGraphFactory.createTxnMem()).serverAuthPolicy(Auth.ANY_USER).securityHandler(sh).build();
        addExtraFilter(server);
        server.start();
        // And use it.
        String URL = "http://localhost:3330/ds";
        try (RDFConnection conn = RDFConnection.connectPW(URL, "u", "p")) {
            boolean b = conn.queryAsk("ASK{}");
            System.out.println("ASK=" + b);
        }
    // server.join();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        System.exit(0);
    }
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) UserStore(org.eclipse.jetty.security.UserStore) RDFConnection(org.apache.jena.rdfconnection.RDFConnection) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) IOException(java.io.IOException)

Aggregations

SecurityHandler (org.eclipse.jetty.security.SecurityHandler)19 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)4 IOException (java.io.IOException)3 FusekiServer (org.apache.jena.fuseki.main.FusekiServer)3 UserStore (org.eclipse.jetty.security.UserStore)3 Handler (org.eclipse.jetty.server.Handler)3 GzipHandler (org.eclipse.jetty.server.handler.gzip.GzipHandler)3 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)3 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 Constraint (org.eclipse.jetty.util.security.Constraint)3 BeforeClass (org.junit.BeforeClass)3 Filter (javax.servlet.Filter)2 LoginService (org.eclipse.jetty.security.LoginService)2 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)2 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 HttpResourceBinding (io.airlift.http.server.HttpServerBinder.HttpResourceBinding)1 ForbiddenException (io.crnk.core.exception.ForbiddenException)1