use of org.apache.jena.fuseki.auth.AuthPolicy in project jena by apache.
the class TestAuthorized method auth_anyLoggedIn_2.
@Test
public void auth_anyLoggedIn_2() {
AuthPolicy auth = Auth.policyAllowSpecific("*");
assertFalse(auth.isAllowed(null));
assertTrue(auth.isAllowed("user1"));
}
use of org.apache.jena.fuseki.auth.AuthPolicy 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();
}
use of org.apache.jena.fuseki.auth.AuthPolicy in project jena by apache.
the class FusekiConfig method accEndpointOldStyle.
// Old style.
// fuseki:serviceQuery "sparql";
// or
// fuseki:serviceQuery [ fuseki:name "sparql" ; fuseki:allowedUsers (..) ];
private static void accEndpointOldStyle(Collection<Endpoint> endpoints, Operation operation, Resource svc, Property property) {
String p = "<" + property.getURI() + ">";
ResultSet rs = BuildLib.query("SELECT * { ?svc " + p + " ?ep}", svc.getModel(), "svc", svc);
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
// No policy yet - set below if one is found.
AuthPolicy authPolicy = null;
RDFNode ep = soln.get("ep");
String endpointName = null;
if (ep.isLiteral())
// fuseki:serviceQuery "sparql"
endpointName = soln.getLiteral("ep").getLexicalForm();
else if (ep.isResource()) {
Resource r = (Resource) ep;
try {
// [ fuseki:name ""; fuseki:allowedUsers ( "" "" ) ]
Statement stmt = r.getProperty(FusekiVocab.pEndpointName);
if (stmt == null)
throw new FusekiConfigException("Expected property <" + FusekiVocab.pEndpointName + "> with <" + property.getURI() + "> for <" + svc + ">");
endpointName = stmt.getString();
List<RDFNode> x = GraphUtils.multiValue(r, FusekiVocab.pAllowedUsers);
if (x.size() > 1)
throw new FusekiConfigException("Multiple fuseki:" + FusekiVocab.pAllowedUsers.getLocalName() + " for " + r);
if (!x.isEmpty())
authPolicy = allowedUsers(r);
} catch (JenaException | ClassCastException ex) {
throw new FusekiConfigException("Failed to parse endpoint: " + r);
}
} else {
throw new FusekiConfigException("Unrecognized: " + ep);
}
if (StringUtils.isEmpty(endpointName))
endpointName = null;
Endpoint endpoint = Endpoint.create(operation, endpointName, authPolicy);
endpoints.add(endpoint);
}
}
use of org.apache.jena.fuseki.auth.AuthPolicy in project jena by apache.
the class TestAuthorized method auth_parse_1.
@Test
public void auth_parse_1() {
Resource r = model.createResource("http://example/r1");
AuthPolicy auth = FusekiConfig.allowedUsers(r);
assertNotNull(auth);
assertFalse(auth.isAllowed(null));
assertTrue(auth.isAllowed("user1"));
assertTrue(auth.isAllowed("user2"));
assertFalse(auth.isAllowed("user3"));
}
use of org.apache.jena.fuseki.auth.AuthPolicy in project jena by apache.
the class TestAuthorized method auth_anyLoggedIn_1.
@Test
public void auth_anyLoggedIn_1() {
AuthPolicy auth = Auth.ANY_USER;
assertFalse(auth.isAllowed(null));
assertTrue(auth.isAllowed("user1"));
}
Aggregations