-- Precautionary steps to avert confusion --

-- Clearout perms set for 'nobody' 

-- DB.DBA.RDF_ALL_USER_PERMS_DEL ('nobody') ;

-- DB.DBA.RDF_ALL_USER_PERMS_DEL ('VAL_SPARQL_ADMIN_G_CTX') ;

-- DB.DBA.RDF_ALL_USER_PERMS_DEL ('{problematic-sql-user-returned-in-integrity-check-errors}') ;

-- DB.DBA.RDF_GRAPH_USER_PERMS_SET ('http://kingsley.idehen.net/Artists#','kidehen1',15)  ;
-- DB.DBA.RDF_GRAPH_USER_PERMS_SET ('http://kingsley.idehen.net/Artists#','nobody',7)  ;
-- DB.DBA.RDF_DEFAULT_USER_PERMS_SET ('kidehen1', 15, 0);

-- Read, Write, Sponge, Graph Group listing  privileges on 'world' named graphs for users
--- VAL_SPARQL_ADMIN_G_CTX

-- DB.DBA.RDF_DEFAULT_USER_PERMS_SET ('VAL_SPARQL_ADMIN_G_CTX', 15, 0);



-- DB.DBA.RDF_DEFAULT_USER_PERMS_SET ('{problematic-sql-user-returned-in-integrity-check-errors}', 15, 0);

-- Read privileges for 'nobody' on 'world' named graphs

-- DB.DBA.RDF_DEFAULT_USER_PERMS_SET ('nobody', 1, 0);


-- Graph Security Integrity Check

RDF_GRAPH_SECURITY_AUDIT ( 0 ) ;

-- Clear Rules Graph Cache -- 

VAL.DBA.clear_graph_acl_cache() ;


-- Protected Named Graph Data Generation
-- Cleanup

SPARQL
CLEAR GRAPH <urn:protected:demo:graph:1> ;

SPARQL
CLEAR GRAPH <urn:protected:demo:graph:2> ; 

-- Data for Named Graph <urn:protected:demo:graph:1>

SPARQL
PREFIX acl: <http://www.w3.org/ns/auth/acl#>
PREFIX oplacl: <http://www.openlinksw.com/ontology/acl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

INSERT { GRAPH <urn:protected:demo:graph:1> 
              { <#i> a foaf:Person ;
			  		foaf:name "Kingsley Uyi Idehen" ;
					owl:sameAs <https://twitter.com/hashtag/kidehen#this> . 
			  } 
		}  ;

-- Data Generation Verification

SPARQL 
SELECT * 
FROM <urn:protected:demo:graph:1>
WHERE {?s ?p ?o} ;

-- Data for Named Graph <urn:protected:demo:graph:2>
		
SPARQL
PREFIX acl: <http://www.w3.org/ns/auth/acl#>
PREFIX oplacl: <http://www.openlinksw.com/ontology/acl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX like: <http://ontologi.es/like#> 
PREFIX owl: <http://www.w3.org/2002/07/owl#> 

INSERT { GRAPH <urn:protected:demo:graph:2> 
              { <#i> a foaf:Person ;
			  		foaf:name "Kingsley Uyi Idehen" ;
					owl:sameAs <https://www.linkedin.com/in/kidehen#this>, <https://www.facebook.com/kidehen#this> ;
					foaf:mbox <mailto:kidehen@openlinksw.com> ;
					like:likes dbpedia:Jollof_rice, dbpedia:Suya . 
					
			  } 
		} ;
		
		
-- Data Generation Verification

SPARQL 
SELECT * 
FROM <urn:protected:demo:graph:2>
WHERE {?s ?p ?o} ;


-- Protect Named Graphs by making them Private, using Virtuoso Graph Security Feature
-- i.e., by adding them to Private Named Graph Group

DB.DBA.RDF_GRAPH_GROUP_INS
('http://www.openlinksw.com/schemas/virtrdf#PrivateGraphs','urn:protected:demo:graph:1') ;

DB.DBA.RDF_GRAPH_GROUP_INS
('http://www.openlinksw.com/schemas/virtrdf#PrivateGraphs','urn:protected:demo:graph:2') ;


-- Graph Group Description & Loading --


-- Conditional Group Definition 

SPARQL
PREFIX acl: <http://www.w3.org/ns/auth/acl#>
PREFIX oplacl: <http://www.openlinksw.com/ontology/acl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

