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

Commit 3262582

Browse files
committed
merged and updated stuff with new configuration
1 parent be27be7 commit 3262582

19 files changed

+155
-293
lines changed

src/main/java/authentication/web/HttpRequestManager.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.apache.commons.codec.digest.DigestUtils;
1515
import org.apache.log4j.Logger;
1616

17-
import util.UnsupportedAuthenticationSchema;
18-
1917
public class HttpRequestManager {
2018

2119
private static final Logger log = Logger
@@ -38,7 +36,7 @@ public static String executePost(String url, String urlParameters)
3836
}
3937

4038
public static String executePost(String url, String urlParameters,
41-
String username, String password) throws IOException {
39+
String username, String password) throws Exception {
4240
// TODO: May be try to do Authorized post by default first ??? to avoid
4341
// doing two queries? are all the queries made by the generator will use
4442
// the
@@ -73,10 +71,8 @@ public static String executePost(String url, String urlParameters,
7371
throw new HTTPException(responseCode);
7472
}
7573
} else
76-
throw new UnsupportedAuthenticationSchema(
77-
"Unsupported authentication type: "
78-
+ wwwAuthenticateHeader
79-
.getAuthenticationScheme());
74+
throw new Exception("Unsupported authentication type: "
75+
+ wwwAuthenticateHeader.getAuthenticationScheme());
8076
case 400: // bad request
8177
log.error(connection.getResponseCode() + "\n\t "
8278
+ connection.getResponseMessage() + "\n\t url:" + url
@@ -119,8 +115,7 @@ private static HttpURLConnection sendPost(String url, String urlParameters)
119115

120116
private static HttpURLConnection sendAuthorizedPost(String url,
121117
String urlParameters, WWWAuthenticateHeader wwwAuthenticateHeader,
122-
String username, String password) throws IOException,
123-
UnsupportedAuthenticationSchema {
118+
String username, String password) throws Exception {
124119
log.debug("Execute authorized POST to " + url);
125120
URL targetURL = new URL(url);
126121
HttpURLConnection connection = (HttpURLConnection) targetURL
@@ -178,13 +173,11 @@ private static WWWAuthenticateHeader getWWWAuthenticationHeader(
178173

179174
private static String getDigestAuthorizationProperty(String endpoint,
180175
WWWAuthenticateHeader wwwAuthenticateHeader, String username,
181-
String password, String requestMethod)
182-
throws UnsupportedAuthenticationSchema {
176+
String password, String requestMethod) throws Exception {
183177
if (!wwwAuthenticateHeader.isDigest())
184-
throw new UnsupportedAuthenticationSchema(
185-
"Unexpected authentication scheme "
186-
+ wwwAuthenticateHeader.getAuthenticationScheme()
187-
+ ", Digest expected");
178+
throw new Exception("Unexpected authentication scheme "
179+
+ wwwAuthenticateHeader.getAuthenticationScheme()
180+
+ ", Digest expected");
188181
String nc = "00000001";
189182
String cnonce = DigestUtils.md5Hex(Long.toString(System
190183
.currentTimeMillis()));

src/main/java/rest/Configuration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public Response getConfiguration(@Context ServletContext context) {
5353
frameworkConf.getPublicSparqlEndpoint());
5454
config.addProperty("authSparqlEndpoint",
5555
frameworkConf.getAuthSparqlEndpoint());
56+
config.addProperty("flagPath",
57+
context.getInitParameter("framework-setup-path"));
5658

5759
} catch (IOException e) {
5860
log.error(e);

src/main/java/rest/WorkbenchSetup.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class WorkbenchSetup {
2525

2626
private static final Logger log = Logger.getLogger(WorkbenchSetup.class);
2727

28+
private @Context
29+
ServletContext context;
30+
2831
/**
2932
* Get the status of the setup
3033
*
@@ -33,7 +36,8 @@ public class WorkbenchSetup {
3336
@GET
3437
@Produces(MediaType.TEXT_PLAIN)
3538
public Response isSetuUp() {
36-
RDFStoreSetupManager setupManager = new RDFStoreSetupManager();
39+
RDFStoreSetupManager setupManager = new RDFStoreSetupManager(
40+
context.getInitParameter("framework-setup-path"));
3741
return Response.ok(setupManager.isSetUp(), MediaType.TEXT_PLAIN)
3842
.build();
3943
}
@@ -46,7 +50,8 @@ public Response isSetuUp() {
4650
*/
4751
@POST
4852
public Response reset(@Context ServletContext context) {
49-
RDFStoreSetupManager setupManager = new RDFStoreSetupManager();
53+
RDFStoreSetupManager setupManager = new RDFStoreSetupManager(
54+
context.getInitParameter("framework-setup-path"));
5055
FrameworkConfiguration frameworkConfiguration = null;
5156
try {
5257
frameworkConfiguration = FrameworkConfiguration
@@ -75,7 +80,8 @@ public Response reset(@Context ServletContext context) {
7580
*/
7681
@PUT
7782
public Response initialize(@Context ServletContext context) {
78-
RDFStoreSetupManager setupManager = new RDFStoreSetupManager();
83+
RDFStoreSetupManager setupManager = new RDFStoreSetupManager(
84+
context.getInitParameter("framework-setup-path"));
7985

8086
if (setupManager.isSetUp()) {
8187
log.info("System is already set up. To reset system use PUT method");

src/main/java/setup/RDFStoreSetupManager.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public class RDFStoreSetupManager {
3333
private static final Logger log = Logger
3434
.getLogger(RDFStoreSetupManager.class);
3535

36-
private File catalinaBase = new File(System.getProperty("catalina.base"))
37-
.getAbsoluteFile();
38-
// TODO: move a file outside the application (i.e. /etc/ontos)
39-
private File initFile = new File(catalinaBase.getAbsoluteFile(),
40-
"webapps/generator/WEB-INF/init.txt");
36+
private File initFile;
37+
38+
public RDFStoreSetupManager(String path) {
39+
initFile = new File(path, "init.txt");
40+
}
4141

4242
// set rdf store up using configuration; if reset==true than clear (using
4343
// config) rdf store and set up once again
@@ -165,6 +165,7 @@ public void setUp(FrameworkConfiguration config, boolean reset)
165165
queryString = "PREFIX foaf:<http://xmlns.com/foaf/0.1/> "
166166
+ "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
167167
+ "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> "
168+
+ "PREFIX void: <http://rdfs.org/ns/void#> "
168169
+ "PREFIX lds:<http://stack.linkeddata.org/ldis-schema/>"
169170
+ " CONSTRUCT { <"
170171
+ config.getFrameworkUri()
@@ -173,17 +174,29 @@ public void setUp(FrameworkConfiguration config, boolean reset)
173174
+ config.getFrameworkUri()
174175
+ "> lds:integrates ?component ."
175176
+ "?component rdfs:label ?label . ?component rdf:type ?type . "
176-
+ "?component lds:providesService ?service . ?service rdf:type ?servicetype ."
177-
+ "?service lds:serviceUrl ?serviceUrl .} "
177+
+ "?component lds:providesService ?service . "
178+
+ "?service rdf:type ?servicetype ."
179+
+ "?service rdfs:label ?servicelabel ."
180+
+ "?service void:sparqlEndpoint ?serviceendpoint ."
181+
+ "?service lds:serviceUrl ?serviceUrl ."
182+
+ "} "
178183
+ " WHERE { <"
179184
+ config.getFrameworkUri()
180185
+ "> ?p ?o ."
181186
+ "<"
182187
+ config.getFrameworkUri()
183188
+ "> lds:integrates ?component ."
184189
+ "?component rdfs:label ?label . ?component rdf:type ?type . "
185-
+ "?component lds:providesService ?service . ?service rdf:type ?servicetype ."
186-
+ "?service lds:serviceUrl ?serviceUrl .}";
190+
+ "?component lds:providesService ?service . "
191+
+ "?service rdf:type ?servicetype ."
192+
+ "?service lds:serviceUrl ?serviceUrl ."
193+
+ "OPTIONAL { "
194+
+ " ?service rdfs:label ?servicelabel ."
195+
+ " ?service void:sparqlEndpoint ?serviceendpoint "
196+
+ " }"
197+
+ "}";
198+
199+
log.debug(queryString);
187200
QueryExecution qexec = QueryExecutionFactory.create(queryString,
188201
configurationModel);
189202
Model triples = qexec.execConstruct();
@@ -239,10 +252,16 @@ public void setUp(FrameworkConfiguration config, boolean reset)
239252
}
240253
qexec.close();
241254

242-
boolean created = initFile.createNewFile();
243-
if (!created)
244-
throw new Exception("Failed to create init flag file "
245-
+ initFile.getPath());
255+
try {
256+
boolean created = initFile.createNewFile();
257+
if (!created) {
258+
log.error("Failed to create init flag file "
259+
+ initFile.getPath());
260+
}
261+
} catch (Exception e) {
262+
log.error("Failed to create init flag file " + initFile.getPath());
263+
throw new Exception(e);
264+
}
246265

247266
log.info("System was initialized successfully.");
248267
}
@@ -290,6 +309,8 @@ public void clear(FrameworkConfiguration config) throws Exception {
290309
}
291310

292311
public boolean isSetUp() {
312+
log.info("Checking if " + initFile.getPath() + initFile.getName()
313+
+ " exists");
293314
return initFile.exists();
294315
}
295316
}

src/main/java/util/UnsupportedAuthenticationSchema.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
@prefix : <http://***PROJECT_URL***/resource/> .
2-
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .
3-
@prefix dcmit: <http://purl.org/dc/dcmitype/> .
42
@prefix dcterms: <http://purl.org/dc/terms/> .
53
@prefix lds: <http://stack.linkeddata.org/ldis-schema/> .
6-
@prefix owl: <http://www.w3.org/2002/07/owl#> .
74
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
85
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
9-
@prefix schema: <http://schema.org/> .
106
@prefix sd: <http://www.w3.org/ns/sparql-service-description#> .
117
@prefix void: <http://rdfs.org/ns/void#> .
128
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
139
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
1410
@prefix ontos: <http://ldiw.ontos.com/ontology/> .
15-
@prefix acl: <http://www.w3.org/ns/auth/acl#> .
1611

1712
########### ABOUT THIS FILE #############################################################
1813
# This file contains the default set-up of components in the framework;

0 commit comments

Comments
 (0)