11package authentication ;
22
3- import java .io .ByteArrayOutputStream ;
43import java .io .IOException ;
54
65import javax .servlet .ServletContext ;
@@ -31,7 +30,6 @@ public class FrameworkConfiguration {
3130 private String emailUsername = "" ;
3231 private String emailPassword = "" ;
3332
34- private String accountsOntologyNS = "" ;
3533 private String resourceNS = "" ;
3634 private String frameworkOntologyNS = "" ;
3735
@@ -55,31 +53,21 @@ public class FrameworkConfiguration {
5553 /**
5654 *
5755 * @param context
58- * @param reset
5956 * @return
6057 * @throws Exception
6158 */
62- // TODO: replace System.out.println with a logging implementation
63- public static synchronized FrameworkConfiguration getInstance (ServletContext context ,
64- boolean reset ) throws Exception {
59+ public static synchronized FrameworkConfiguration getInstance (ServletContext context ) throws Exception {
6560
6661 if (instance == null ) {
6762
68- System .out .println ("[INFO] System Initialization " );
69-
7063 instance = new FrameworkConfiguration ();
7164
7265 String configurationFile = "framework-configuration.ttl" ;
73- String datasetsFile = "framework-datasets.ttl" ;
74- String componentsFile = "framework-components.ttl" ;
75- String ontologyFile = "framework-ontology.ttl" ;
76- String accountsOntologyFile = "framework-accounts-ontology.ttl" ;
7766
7867 // initialize parameters from context
7968 instance .frameworkUri = context .getInitParameter ("framework-uri" );
8069
8170 instance .setFrameworkOntologyNS (context .getInitParameter ("framework-ontology-ns" ));
82- instance .setAccountsOntologyNamespace (context .getInitParameter ("accounts-ns" ));
8371 instance .setResourceNamespace (context .getInitParameter ("framework-ns" ));
8472
8573 instance .setSmtpHost (context .getInitParameter ("smtp-host" ));
@@ -174,145 +162,6 @@ else if ("groups".equals(soln.get("label").asLiteral().getString()))
174162 instance .setGroupsGraph (soln .get ("name" ).toString ());
175163 }
176164 qexec .close ();
177-
178- // creates the system user exist for the application in virtuoso
179- VirtuosoUserManager userManager = instance .getVirtuosoUserManager ();
180-
181- // if the flag to reinstall is true
182- if (reset ) {
183- try {
184- userManager .dropUser (instance .getAuthSparqlUser ());
185- } catch (Exception e ) {
186- // catches the error in case the user do not exist
187- }
188- // TODO: we may need to delete all users before to clean the store?
189- }
190-
191- try {
192-
193- userManager .createUser (instance .getAuthSparqlUser (), instance .getAuthSparqlPassword ());
194- userManager .setDefaultRdfPermissions (instance .getAuthSparqlUser (), 3 );
195- userManager .grantRole (instance .getAuthSparqlUser (), "SPARQL_UPDATE" );
196- userManager .grantLOLook (instance .getAuthSparqlUser ());
197- // TODO: check if we still need to grant these to SPARQL user
198- userManager .grantRole ("SPARQL" , "SPARQL_UPDATE" );
199- userManager .grantLOLook ("SPARQL" );
200-
201- System .out .println ("[INFO] System User was created " );
202- } catch (Exception e ) {
203- if ("virtuoso.jdbc4.VirtuosoException" .equals (e .getClass ().getCanonicalName ()))
204- // TODO: replace with a logging implementation
205- System .out .println ("Seems that the user is already there" );
206- else
207- throw e ;
208- }
209-
210- SecureRdfStoreManagerImpl frameworkRdfStoreManager = new SecureRdfStoreManagerImpl (instance
211- .getAuthSparqlEndpoint (), instance .getAuthSparqlUser (), instance .getAuthSparqlPassword ());
212- // delete all graphs if reinstall is requested
213- if (reset ) {
214- try {
215- frameworkRdfStoreManager .dropGraph (instance .getSettingsGraph ());
216- frameworkRdfStoreManager .dropGraph (instance .getAccountsGraph ());
217- frameworkRdfStoreManager .dropGraph (instance .getGroupsGraph ());
218- frameworkRdfStoreManager .dropGraph (instance .getInitialSettingsGraph ());
219- } catch (Exception e ) {
220- }
221- }
222-
223- // check if settingsGraph exist do not overwrite
224- String queryString = " ASK { GRAPH <" + instance .getSettingsGraph () + "> {?s a ?o} }" ;
225- String response = frameworkRdfStoreManager .execute (queryString , "text/plain" );
226- if (response .toLowerCase ().indexOf ("true" ) < 0 ) {
227-
228- // TODO: replace with a logging implementation
229- System .out .println ("[INFO] Default Graphs creation/configuration " );
230-
231- // Read configuration files
232- Model datasetModel = ModelFactory .createDefaultModel ();
233- Model componentsModel = ModelFactory .createDefaultModel ();
234- Model ontologyModel = ModelFactory .createDefaultModel ();
235- Model ontologyAccountsModel = ModelFactory .createDefaultModel ();
236-
237- try {
238- datasetModel .read (datasetsFile );
239- componentsModel .read (componentsFile );
240- ontologyModel .read (ontologyFile );
241- ontologyAccountsModel .read (accountsOntologyFile );
242- } catch (RiotException e ) {
243- throw new IOException ("Malformed configuration files" );
244- }
245-
246- // create required named graphs and load the configuration files
247- // using framework default user
248- frameworkRdfStoreManager .createGraph (instance .getSettingsGraph ());
249- frameworkRdfStoreManager .createGraph (instance .getAccountsGraph ());
250- frameworkRdfStoreManager .createGraph (instance .getGroupsGraph ());
251- frameworkRdfStoreManager .createGraph (instance .getInitialSettingsGraph ());
252-
253- // Make graphs accessible to framework user only
254- userManager .setDefaultRdfPermissions ("nobody" , 0 );
255- userManager .setRdfGraphPermissions (instance .getAuthSparqlUser (), instance
256- .getSettingsGraph (), 3 );
257- userManager .setRdfGraphPermissions (instance .getAuthSparqlUser (), instance
258- .getAccountsGraph (), 3 );
259- userManager .setRdfGraphPermissions (instance .getAuthSparqlUser (), instance .getGroupsGraph (),
260- 3 );
261- userManager .setRdfGraphPermissions (instance .getAuthSparqlUser (), instance
262- .getInitialSettingsGraph (), 3 );
263-
264- // join the settings files
265- Model settingsModel = ModelFactory .createDefaultModel ();
266- settingsModel .add (datasetModel );
267- settingsModel .add (componentsModel );
268- settingsModel .add (ontologyModel );
269-
270- // add to settings virtuoso component without users/passwords
271- queryString = "PREFIX foaf:<http://xmlns.com/foaf/0.1/> "
272- + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
273- + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> "
274- + "PREFIX lds:<http://stack.linkeddata.org/ldis-schema/>" + " CONSTRUCT { <"
275- + instance .getFrameworkUri () + "> ?p ?o . " + "<" + instance .getFrameworkUri ()
276- + "> lds:integrates ?component ."
277- + "?component rdfs:label ?label . ?component rdf:type ?type . "
278- + "?component lds:providesService ?service . ?service rdf:type ?servicetype ."
279- + "?service lds:serviceUrl ?serviceUrl .} " + " WHERE { <"
280- + instance .getFrameworkUri () + "> ?p ?o ." + "<" + instance .getFrameworkUri ()
281- + "> lds:integrates ?component ."
282- + "?component rdfs:label ?label . ?component rdf:type ?type . "
283- + "?component lds:providesService ?service . ?service rdf:type ?servicetype ."
284- + "?service lds:serviceUrl ?serviceUrl .}" ;
285- qexec = QueryExecutionFactory .create (queryString , configurationModel );
286- Model triples = qexec .execConstruct ();
287- settingsModel .add (triples );
288- qexec .close ();
289-
290- // write the initial settings model (default settings for new
291- // users)
292- ByteArrayOutputStream os = new ByteArrayOutputStream ();
293- settingsModel .write (os , "N-TRIPLES" );
294- queryString = "INSERT DATA { GRAPH <" + instance .getInitialSettingsGraph () + "> { "
295- + os .toString () + " } }" ;
296- os .close ();
297- frameworkRdfStoreManager .execute (queryString , null );
298-
299- // write the system settings model (include system graphs data)
300- // settingsModel.add(graphsModel);
301- os = new ByteArrayOutputStream ();
302- settingsModel .write (os , "N-TRIPLES" );
303- queryString = "INSERT DATA { GRAPH <" + instance .getSettingsGraph () + "> { "
304- + os .toString () + " } }" ;
305- os .close ();
306- frameworkRdfStoreManager .execute (queryString , null );
307-
308- // create and add accounts ontology to the accounts graph
309- os = new ByteArrayOutputStream ();
310- ontologyAccountsModel .write (os , "N-TRIPLES" );
311- queryString = "INSERT DATA { GRAPH <" + instance .getAccountsGraph () + "> { "
312- + os .toString () + " } }" ;
313- os .close ();
314- frameworkRdfStoreManager .execute (queryString , null );
315- }
316165 }
317166
318167 return instance ;
@@ -439,14 +288,6 @@ public void setAuthSparqlPassword(String authSparqlPassword) {
439288 // this.accountsNamespace = accountsNamespace;
440289 // }
441290
442- public String getAccountsOntologyNamespace () {
443- return accountsOntologyNS ;
444- }
445-
446- public void setAccountsOntologyNamespace (String accountsNamespace ) {
447- this .accountsOntologyNS = accountsNamespace ;
448- }
449-
450291 public String getAccountsGraph () {
451292 return accountsGraph ;
452293 }
0 commit comments