From f4b25b639a5f13e038641668dcb4de9e2e84a5c5 Mon Sep 17 00:00:00 2001
From: Nordine Bittich <3816305+nbittich@users.noreply.github.com>
Date: Wed, 4 Aug 2021 16:49:07 +0200
Subject: [PATCH] Feature/mock login (#23)
---
config/authorization/config.ex | 65 +++++++++++++++--
config/db/virtuoso.ini | 2 +-
config/dispatcher/dispatcher.ex | 16 +++-
...151011002223444444-create-mock-user.sparql | 32 ++++++++
...10815112611122233-create-mock-group.sparql | 13 ++++
.../20210824115111111133333333-auth.sparql | 18 +++++
.../202109241151111112111233322-auth.sparql | 52 +++++++++++++
config/resources/auth.json | 73 +++++++++++++++++++
config/resources/domain.lisp | 3 +-
docker-compose.dev.yml | 9 ++-
docker-compose.yml | 4 +-
11 files changed, 276 insertions(+), 11 deletions(-)
create mode 100644 config/migrations/202108151011002223444444-create-mock-user.sparql
create mode 100644 config/migrations/20210815112611122233-create-mock-group.sparql
create mode 100644 config/migrations/20210824115111111133333333-auth.sparql
create mode 100644 config/migrations/202109241151111112111233322-auth.sparql
create mode 100644 config/resources/auth.json
diff --git a/config/authorization/config.ex b/config/authorization/config.ex
index 3bd99d8..60c5983 100644
--- a/config/authorization/config.ex
+++ b/config/authorization/config.ex
@@ -7,14 +7,30 @@ alias Acl.GroupSpec, as: GroupSpec
alias Acl.GroupSpec.GraphCleanup, as: GraphCleanup
defmodule Acl.UserGroups.Config do
+ defp access_by_role( group_string ) do
+ %AccessByQuery{
+ vars: ["session_group","session_role"],
+ query: sparql_query_for_access_role( group_string ) }
+ end
+
+ defp sparql_query_for_access_role( group_string ) do
+ "PREFIX ext:
+ PREFIX mu:
+ SELECT ?session_group ?session_role WHERE {
+ ext:sessionGroup/mu:uuid ?session_group;
+ ext:sessionRole ?session_role.
+ FILTER( ?session_role = \"#{group_string}\" )
+ }"
+ end
+
def user_groups do
[
- %GroupSpec{
- name: "public",
+ %GroupSpec{
+ name: "ch-admin",
useage: [:read, :write, :read_for_write],
- access: %AlwaysAccessible{},
+ access: access_by_role( "ChAdmin" ),
graphs: [ %GraphSpec{
- graph: "http://mu.semte.ch/graphs/public",
+ graph: "http://mu.semte.ch/graphs/contacthub/",
constraint: %ResourceConstraint{
resource_types: [
"http://www.w3.org/ns/org#Organization",
@@ -51,9 +67,48 @@ defmodule Acl.UserGroups.Config do
"http://lblod.data.gift/vocabularies/organisatie/BestuurseenheidClassificatieCode",
"http://lblod.data.gift/vocabularies/organisatie/TypeBetrokkenheid",
"http://www.w3.org/2004/02/skos/core#ConceptScheme",
- "http://www.w3.org/2004/02/skos/core#Concept"
+ "http://www.w3.org/2004/02/skos/core#Concept",
+ "http://xmlns.com/foaf/0.1/Image",
+ "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#FileDataObject" ] } } ] },
+ %GroupSpec{
+ name: "public",
+ useage: [:read],
+ access: %AlwaysAccessible{},
+ graphs: [ %GraphSpec{
+ graph: "http://mu.semte.ch/graphs/public",
+ constraint: %ResourceConstraint{
+ resource_types: [
+ "http://data.vlaanderen.be/ns/besluit#Bestuurseenheid",
+ "http://xmlns.com/foaf/0.1/Person",
+ "http://xmlns.com/foaf/0.1/OnlineAccount"
]
+ } },
+ %GraphSpec{
+ graph: "http://mu.semte.ch/graphs/sessions",
+ constraint: %ResourceFormatConstraint{
+ resource_prefix: "http://mu.semte.ch/sessions/"
} } ] },
+
+ %GroupSpec{
+ name: "org",
+ useage: [:read],
+ access: %AccessByQuery{
+ vars: ["session_group"],
+ query: "PREFIX ext:
+ PREFIX mu:
+ SELECT ?session_group ?session_role WHERE {
+ ext:sessionGroup/mu:uuid ?session_group.
+ }" },
+ graphs: [ %GraphSpec{
+ graph: "http://mu.semte.ch/graphs/organizations/",
+ constraint: %ResourceConstraint{
+ resource_types: [
+ "http://xmlns.com/foaf/0.1/Person",
+ "http://xmlns.com/foaf/0.1/OnlineAccount",
+ "http://www.w3.org/ns/adms#Identifier",
+ ] } } ] },
+ # // CLEANUP
+ #
%GraphCleanup{
originating_graph: "http://mu.semte.ch/application",
useage: [:read, :write],
diff --git a/config/db/virtuoso.ini b/config/db/virtuoso.ini
index f02e7e8..b65df13 100755
--- a/config/db/virtuoso.ini
+++ b/config/db/virtuoso.ini
@@ -245,7 +245,7 @@ LoadPath = /usr/local/virtuoso-opensource/lib/virtuoso/hosting
;Load1 = plain, wikiv
;Load2 = plain, mediawiki
;Load3 = plain, creolewiki
-;Load4 = plain, im
+;Load4 = plain, im
;Load5 = plain, wbxml2
;Load6 = plain, hslookup
;Load7 = attach, libphp5.so
diff --git a/config/dispatcher/dispatcher.ex b/config/dispatcher/dispatcher.ex
index 572c309..5f6f5ab 100644
--- a/config/dispatcher/dispatcher.ex
+++ b/config/dispatcher/dispatcher.ex
@@ -194,7 +194,21 @@ defmodule Dispatcher do
# sparql endpoint
###############################################################
match "/sparql/*path", %{ accept: [:any], layer: :api} do
- forward conn, path, "http://db:8890/sparql/"
+ Proxy.forward conn, path, "http://db:8890/sparql/"
+ end
+
+ ###############
+ # LOGIN
+ match "/accounts/*path", %{ accept: [:json], layer: :api} do
+ Proxy.forward conn, path, "http://resource/accounts/"
+ end
+
+ match "/groups/*path", %{ accept: [:json], layer: :api} do
+ Proxy.forward conn, path, "http://resource/groups/"
+ end
+
+ match "/mock/sessions/*path", %{ accept: [:any], layer: :api} do
+ Proxy.forward conn, path, "http://mocklogin/sessions/"
end
###############
diff --git a/config/migrations/202108151011002223444444-create-mock-user.sparql b/config/migrations/202108151011002223444444-create-mock-user.sparql
new file mode 100644
index 0000000..2ebb37b
--- /dev/null
+++ b/config/migrations/202108151011002223444444-create-mock-user.sparql
@@ -0,0 +1,32 @@
+PREFIX besluit:
+PREFIX skos:
+PREFIX foaf:
+PREFIX mu:
+PREFIX ext:
+
+INSERT DATA {
+ GRAPH {
+ a foaf:Person ;
+ mu:uuid "d39fe09e-d339-4e43-8680-dbbcfb3d3470" ;
+ foaf:firstName "Mock" ;
+ foaf:familyName "Agentschap Binnenlands Bestuur" ;
+ foaf:member ;
+ foaf:account .
+ a foaf:OnlineAccount ;
+ mu:uuid "3a91ff60-07c1-4136-ac5e-55cf401e0956" ;
+ foaf:accountServiceHomepage ;
+ ext:sessionRole "ChAdmin".
+ }
+ GRAPH {
+ a foaf:Person ;
+ mu:uuid "d39fe09e-d339-4e43-8680-dbbcfb3d3470" ;
+ foaf:firstName "Mock" ;
+ foaf:familyName "Agentschap Binnenlands Bestuur" ;
+ foaf:member ;
+ foaf:account .
+ a foaf:OnlineAccount ;
+ mu:uuid "3a91ff60-07c1-4136-ac5e-55cf401e0956" ;
+ foaf:accountServiceHomepage ;
+ ext:sessionRole "ChAdmin".
+ }
+}
\ No newline at end of file
diff --git a/config/migrations/20210815112611122233-create-mock-group.sparql b/config/migrations/20210815112611122233-create-mock-group.sparql
new file mode 100644
index 0000000..2624663
--- /dev/null
+++ b/config/migrations/20210815112611122233-create-mock-group.sparql
@@ -0,0 +1,13 @@
+PREFIX mu:
+PREFIX skos:
+PREFIX dcterms:
+PREFIX besluit:
+
+INSERT DATA {
+ GRAPH {
+ a besluit:Bestuurseenheid ;
+ mu:uuid "141d9d6b-54af-4d17-b313-8d1c30bc3f5b" ;
+ skos:prefLabel "Agentschap Binnenlands Bestuur" ;
+ dcterms:identifier "OVO001835" .
+ }
+}
\ No newline at end of file
diff --git a/config/migrations/20210824115111111133333333-auth.sparql b/config/migrations/20210824115111111133333333-auth.sparql
new file mode 100644
index 0000000..43adbab
--- /dev/null
+++ b/config/migrations/20210824115111111133333333-auth.sparql
@@ -0,0 +1,18 @@
+DELETE {
+ GRAPH {
+ ?s ?p ?o .
+ }
+} INSERT {
+ GRAPH {
+ ?s ?p ?o .
+ }
+} WHERE {
+ GRAPH {
+ ?s a ?type ; ?p ?o .
+ VALUES ?type {
+
+
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/config/migrations/202109241151111112111233322-auth.sparql b/config/migrations/202109241151111112111233322-auth.sparql
new file mode 100644
index 0000000..cc6ebab
--- /dev/null
+++ b/config/migrations/202109241151111112111233322-auth.sparql
@@ -0,0 +1,52 @@
+ DELETE {
+ GRAPH {
+ ?s ?p ?o .
+ }
+ } INSERT {
+ GRAPH {
+ ?s ?p ?o .
+ }
+ } WHERE {
+ GRAPH {
+ ?s a ?type ; ?p ?o .
+ VALUES ?type {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+ }
+ }
\ No newline at end of file
diff --git a/config/resources/auth.json b/config/resources/auth.json
new file mode 100644
index 0000000..2046ef1
--- /dev/null
+++ b/config/resources/auth.json
@@ -0,0 +1,73 @@
+{
+ "version": "0.1",
+ "prefixes": {
+ "foaf": "http://xmlns.com/foaf/0.1/",
+ "besluit": "http://data.vlaanderen.be/ns/besluit#",
+ "dct": "http://purl.org/dc/terms/",
+ "skos": "http://www.w3.org/2004/02/skos/core#"
+ },
+ "resources": {
+ "users": {
+ "name": "user",
+ "class": "foaf:Person",
+ "attributes": {
+ "first-name": {
+ "type": "string",
+ "predicate": "foaf:firstName"
+ },
+ "family-name": {
+ "type": "string",
+ "predicate": "foaf:familyName"
+ }
+ },
+ "relationships": {
+ "accounts": {
+ "predicate": "foaf:account",
+ "target": "account",
+ "cardinality": "many"
+ },
+ "groups": {
+ "predicate": "foaf:member",
+ "target": "group",
+ "cardinality": "many"
+ }
+ },
+ "new-resource-base": "http://data.lblod.info/id/gebruiker/"
+ },
+ "accounts": {
+ "name": "account",
+ "class": "foaf:OnlineAccount",
+ "attributes": {
+ "provider": {
+ "type": "string",
+ "predicate": "foaf:accountServiceHomepage"
+ },
+ "identifier": {
+ "type": "string",
+ "predicate": "dct:identifier"
+ }
+ },
+ "relationships": {
+ "user": {
+ "predicate": "foaf:account",
+ "target": "user",
+ "cardinality": "one",
+ "inverse": true
+ }
+ },
+ "new-resource-base": "http://data.lblod.info/id/account/"
+ },
+ "groups": {
+ "name": "group",
+ "class": "besluit:Bestuurseenheid",
+ "attributes": {
+ "name": {
+ "type": "string",
+ "predicate": "skos:prefLabel"
+ }
+ },
+ "relationships": {},
+ "new-resource-base": "http://data.lblod.info/id/bestuurseenheden/"
+ }
+ }
+}
\ No newline at end of file
diff --git a/config/resources/domain.lisp b/config/resources/domain.lisp
index 7555bcb..a0faba9 100644
--- a/config/resources/domain.lisp
+++ b/config/resources/domain.lisp
@@ -11,4 +11,5 @@
(defparameter *cache-count-queries* t)
(defparameter *supply-cache-headers-p* t)
-(read-domain-file "domain.json")
\ No newline at end of file
+(read-domain-file "domain.json")
+(read-domain-file "auth.json")
\ No newline at end of file
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 145f00f..b49242c 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -11,6 +11,9 @@ services:
restart: "no"
db:
restart: "no"
+ triplestore:
+ ports:
+ - "8890:8890"
migrations:
restart: "no"
resource:
@@ -26,4 +29,8 @@ services:
kalliope-api:
restart: "no"
deltanotifier:
- restart: "no"
\ No newline at end of file
+ restart: "no"
+ mocklogin:
+ image: lblod/mock-login-service:latest
+ links:
+ - db:database
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 632e65e..30854fb 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -9,10 +9,10 @@ x-logging:
services:
identifier:
- image: semtech/mu-identifier:1.9.1
+ image: semtech/mu-identifier:1.8.1
environment:
DEFAULT_ACCESS_CONTROL_ALLOW_ORIGIN_HEADER: "*"
- DEFAULT_MU_AUTH_ALLOWED_GROUPS_HEADER: "[{\"variables\":[],\"name\":\"public\"}, {\"variables\":[],\"name\":\"clean\"}]"
+ DEFAULT_MU_AUTH_ALLOWED_GROUPS_HEADER: "[{\"variables\":[],\"name\":\"public\"}]"
labels:
- "logging=true"
restart: always