WITH GRAPH <http://kingsley.idehen.net/acl/graph/groups/http%3A%2F%2Fwww.openlinksw.com%2Fontology%2Facl%23DefaultRealm>
INSERT {
			<#groupBasicNetID> 
			a foaf:Group, oplacl:ConditionalGroup ;
			<http://xmlns.com/foaf/0.1/name> "Identities Denoted using a NetID based Identifier" ;
			<http://www.openlinksw.com/ontology/acl#hasCondition> [
																    a <http://www.openlinksw.com/ontology/acl#GroupCondition>, 
																	  <http://www.openlinksw.com/ontology/acl#GenericCondition> ;
																      <http://www.openlinksw.com/ontology/acl#hasCriteria> 
																	                 <http://www.openlinksw.com/ontology/acl#NetID> ;
																      <http://www.openlinksw.com/ontology/acl#hasComparator>         
																	                 <http://www.openlinksw.com/ontology/acl#IsNotNull> ;
																       <http://www.openlinksw.com/ontology/acl#hasValue> 1
											                      ] .
		} ;

	
-- Protected Named Graph ACL Definitions ---

-- Protection of Private Named Graph identified by IRI: <urn:protected:demo:graph:1> 
  
SPARQL
PREFIX  oplacl:  <http://www.openlinksw.com/ontology/acl#>
PREFIX     acl:  <http://www.w3.org/ns/auth/acl#>


WITH <http://kingsley.idehen.net/acl/graph/rules/http%3A%2F%2Fwww.openlinksw.com%2Fontology%2Facl%23DefaultRealm>
INSERT
   {
    <urn:HttpTLSPrivateNamedGraph:Rule1>  
	 a  acl:Authorization ;
	 rdfs:label "Private Named Graph ACL (HTTP Realm) for Named Graph Identified by IRI: <urn:protected:demo:graph:1>" ;
	 foaf:maker <http://kingsley.idehen.net/public_home/kidehen/profile.ttl#i> ;
	 oplacl:hasAccessMode  oplacl:Read ;
	 acl:accessTo <urn:protected:demo:graph:1> ;
	 acl:agent <#groupBasicNetID> ;
     oplacl:hasScope  oplacl:PrivateGraphs ;
     oplacl:hasRealm  oplacl:DefaultRealm .
  };
	  
-- Protection of Private Named Graph identified by IRI: <urn:protected:demo:graph:2> 

SPARQL
PREFIX  oplacl:  <http://www.openlinksw.com/ontology/acl#>
PREFIX     acl:  <http://www.w3.org/ns/auth/acl#>

WITH <http://kingsley.idehen.net/acl/graph/rules/http%3A%2F%2Fwww.openlinksw.com%2Fontology%2Facl%23DefaultRealm>
INSERT
{
 <urn:HttpTLSPrivateNamedGraph:Rule2> 
	 a  acl:Authorization ;
 rdfs:label "Private Named Graph ACL (HTTP Realm) for Named Graph Identified by IRI: <urn:protected:demo:graph:2>" ;
	 foaf:maker <http://kingsley.idehen.net/public_home/kidehen/profile.ttl#i> ;
	 oplacl:hasAccessMode  oplacl:Read ;
	 acl:accessTo <urn:protected:demo:graph:2> ;
   acl:agent <http://kingsley.idehen.net/public_home/kidehen/profile.ttl#i>,
          <http://id.myopenlink.net/DAV/home/KingsleyUyiIdehen/Public/kingsley.ttl#this>,
		  <https://s3.amazonaws.com/webid-sandbox/Profile/Basic-Identity-Claims-And-Profile-Document.ttl#i>,
		  <http://kingsley.idehen.net/public_home/kidehen/profile.ttl#i>, 
		  <https://www.dropbox.com/s/m5sdy9nn0qi15hk/profile.ttl?dl=1#identity>,
		  <http://id.myopenlink.net/DAV/home/cblakeley/youid_profile_160420.ttl#i>,
		  <https://dbfff61d85d4da9b5aefce09723385e78a93f731.googledrive.com/host/0B-Mx14cLTEsaczdJdk96UVQ0aVE/profile.ttl#identity>,
		  <http://id.myopenlink.net/DAV/home/hwilliams/YouID/Hugh_Williams_id_myopenlink_net_1/profile.ttl#identity>,
		  <http://id.myopenlink.net/DAV/home/danielhm/profile.ttl#i>, <http://kingsley.idehen.net/DAV/home/kidehen/onno_profile.ttl#i> ;
     oplacl:hasScope  oplacl:PrivateGraphs ;
     oplacl:hasRealm  oplacl:DefaultRealm .
};

