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

Commit 2bbe6ab

Browse files
committed
fix component integration route restrictions
1 parent d545ca8 commit 2bbe6ab

File tree

11 files changed

+217
-135
lines changed

11 files changed

+217
-135
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
<artifactId>tomcat7-maven-plugin</artifactId>
214214
<version>2.2</version>
215215
<configuration>
216-
<server>generator</server>
216+
<server>localhost</server>
217217
<url>${tomcat.deploy.url}</url>
218218
<path>/${project.build.finalName}</path>
219219
<update>true</update>

src/main/java/eu/geoknow/generator/configuration/FrameworkManager.java

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,39 +101,80 @@ public Service getFrameworkService(String uri) throws Exception {
101101
return service;
102102
}
103103

104+
105+
public Map<String, ArrayList<String>> getRouteRestrictions() throws Exception {
106+
String query =
107+
"SELECT ?route ?service FROM <" + config.getComponentsGraph() + "> WHERE { "
108+
+ "?restriction a <http://ldiw.ontos.com/ontology/RouteRestriction> ."
109+
+ "?restriction <" + LDIWO.route.getURI() + "> ?route ." + "?restriction <"
110+
+ LDIWO.requiresService.getURI() + "> ?service .}";
111+
112+
log.debug(query);
113+
String result = storeManager.execute(query, MediaType.SPARQL_JSON_RESPONSE_FORMAT);
114+
115+
Map<String, ArrayList<String>> routes = new HashMap<String, ArrayList<String>>();
116+
ObjectMapper mapper = new ObjectMapper();
117+
JsonNode rootNode = mapper.readTree(result);
118+
Iterator<JsonNode> bindingsIter = rootNode.path("results").path("bindings").elements();
119+
while (bindingsIter.hasNext()) {
120+
JsonNode bindingNode = bindingsIter.next();
121+
String route = bindingNode.get("route").path("value").textValue();
122+
String service = bindingNode.get("service").path("value").textValue();
123+
if (!routes.containsKey(route)) {
124+
ArrayList<String> services = new ArrayList<String>();
125+
routes.put(route, services);
126+
}
127+
routes.get(route).add(service);
128+
129+
}
130+
return routes;
131+
132+
}
133+
104134
/**
105135
* Get the list of integrated components
106136
*
107137
* @return List<String> compoments uris
108138
* @throws Exception
109139
*/
110-
public List<Map<String, String>> getIntegratedComponents() throws Exception {
140+
public Collection<Map<String, Object>> getIntegratedComponents() throws Exception {
111141

112142
String query =
113-
"SELECT ?component ?route ?type ?label FROM <" + config.getSettingsGraph() + "> FROM <"
114-
+ config.getComponentsGraph() + "> WHERE { <" + config.getFrameworkUri() + "> <"
115-
+ LDIS.integrates.getURI() + "> ?component . ?component <"
143+
"SELECT ?component ?service ?route ?type ?label FROM <" + config.getSettingsGraph()
144+
+ "> FROM <" + config.getComponentsGraph() + "> WHERE { <" + config.getFrameworkUri()
145+
+ "> <" + LDIS.integrates.getURI() + "> ?component . ?component <"
116146
+ LDIS.providesService.getURI() + "> ?service. ?service a ?type . ?service <"
117147
+ RDFS.label.getURI() + "> ?label . ?restriction <" + LDIWO.requiresService.getURI()
118148
+ "> ?service . ?restriction <" + LDIWO.route.getURI() + "> ?route }";
119149

120150
log.debug(query);
121151
String result = storeManager.execute(query, MediaType.SPARQL_JSON_RESPONSE_FORMAT);
122152

123-
List<Map<String, String>> components = new ArrayList<Map<String, String>>();
153+
Map<String, Map<String, Object>> components = new HashMap<String, Map<String, Object>>();
154+
// List<Map<String, String>> components = new ArrayList<Map<String, String>>();
124155
ObjectMapper mapper = new ObjectMapper();
125156
JsonNode rootNode = mapper.readTree(result);
126157
Iterator<JsonNode> bindingsIter = rootNode.path("results").path("bindings").elements();
127158
while (bindingsIter.hasNext()) {
128159
JsonNode bindingNode = bindingsIter.next();
129-
Map<String, String> component = new HashMap<String, String>();
130-
component.put("uri", bindingNode.get("component").path("value").textValue());
131-
component.put("route", bindingNode.get("route").path("value").textValue());
132-
component.put("type", bindingNode.get("type").path("value").textValue());
133-
component.put("label", bindingNode.get("label").path("value").textValue());
134-
components.add(component);
160+
String uri = bindingNode.get("component").path("value").textValue();
161+
String service = bindingNode.get("service").path("value").textValue();
162+
if (!components.containsKey(uri)) {
163+
Map<String, Object> component = new HashMap<String, Object>();
164+
component.put("uri", uri);
165+
component.put("route", bindingNode.get("route").path("value").textValue());
166+
component.put("type", bindingNode.get("type").path("value").textValue());
167+
component.put("label", bindingNode.get("label").path("value").textValue());
168+
ArrayList<String> services = new ArrayList<String>();
169+
services.add(service);
170+
component.put("requires", services);
171+
components.put(uri, component);
172+
} else {
173+
((ArrayList<String>) components.get(uri).get("requires")).add(service);
174+
}
175+
135176
}
136-
return components;
177+
return components.values();
137178
}
138179

139180
/**
@@ -194,4 +235,6 @@ public void removeComponentsIntegration(String uri) throws Exception {
194235
log.debug(result);
195236

196237
}
238+
239+
197240
}

src/main/java/eu/geoknow/generator/configuration/FrameworkSetup.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public void setUp(boolean reset) throws Exception {
6969

7070
// if setup is already done but not reset is wanted, exit here
7171
if (config.isSetUp() && !reset) {
72-
log.debug("System is already initialized. Reset " + reset);
72+
log.debug("System is already initialized, and reset is " + reset
73+
+ ". Will update components data... ");
74+
frameworkRdfStoreManager.dropGraph(config.getComponentsGraph());
75+
setupComponentsGraph();
7376
return;
7477
}
7578
// if setup already done and reset is want, delete flag and delete

src/main/java/eu/geoknow/generator/rest/Configuration.java

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eu.geoknow.generator.rest;
22

33
import java.io.IOException;
4+
import java.util.ArrayList;
45
import java.util.Collection;
56
import java.util.List;
67
import java.util.Map;
@@ -207,9 +208,9 @@ public Response getIntegratedComponents(@CookieParam(value = "user") Cookie user
207208
value = "token") String token) {
208209

209210
UserProfile user;
211+
FrameworkUserManager frameworkUserManager;
210212
try {
211-
FrameworkUserManager frameworkUserManager =
212-
FrameworkConfiguration.getInstance().getFrameworkUserManager();
213+
frameworkUserManager = FrameworkConfiguration.getInstance().getFrameworkUserManager();
213214
// authenticates the user, throw exception if fail
214215
user = frameworkUserManager.validate(userc, token);
215216
if (user == null) {
@@ -222,8 +223,16 @@ public Response getIntegratedComponents(@CookieParam(value = "user") Cookie user
222223

223224
try {
224225
FrameworkManager manager = new FrameworkManager();
225-
List<Map<String, String>> integrated = manager.getIntegratedComponents();
226+
Collection<Map<String, Object>> integrated = manager.getIntegratedComponents();
226227
List<String> required = manager.getRequiredComponents();
228+
229+
// Now have to filter the results, depending on the user'r role
230+
/*
231+
* if (!frameworkUserManager.isAdmin(user.getAccountURI())) { for (String s :
232+
* user.getRole().getServices()) {
233+
*
234+
* } }
235+
*/
227236
Gson gson = new Gson();
228237
String json =
229238
"{ \"integrated\" : " + gson.toJson(integrated) + ", \"required\" : "
@@ -393,4 +402,45 @@ public Response exists(@CookieParam(value = "user") Cookie userc,
393402
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
394403
}
395404
}
405+
406+
/**
407+
* Get a list of integrated components
408+
*
409+
* @param userc
410+
* @param token
411+
* @return
412+
*/
413+
@GET
414+
@Path("/routes")
415+
@Produces(MediaType.APPLICATION_JSON)
416+
public Response getRouteRestrictions(@CookieParam(value = "user") Cookie userc, @CookieParam(
417+
value = "token") String token) {
418+
419+
UserProfile user;
420+
FrameworkUserManager frameworkUserManager;
421+
try {
422+
frameworkUserManager = FrameworkConfiguration.getInstance().getFrameworkUserManager();
423+
// authenticates the user, throw exception if fail
424+
user = frameworkUserManager.validate(userc, token);
425+
if (user == null) {
426+
return Response.status(Response.Status.UNAUTHORIZED).entity("Invalid credentials").build();
427+
}
428+
} catch (Exception e) {
429+
log.error(e);
430+
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
431+
}
432+
433+
try {
434+
FrameworkManager manager = new FrameworkManager();
435+
Map<String, ArrayList<String>> routes = manager.getRouteRestrictions();
436+
437+
Gson gson = new Gson();
438+
String json = "{ \"restrictions\" : " + gson.toJson(routes) + "}";
439+
return Response.status(Response.Status.OK).entity(json).type(MediaType.APPLICATION_JSON)
440+
.build();
441+
} catch (Exception e) {
442+
log.error(e);
443+
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
444+
}
445+
}
396446
}

