Search in sources :

Example 16 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class ExFuseki_01_NamedService method main.

public static void main(String... args) {
    // Create a new operation: operations are really just names (symbols). The code to
    // run is found by looking up the operation in a per-server table that gives the server-specific
    // implementation as an ActionService.
    Operation myOperation = Operation.alloc("http://example/special1", "special1", "Custom operation");
    // Service endpoint name.
    // This can be different for different datasets even in the same server.
    // c.f. {@code fuseki:serviceQuery}
    String endpointName = "special";
    // The handled for the new operation.
    ActionService customHandler = new DemoService();
    FusekiServer server = FusekiServer.create().port(PORT).verbose(true).registerOperation(myOperation, customHandler).add(DATASET, DatasetGraphFactory.createTxnMem(), true).addEndpoint(DATASET, endpointName, myOperation).build();
    // Start the server. This does not block this thread.
    server.start();
    // Try some operations on the server using the service URL.
    String customOperationURL = SERVER_URL + DATASET + "/" + endpointName;
    try {
        // Service endpoint name : GET
        String s1 = HttpOp.httpGetString(customOperationURL);
        System.out.print(s1);
        if (s1 == null)
            System.out.println();
        // Service endpoint name : POST
        try (TypedInputStream stream = HttpOp.httpPostStream(customOperationURL, "text/plain")) {
            String s2 = FileUtils.readWholeFileAsUTF8(stream);
            System.out.print(s2);
            if (s2 == null)
                System.out.println();
        } catch (IOException ex) {
            IO.exception(ex);
        }
        // Service endpoint name. DELETE -> fails 405
        try {
            HttpOp.httpDelete(customOperationURL);
            throw new IllegalStateException("DELETE succeeded");
        } catch (HttpException ex) {
            if (ex.getStatusCode() != HttpSC.METHOD_NOT_ALLOWED_405)
                System.err.println("Unexpected HTTP Response Code: " + ex.getMessage());
            else
                System.out.println("DELETE rejected correctly: " + ex.getMessage());
        }
    } finally {
        server.stop();
    }
}
Also used : HttpException(org.apache.jena.atlas.web.HttpException) Operation(org.apache.jena.fuseki.server.Operation) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) IOException(java.io.IOException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) ActionService(org.apache.jena.fuseki.servlets.ActionService)

Example 17 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class ExFuseki_06_DataAccessCtl method fuseki.

/**
 * Create a Fuseki server with:
 * <ul>
 * <li>port, dataset and name
 * <li>user/password for Jetty basic authentication
 * <li>Authorization service
 * </ul>
 */
private static FusekiServer fuseki(int port, UserStore userStore, AuthorizationService authorizeSvc, String dsName, DatasetGraph dsgBase) {
    // Associate access control information with the dataset.
    DatasetGraph dsx = DataAccessCtl.controlledDataset(dsgBase, authorizeSvc);
    // Build a Fuseki server with the access control operations replacing the normal (no control) operations.
    FusekiServer.Builder builder = FusekiLib.fusekiBuilderAccessCtl(DataAccessCtl.requestUserServlet).port(port).add(dsName, dsx, false);
    // Add service endpoint login for authentication.
    ConstraintSecurityHandler sh = null;
    if (userStore != null) {
        sh = JettyLib.makeSecurityHandler("Dataset:" + dsName, userStore);
        JettyLib.addPathConstraint(sh, dsName);
        builder.securityHandler(sh);
    }
    return builder.build();
}
Also used : ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 18 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class ExFuseki_10_Https_Setup method codeHttps.

public static FusekiServer codeHttps() {
    FusekiLogging.setLogging();
    // Some empty dataset
    DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
    FusekiServer server = FusekiServer.create().https(3443, ExConst.KEYSTORE, ExConst.KEYSTOREPASSWORD).port(3030).add("/ds", dsg).build();
    server.start();
    // server.join();
    return server;
}
Also used : FusekiServer(org.apache.jena.fuseki.main.FusekiServer) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 19 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class TestServiceDataAuthConfig method build.

