# -----------------------------
# Access control policy example
# -----------------------------

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix var: <http://www.w3.org/2000/10/swap/var#>.
@prefix : <http://example.org/#>.

:test1 :policy :PolicyX;
    :has :A, :B, :C.

:PolicyX a :Policy;
    :allOf :A, :B;
    :anyOf :C;
    :noneOf :D.

[ log:graph (
    [ log:triple (var:Pol :pass :allOfTest)]
)] log:isImpliedBy [ log:graph (
    [ log:triple (var:Test :policy var:Pol)]
    [ log:triple (var:Pol rdf:type :Policy)]
    [ log:triple (([ log:graph (
        [ log:triple (var:Pol :allOf var:Field)]
    )] [ log:graph (
        [ log:triple (var:Test :has var:Field)]
    )]) log:forAllIn var:X)]
)].

[ log:graph (
    [ log:triple (var:Pol :pass :anyOfTest)]
)] log:isImpliedBy [ log:graph (
    [ log:triple (var:Test :policy var:Pol)]
    [ log:triple (var:Pol rdf:type :Policy)]
    [ log:triple ((var:Field [ log:graph (
        [ log:triple (var:Pol :anyOf var:Field)]
        [ log:triple (var:Test :has var:Field)]
    )] var:List) log:collectAllIn var:X)]
    [ log:triple (var:List list:length var:L)]
    [ log:triple ((var:L) log:notEqualTo (0))]
)].

[ log:graph (
    [ log:triple (var:Pol :pass :noneOfTest)]
)] log:isImpliedBy [ log:graph (
    [ log:triple (var:Test :policy var:Pol)]
    [ log:triple (var:Pol rdf:type :Policy)]
    [ log:triple ((var:Field [ log:graph (
        [ log:triple (var:Pol :noneOf var:Field)]
        [ log:triple (var:Test :has var:Field)]
    )] var:List) log:collectAllIn var:X)]
    [ log:triple (var:List list:length var:L)]
    [ log:triple ((var:L) log:equalTo (0))]
)].

# query
[ log:graph (
    [ log:triple (var:Pol rdf:type :Policy)]
    [ log:triple (var:Pol :pass :allOfTest)]
    [ log:triple (var:Pol :pass :anyOfTest)]
    [ log:triple (var:Pol :pass :noneOfTest)]
)] log:impliesAnswer [ log:graph (
    [ log:triple (:test :for var:Pol)]
    [ log:triple (:test :is true)]
)].