src/main/resources/system-components-template.ttl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,66 @@
180180
rdfs:label "Public-Private Data Coevolution"^^xsd:string ;
181181
lds:serviceUrl <http://localhost:8080/coevolution-service/> .
182182

183+
184+
########### ROUTES RESTRICTIONS DESCRIPTION #######################################################
185+
# Following triples describe required services for routes. It is used in conditional routing.
186+
# #######################################################################################
187+
188+
189+
:RolesRouteRestriction
190+
a ontos:RouteRestriction;
191+
ontos:route "/settings/roles"^^xsd:string;
192+
ontos:requiresService :UserManager .
193+
194+
:RdfImportRouteRestriction
195+
a ontos:RouteRestriction;
196+
ontos:route "/workbench/extraction-and-loading/import-rdf"^^xsd:string;
197+
ontos:requiresService :RdfImportService .
198+
199+
:SparqlifyRouteRestriction
200+
a ontos:RouteRestriction;
201+
ontos:route "/workbench/extraction-and-loading/sparqlify"^^xsd:string;
202+
ontos:requiresService :SparqlifyService .
203+
204+
:TripleGeoRouteRestriction
205+
a ontos:RouteRestriction;
206+
ontos:route "/workbench/extraction-and-loading/triplegeo"^^xsd:string;
207+
ontos:requiresService :TripleGeoService .
208+
209+
:FaceteRouteRestriction
210+
a ontos:RouteRestriction;
211+
ontos:route "/workbench/search-querying-and-exploration/facete"^^xsd:string;
212+
ontos:requiresService :FaceteService .
213+
214+
:MappifyRouteRestriction
215+
a ontos:RouteRestriction;
216+
ontos:route "/workbench/search-querying-and-exploration/mappify"^^xsd:string;
217+
ontos:requiresService :MappifyService .
218+
219+
:OntoWikiRouteRestriction
220+
a ontos:RouteRestriction;
221+
ontos:route "/workbench/manual-revision-and-authoring/ontowiki"^^xsd:string;
222+
ontos:requiresService :OntoWikiService .
223+
224+
:LIMESRouteRestriction
225+
a ontos:RouteRestriction;
226+
ontos:route "/workbench/linking-and-fusing/limes"^^xsd:string;
227+
ontos:requiresService :LimesService .
228+
229+
230+
:DeerRouteRestriction
231+
a ontos:RouteRestriction;
232+
ontos:route "/workbench/classification-and-enrichment/deer"^^xsd:string;
233+
ontos:requiresService :DEERService .
234+
235+
:FagiRouteRestriction
236+
a ontos:RouteRestriction;
237+
ontos:route "/workbench/linking-and-fusing/fagi-gis"^^xsd:string;
238+
ontos:requiresService :FagiGisService .
239+
240+
241+
:CoevRouteRestriction
242+
a ontos:RouteRestriction;
243+
ontos:route "/workbench/evolution-and-repair/coevolution-apply"^^xsd:string;
244+
ontos:requiresService :CoevolutionService .
245+

