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

Commit 75d2b42

Browse files
committed
last modifications
1 parent 8c8c249 commit 75d2b42

22 files changed

+543
-230
lines changed

src/main/java/authentication/FrameworkConfiguration.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ public class FrameworkConfiguration {
6767
*
6868
* @param context
6969
* @return
70+
* @throws IOException
7071
* @throws Exception
7172
*/
7273
public static synchronized FrameworkConfiguration getInstance(
73-
ServletContext context) throws Exception {
74+
ServletContext context) throws IOException {
7475

7576
if (instance == null) {
7677

@@ -122,9 +123,10 @@ public static synchronized FrameworkConfiguration getInstance(
122123
instance.setFrameworkUri(soln.get("uri").toString());
123124
instance.setPublicSparqlEndpoint(soln.get("endpoint")
124125
.toString());
125-
instance.setResourceNamespace(instance.getFrameworkUri()
126+
instance.setResourceNamespace(instance
127+
.getFrameworkUri()
126128
.substring(0,
127-
instance.getFrameworkUri().lastIndexOf("/")));
129+
instance.getFrameworkUri().lastIndexOf("/") + 1));
128130
}
129131
qexec.close();
130132

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

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

17+
import util.UnsupportedAuthenticationSchema;
18+
1719
public class HttpRequestManager {
1820

1921
private static final Logger log = Logger
@@ -36,7 +38,7 @@ public static String executePost(String url, String urlParameters)
3638
}
3739

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

116120
private static HttpURLConnection sendAuthorizedPost(String url,
117121
String urlParameters, WWWAuthenticateHeader wwwAuthenticateHeader,
118-
String username, String password) throws Exception {
122+
String username, String password) throws IOException,
123+
UnsupportedAuthenticationSchema {
119124
log.debug("Execute authorized POST to " + url);
120125
URL targetURL = new URL(url);
121126
HttpURLConnection connection = (HttpURLConnection) targetURL
@@ -173,11 +178,13 @@ private static WWWAuthenticateHeader getWWWAuthenticationHeader(
173178

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

src/main/java/authentication/web/RdfStoreProxy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
7272
String mode = req.getParameter("mode");
7373
String query = req.getParameter("query");
7474

75-
// System.out.println("mode " + mode);
76-
// System.out.println("username " + username);
75+
log.debug("mode " + mode);
76+
log.debug("username " + username);
7777

7878
try {
7979
RdfStoreManager rdfStoreManager;

src/main/java/rdf/SecureRdfStoreManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public SecureRdfStoreManagerImpl(String endpoint, String username, String passwo
1212
this.password = password;
1313
}
1414

15-
protected String executePost(String endpoint, String urlParameters) throws Exception {
15+
protected String executePost(String endpoint, String urlParameters) throws Exception{
1616
return HttpRequestManager.executePost(endpoint, urlParameters, username, password);
1717
}
1818
}

src/main/java/rest/Configuration.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package rest;
22

3+
import java.io.IOException;
4+
35
import javax.servlet.ServletContext;
46
import javax.ws.rs.GET;
57
import javax.ws.rs.Path;
68
import javax.ws.rs.Produces;
79
import javax.ws.rs.core.Context;
810
import javax.ws.rs.core.MediaType;
11+
import javax.ws.rs.core.Response;
912

1013
import org.apache.log4j.Logger;
1114

@@ -30,7 +33,7 @@ public class Configuration {
3033
*/
3134
@GET
3235
@Produces(MediaType.APPLICATION_JSON)
33-
public String getConfiguration(@Context ServletContext context) {
36+
public Response getConfiguration(@Context ServletContext context) {
3437

3538
FrameworkConfiguration frameworkConf;
3639
JsonObject config = null;
@@ -41,17 +44,23 @@ public String getConfiguration(@Context ServletContext context) {
4144
config.addProperty("ns", frameworkConf.getResourceNamespace());
4245
config.addProperty("defaultSettingsGraphUri",
4346
frameworkConf.getSettingsGraph());
44-
config.addProperty("groupsGraphUri",
45-
frameworkConf.getGroupsGraph());
47+
config.addProperty("groupsGraphUri", frameworkConf.getGroupsGraph());
4648
config.addProperty("frameworkOntologyNs",
4749
frameworkConf.getFrameworkOntologyNS());
4850
config.addProperty("accountsGraph",
4951
frameworkConf.getAccountsGraph());
52+
config.addProperty("sparqlEndpoint",
53+
frameworkConf.getPublicSparqlEndpoint());
54+
config.addProperty("authSparqlEndpoint",
55+
frameworkConf.getAuthSparqlEndpoint());
5056

51-
} catch (Exception e) {
57+
} catch (IOException e) {
5258
log.error(e);
5359
e.printStackTrace();
60+
return Response.status(Response.Status.EXPECTATION_FAILED)
61+
.entity("Error reading configuration files.").build();
5462
}
55-
return config.toString();
63+
return Response.ok(config.toString(), MediaType.APPLICATION_JSON)
64+
.build();
5665
}
5766
}

src/main/java/rest/WorkbenchSetup.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Response reset(@Context ServletContext context) {
6464
.entity(e.getMessage()).build();
6565
}
6666
log.info("System was reseted successfully.");
67-
return Response.ok().build();
67+
return Response.ok().entity("System reseted successfully").build();
6868
}
6969

7070
/**
@@ -101,7 +101,8 @@ public Response initialize(@Context ServletContext context) {
101101
.entity(e.getMessage()).build();
102102
}
103103
log.info("System was set up successfully.");
104-
return Response.ok().build();
104+
return Response.ok().entity("System initialized successfully")
105+
.build();
105106
}
106107
}
107108
}

src/main/java/setup/InitialSetupServlet.java

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

src/main/java/setup/RDFStoreSetupManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public void setUp(FrameworkConfiguration config, boolean reset)
128128
userManager.grantLOLook("SPARQL");
129129
} catch (Exception e) {
130130
// role is already granted
131-
e.printStackTrace();
131+
log.warn("SPARQL has already SPARQL_UPDATE rol");
132+
// e.printStackTrace();
132133
}
133134

134135
log.info(" Default Graphs creation and configuration ");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package util;
2+
3+
public class UnsupportedAuthenticationSchema extends RuntimeException {
4+
/**
5+
*
6+
*/
7+
private static final long serialVersionUID = 1L;
8+
9+
public UnsupportedAuthenticationSchema(String message) {
10+
super(message);
11+
}
12+
}

0 commit comments

Comments
 (0)