diff --git a/README.md b/README.md index 7ad355b..e4658a3 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,80 @@ Next, add the following contents to the config file mounted in `./config/authori It basically configures read/write access for everyone for all data on the `http://mu.semte.ch/graphs/public` graph. +## Tutorials +### Specifying groups of users +sparql-parser does authentication based on user groups. We will later define which groups are allowed to perform which operations on which data. So first we need to define some user groups. +User groups are defined based on the result of a query involving the user's session id. This can look as follows: +```lisp +(supply-allowed-group "super-mega-admins" + :parameters ("session_group_id" "session_role") + :query "PREFIX ext: + PREFIX mu: + + SELECT ?session_group ?session_role WHERE { + ext:sessionGroup/mu:uuid ?session_group_id; + ext:sessionRole ?session_role. + FILTER( ?session_role = \"SuperMegaAdmin\" ) + }") +``` +If this query returns a result, the user will belong to the `super-mega-admins` group. The value for `` will be filled in automatically at runtime. The value of the variables listed in the `:parameters` argument will be joined using `/` and appended to the graph URI when it is accessed. This allows us to have a separate graph per user group. + +### Specifying which triples are accessible from which graphs +For this we need a `define-graph` block. This will create a *graph spec* and looks as follows: +```lisp +(define-graph organization ("http://mu.semte.ch/graphs/organizations/") + ("foaf:Person" -> _) + ("foaf:OnlineAccount" x> "ext:password")) +``` +**NOTE**: Any prefixes such as `foaf` and `ext` need to be defined, see [Defining prefixes](#defining-prefixes) + +The `define-graph` macro takes: +- A unique identifier (*here `organization`*) +- The URI of the graph where the triples are stored (*here `http://mu.semte.ch/graphs/organizations/`*) +- One or more triple shapes (*here `("foaf:Person" -> _)` and `("foaf:OnlineAccount" x> "ext:password")`*). + +The triple shapes have this form: `( )`. `` and `` must be a URI string (e.g. `"foaf:Person"`) or a `_` (indicating a wildcard). Triples that match these shapes will go to (or retrieved from) the specified graph (in the above example this is `http://mu.semte.ch/graphs/organizations/`). +**Note**: different *graph specs* can specify the same graph URI. + +These are all the possible operators: +- `T -> p`: Triples where the subject is of type `T` and the predicate is `p`. +- `T <- p`: Triples where the object is of type `T` and the predicate is `p`. +- `T x> p`: For triples where the subject is of type `T`, allow every predicate except for `p`. +- `T