src/main/resources/system-configuration-template.ttl

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -73,66 +73,4 @@
7373
dcterms:title "default"^^xsd:string;
7474
dcterms:description "Default graph"^^xsd:string
7575
.
76-
77-
########### ROUTES RESTRICTIONS DESCRIPTION #######################################################
78-
# Following triples describe required services for routes. It is used in conditional routing.
79-
# #######################################################################################
80-
81-
82-
83-
:RolesRouteRestriction
84-
a ontos:RouteRestriction;
85-
ontos:route "/settings/roles"^^xsd:string;
86-
ontos:requiresService :UserManagerService .
87-
88-
:RdfImportRouteRestriction
89-
a ontos:RouteRestriction;
90-
ontos:route "/workbench/extraction-and-loading/import-rdf"^^xsd:string;
91-
ontos:requiresService :RdfImportService .
92-
93-
:SparqlifyRouteRestriction
94-
a ontos:RouteRestriction;
95-
ontos:route "/workbench/extraction-and-loading/sparqlify"^^xsd:string;
96-
ontos:requiresService :SparqlifyService .
97-
98-
:TripleGeoRouteRestriction
99-
a ontos:RouteRestriction;
100-
ontos:route "/workbench/extraction-and-loading/triplegeo"^^xsd:string;
101-
ontos:requiresService :TripleGeoService .
102-
103-
:FaceteRouteRestriction
104-
a ontos:RouteRestriction;
105-
ontos:route "/workbench/search-querying-and-exploration/facete"^^xsd:string;
106-
ontos:requiresService :FaceteService .
107-
108-
:MappifyRouteRestriction
109-
a ontos:RouteRestriction;
110-
ontos:route "/workbench/search-querying-and-exploration/mappify"^^xsd:string;
111-
ontos:requiresService :MappifyService .
112-
113-
:OntoWikiRouteRestriction
114-
a ontos:RouteRestriction;
115-
ontos:route "/workbench/manual-revision-and-authoring/ontowiki"^^xsd:string;
116-
ontos:requiresService :OntoWikiService .
117-
118-
:LIMESRouteRestriction
119-
a ontos:RouteRestriction;
120-
ontos:route "/workbench/linking-and-fusing/limes"^^xsd:string;
121-
ontos:requiresService :LimesService .
122-
123-
124-
:DeerRouteRestriction
125-
a ontos:RouteRestriction;
126-
ontos:route "/workbench/classification-and-enrichment/deer"^^xsd:string;
127-
ontos:requiresService :DEERService .
128-
129-
:FagiRouteRestriction
130-
a ontos:RouteRestriction;
131-
ontos:route "/workbench/linking-and-fusing/fagi-gis"^^xsd:string;
132-
ontos:requiresService :FagiGisService .
133-
134-
135-
:CoevRouteRestriction
136-
a ontos:RouteRestriction;
137-
ontos:route "/workbench/evolution-and-repair/coevolution-apply"^^xsd:string;
138-
ontos:requiresService :CoevolutionService .
76+