public static FusekiServer build(int port, AuthPolicy policy) {
    AuthPolicy policy12 = Auth.policyAllowSpecific("user1", "user2");
    AuthPolicy policy13 = Auth.policyAllowSpecific("user1", "user3");
    DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
    DataService.Builder dSrvBuilder = DataService.newBuilder(dsg);
    dSrvBuilder.addEndpoint(Endpoint.create(Operation.Query, null, policy12));
    dSrvBuilder.addEndpoint(Endpoint.create(Operation.Update, null, policy13));
    DataService dSrv = dSrvBuilder.build();
    FusekiServer server = FusekiServer.create().verbose(true).port(port).passwordFile("testing/Access/passwd").add("/db", dSrv).build();
    return server;
}
Also used : AuthPolicy(org.apache.jena.fuseki.auth.AuthPolicy) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DataService(org.apache.jena.fuseki.server.DataService)

Example 20 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class ExFusekiMain_2_AddShiro method addShiroFilter.

// From Barry Nouwt : https://lists.apache.org/thread.html/r1e3fa952ff9f4a9108e16f07f1edf78c67e08c9b081497c627e3b833%40%3Cusers.jena.apache.org%3E
public static void addShiroFilter(FusekiServer fusekiServer) {
    Server jettyServer = fusekiServer.getJettyServer();
    ServletContextHandler servletContextHandler = (ServletContextHandler) jettyServer.getHandler();
    ServletHandler servletHandler = servletContextHandler.getServletHandler();
    // for shiro
    EnvironmentLoaderListener ell = new EnvironmentLoaderListener();
    servletContextHandler.addEventListener(ell);
    // Copies
    List<FilterMapping> mappings = new ArrayList<FilterMapping>(Arrays.asList(servletHandler.getFilterMappings()));
    List<FilterHolder> holders = new ArrayList<FilterHolder>(Arrays.asList(servletHandler.getFilters()));
    {
        // add Shiro Filter and mapping
        FilterHolder holder1 = new FilterHolder();
        holder1.setFilter(new ShiroFilter());
        FilterMapping mapping1 = new FilterMapping();
        mapping1.setFilterName(holder1.getName());
        mapping1.setPathSpec("/*");
        mapping1.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
        mappings.add(0, mapping1);
        holders.add(0, holder1);
    }
    FilterMapping[] mappings3 = new FilterMapping[mappings.size()];
    mappings3 = mappings.toArray(mappings3);
    FilterHolder[] holders3 = new FilterHolder[holders.size()];
    holders3 = holders.toArray(holders3);
    servletHandler.setFilters(holders3);
    servletHandler.setFilterMappings(mappings3);
    // Specify the Session ID Manager
    SessionIdManager idmanager = new DefaultSessionIdManager(jettyServer);
    jettyServer.setSessionIdManager(idmanager);
    // Specify the session handler
    SessionHandler sessionsHandler = new SessionHandler();
    sessionsHandler.setUsingCookies(false);
    servletHandler.setHandler(sessionsHandler);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) EnvironmentLoaderListener(org.apache.shiro.web.env.EnvironmentLoaderListener) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) Server(org.eclipse.jetty.server.Server) ArrayList(java.util.ArrayList) FilterMapping(org.eclipse.jetty.servlet.FilterMapping) SessionIdManager(org.eclipse.jetty.server.SessionIdManager) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ShiroFilter(org.apache.shiro.web.servlet.ShiroFilter)

Aggregations

FusekiServer (org.apache.jena.fuseki.main.FusekiServer)25 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)6 Operation (org.apache.jena.fuseki.server.Operation)4 UserStore (org.eclipse.jetty.security.UserStore)4 IOException (java.io.IOException)3 ActionService (org.apache.jena.fuseki.servlets.ActionService)3 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)3 Test (org.junit.Test)3 HttpException (org.apache.jena.atlas.web.HttpException)2 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)2 DataService (org.apache.jena.fuseki.server.DataService)2 Graph (org.apache.jena.graph.Graph)2 Node (org.apache.jena.graph.Node)2 Triple (org.apache.jena.graph.Triple)2 QueryExecution (org.apache.jena.query.QueryExecution)2 Model (org.apache.jena.rdf.model.Model)2 Authenticator (java.net.Authenticator)1 BindException (java.net.BindException)1 HttpClient (java.net.http.HttpClient)1