Search in sources :

Example 1 with AuthSetup

use of org.apache.jena.web.AuthSetup in project jena by apache.

the class TestPasswdOnly method passwd_user_bad.

@Test
public void passwd_user_bad() {
    AuthSetup auth1 = new AuthSetup("localhost", port, "user99", "pw1", null);
    expectQuery401(() -> {
        LibSec.withAuth("http://localhost:" + port + "/db", auth1, conn -> {
            conn.queryAsk("ASK{}");
        });
    });
}
Also used : AuthSetup(org.apache.jena.web.AuthSetup) Test(org.junit.Test)

Example 2 with AuthSetup

use of org.apache.jena.web.AuthSetup in project jena by apache.

the class TestSecurityBuilderSetup method beforeClass.

@BeforeClass
public static void beforeClass() {
    int port = WebLib.choosePort();
    authSetup1 = new AuthSetup("localhost", port, "user1", "pw1", "TripleStore");
    authSetup2 = new AuthSetup("localhost", port, "user2", "pw2", "TripleStore");
    authSetupX = new AuthSetup("localhost", port, "userX", "pwX", "TripleStore");
    // Two authorized users.
    UserStore userStore = new UserStore();
    JettyLib.addUser(userStore, authSetup1.user, authSetup1.password);
    JettyLib.addUser(userStore, authSetup2.user, authSetup2.password);
    try {
        userStore.start();
    } catch (Exception ex) {
        throw new RuntimeException("UserStore", ex);
    }
    ConstraintSecurityHandler sh = JettyLib.makeSecurityHandler(authSetup1.realm, userStore);
    // Secure these areas.
    // User needs to be logged in.
    JettyLib.addPathConstraint(sh, "/ds");
    // Allow auth control even through there isn't anything there
    JettyLib.addPathConstraint(sh, "/nowhere");
    // user1 only.
    JettyLib.addPathConstraint(sh, "/ctl");
    // Not controlled: "/open"
    AuthPolicy reqAuth = Auth.policyAllowSpecific("user1");
    DataService dSrv = DataService.newBuilder(DatasetGraphFactory.createTxnMem()).withStdServices(false).setAuthPolicy(reqAuth).build();
    fusekiServer = FusekiServer.create().port(port).add("/ds", DatasetFactory.createTxnMem()).add("/open", DatasetFactory.createTxnMem()).add("/ctl", dSrv).securityHandler(sh).build();
    fusekiServer.start();
    serverURL = fusekiServer.serverURL();
}
Also used : AuthSetup(org.apache.jena.web.AuthSetup) UserStore(org.eclipse.jetty.security.UserStore) AuthPolicy(org.apache.jena.fuseki.auth.AuthPolicy) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) HttpException(org.apache.jena.atlas.web.HttpException) DataService(org.apache.jena.fuseki.server.DataService) BeforeClass(org.junit.BeforeClass)

Example 3 with AuthSetup

use of org.apache.jena.web.AuthSetup in project jena by apache.

the class TestPasswdOnly method passwd_user1.

@Test
public void passwd_user1() {
    // Works!
    AuthSetup auth1 = new AuthSetup("localhost", port, "user1", "pw1", null);
    expectOK(() -> {
        LibSec.withAuth("http://localhost:" + port + "/db", auth1, conn -> {
            conn.queryAsk("ASK{}");
        });
    });
}
Also used : AuthSetup(org.apache.jena.web.AuthSetup) Test(org.junit.Test)

Aggregations

AuthSetup (org.apache.jena.web.AuthSetup)3 Test (org.junit.Test)2 HttpException (org.apache.jena.atlas.web.HttpException)1 AuthPolicy (org.apache.jena.fuseki.auth.AuthPolicy)1 DataService (org.apache.jena.fuseki.server.DataService)1 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)1 UserStore (org.eclipse.jetty.security.UserStore)1 BeforeClass (org.junit.BeforeClass)1