Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
Framework configuration refactoring major changes
Browse files Browse the repository at this point in the history
src/main/java/accounts/FrameworkUserManager.java
- minor changes of some get functions
- added a rollback of virtuoso user creation if the graph insert has an error
- added a missing prefix to  getPrefixes() (I was having an error because a default prefix : was missing)

src/main/java/authentication/FrameworkConfiguration.java
- this file changed a lot to be able to read configuration from web.xml and from ttl files

src/main/java/accounts/VirtuosoUserManager.java
- irrelevant formatting changes

src/main/java/authentication/web/AuthenticationServlet.java
src/main/java/authentication/web/GraphManagerServlet.java
src/main/java/authentication/web/HttpRequestManager.java
src/main/java/authentication/web/UserManagerServlet.java
src/main/java/authentication/web/VirtuosoProxy.java
- added a exception handle
- added the context parameter to the Framework configuration

src/main/java/authentication/web/RdfStoreProxy.java
- added the context parameter to the Framework configuration
- I started checking how to do here the exception in order that the webapp provides more information about errors.. but not finished
- do some formatting

src/main/webapp/WEB-INF/web.xml
- lots of changes.. some configuration is to be handled here : namespaces, Uris, and email settings

src/main/resources/*
- replaced all configuration files
- these files are copied to classes directory when the application is deployed, and then, they can be read by the configuration class

src/main/webapp/js/config.js

- these file should not hava anymore any configuration for the endopoints

- I have to still change it to be able to take namespaces form the server.. thus some configuration is still there
  • Loading branch information
alegrm committed May 22, 2014
1 parent a5d1fe8 commit aba7878
Show file tree
Hide file tree
Showing 19 changed files with 1,288 additions and 1,092 deletions.
37 changes: 27 additions & 10 deletions src/main/java/accounts/FrameworkUserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import util.ObjectPair;
import util.RandomStringGenerator;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -61,13 +62,13 @@ public void createUser(String name, String password, String email) throws Except
counter++;
} while (error && counter<10);
//grant SPARQL_UPDATE role to created Virtuoso user
// todo users with only read access?
//TODO: users with only read access?
rdfStoreUserManager.grantRole(rdfStoreUser, "SPARQL_UPDATE");

//create setting graph for user
String userSettingsGraphURI = frameworkConfig.getResourceNamespace() + URLEncoder.encode(name, "UTF-8") + "/settingsGraph";
// grant write permissions to framework - otherwise framework fails to create graph
rdfStoreUserManager.setRdfGraphPermissions(frameworkConfig.getSparqlFrameworkLogin(), userSettingsGraphURI, 3);
rdfStoreUserManager.setRdfGraphPermissions(frameworkConfig.getAuthSparqlUser(), userSettingsGraphURI, 3);
rdfStoreManager.createGraph(userSettingsGraphURI);
//grant write permissions to user
rdfStoreUserManager.setRdfGraphPermissions(rdfStoreUser, userSettingsGraphURI, 3); // todo deny access for user?
Expand All @@ -76,8 +77,15 @@ public void createUser(String name, String password, String email) throws Except
String query = getPrefixes() + "\n"
+ "INSERT INTO <" + userSettingsGraphURI + "> {?s ?p ?o} "
+ "WHERE {GRAPH <" + frameworkConfig.getInitialSettingsGraph() + "> {?s ?p ?o} }";
rdfStoreManager.execute(query, jsonResponseFormat);

try{
rdfStoreManager.execute(query, jsonResponseFormat);
}
catch(IOException e)
{ // failed to write user graph
// rollback actions:
rdfStoreUserManager.dropUser(rdfStoreUser);
throw e;
}
// write user account to accounts graph
query = getPrefixes() + "\n"
+ "INSERT DATA { GRAPH <" + frameworkConfig.getAccountsGraph() + "> {\n"
Expand All @@ -90,8 +98,17 @@ public void createUser(String name, String password, String email) throws Except
+ " :" + name + " foaf:mbox <mailto:" + email + "> .\n"
+ " :" + name + " dcterms:created \"" + ISO8601Utils.format(new Date()) + "\"^^xsd:date .\n"
+ "} }";
rdfStoreManager.execute(query, jsonResponseFormat);


try{
rdfStoreManager.execute(query, jsonResponseFormat);
}
catch(IOException e)
{ // failed to register user in to the accounts graph
// rollback actions:
rdfStoreUserManager.dropUser(rdfStoreUser);
rdfStoreManager.dropGraph(userSettingsGraphURI);
throw e;
}
//todo delete Virtuoso user if failed to write account triples
}

Expand Down Expand Up @@ -623,12 +640,12 @@ public String getDescribedIn(String graph) throws Exception {

private String getPrefixes() {
if (prefixes==null) {
prefixes = "PREFIX : <" + frameworkConfig.getAccountsNamespace() + ">\n"
+ "PREFIX ao: <" + frameworkConfig.getAccountsOntologyNamespace() + ">\n"
prefixes ="PREFIX : <" + frameworkConfig.getResourceNamespace() + ">\n"
+ "PREFIX ao: <" + frameworkConfig.getAccountsOntologyNamespace() + ">\n"
+ "PREFIX gkg: <"+ frameworkConfig.getFrameworkOntologyNS() +">\n"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX user: <http://schemas.talis.com/2005/user/schema#>\n"
+ "PREFIX sd: <http://www.w3.org/ns/sparql-service-description#>\n"
+ "PREFIX gkg: <http://generator.geoknow.eu/ontology/>\n"
+ "PREFIX acl: <http://www.w3.org/ns/auth/acl#>\n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
+ "PREFIX dcterms: <http://purl.org/dc/terms/>";
Expand Down Expand Up @@ -662,7 +679,7 @@ private boolean checkUserExists(String username, String email) throws Exception

private Collection<String> getSettingsGraphs() throws Exception {
Collection<String> settingsGraphList = new ArrayList<String>();
settingsGraphList.add(frameworkConfig.getDefaultSettingsGraph());
settingsGraphList.add(frameworkConfig.getSettingsGraph());
String query = getPrefixes() + "\n"
+ " SELECT DISTINCT ?sg FROM <" + frameworkConfig.getAccountsGraph() + "> "
+ " WHERE { ?account ao:settingsGraph ?sg }";
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/accounts/VirtuosoUserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public class VirtuosoUserManager implements UserManager {
private String password;
private Connection connection;

/**
* This class manages the User creation in virtuoso for authentication and graph access control
* @param connectionString Connection string to Virtuoso
* @param user Virtuoso user
* @param password Virtuoso password
*/
public VirtuosoUserManager(String connectionString, String user, String password) {
this.connectionString = connectionString;
this.user = user;
Expand All @@ -31,7 +37,7 @@ public void dropUser(String name) throws Exception {

@Override
public void grantRole(String user, String role) throws Exception {
executeUpdate(getConnection(), "GRANT " + role + " TO \"" + user + "\"");
executeUpdate(getConnection(), "GRANT " + role + " TO \"" + user + "\"");
}

@Override
Expand Down
Loading

0 comments on commit aba7878

Please sign in to comment.