src/main/webapp/js/app.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,25 +208,36 @@ app.config(function($routeSegmentProvider, $routeProvider)
208208
});
209209
} else if (!$rootScope.isSystemSetUp) {
210210
$location.path('/system-setup');
211-
} else if (AccountService.getAccount().getAccountURI() != undefined && next.$$route) { //check route permissions
212-
var requiredServices = ConfigurationService.getRequiredServices(next.$$route.originalPath);
213-
if (requiredServices==null) return;
211+
} else if (AccountService.getAccount().getAccountURI() != undefined && next.$$route) {
212+
213+
// if user is admin, has allrigths to all routes
214214
if (AccountService.getAccount().isAdmin()) return;
215-
var role = AccountService.getAccount().getRole();
216-
if (role==undefined) {
217-
$location.path("/access-denied");
218-
} else {
219-
var allowedServices = role.services;
220-
console.log(allowedServices);
221-
console.log(requiredServices);
222-
for (var ind in requiredServices) {
223-
if (allowedServices.indexOf(requiredServices[ind])==-1) {
215+
216+
//check route permissions
217+
ConfigurationService.getRequiredServices(next.$$route.originalPath).then(
218+
//success
219+
function(requiredServices){
220+
// if required services is null means that no service is required, and can be accessed
221+
if (requiredServices==null) return;
222+
// else, check that required services martches the services allowed to the role
223+
var role = AccountService.getAccount().getRole();
224+
if (role==undefined) {
224225
$location.path("/access-denied");
225-
return;
226+
} else {
227+
var allowedServices = role.services;
228+
for (var ind in requiredServices) {
229+
if (allowedServices.indexOf(requiredServices[ind])==-1) {
230+
$location.path("/access-denied");
231+
return;
232+
}
233+
}
226234
}
227-
}
228-
}
229-
}else {
235+
},
236+
//error
237+
function(response){
238+
flash.error = ServerErrorResponse.getMessage(response);
239+
});
240+
}else{
230241
$location.path("/");
231242
}
232243
});

0 commit comments

Comments
 (0)