From 304ec65d1994bb408668b215d7680273d0d7c858 Mon Sep 17 00:00:00 2001
From: Jonathan Bauer
Date: Fri, 5 Dec 2014 15:28:55 +0100
Subject: [client] preparations for parsing the response of the SP
---
dozentenmodul/pom.xml | 6 +++
.../main/java/util/ServiceProviderResponse.java | 14 +++++++
.../src/main/java/util/ShibbolethECP.java | 49 +++++++++++++++++++++-
3 files changed, 68 insertions(+), 1 deletion(-)
create mode 100644 dozentenmodul/src/main/java/util/ServiceProviderResponse.java
(limited to 'dozentenmodul')
diff --git a/dozentenmodul/pom.xml b/dozentenmodul/pom.xml
index 2ceff87a..dd7c9523 100644
--- a/dozentenmodul/pom.xml
+++ b/dozentenmodul/pom.xml
@@ -254,6 +254,12 @@
ecp-client-lean
0.0.2-SNAPSHOT
+
+ com.google.code.gson
+ gson
+ 2.2.4
+ compile
+
diff --git a/dozentenmodul/src/main/java/util/ServiceProviderResponse.java b/dozentenmodul/src/main/java/util/ServiceProviderResponse.java
new file mode 100644
index 00000000..62819ded
--- /dev/null
+++ b/dozentenmodul/src/main/java/util/ServiceProviderResponse.java
@@ -0,0 +1,14 @@
+package util;
+
+public class ServiceProviderResponse {
+ private String status;
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String sTATUS) {
+ status = sTATUS;
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/util/ShibbolethECP.java b/dozentenmodul/src/main/java/util/ShibbolethECP.java
index 2bc9494f..87f1c57a 100644
--- a/dozentenmodul/src/main/java/util/ShibbolethECP.java
+++ b/dozentenmodul/src/main/java/util/ShibbolethECP.java
@@ -1,10 +1,20 @@
package util;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import org.apache.http.HttpResponse;
+import org.apache.http.ParseException;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonSyntaxException;
+
import edu.kit.scc.dei.ecplean.ECPAuthenticationException;
import edu.kit.scc.dei.ecplean.ECPAuthenticator;
@@ -16,6 +26,11 @@ public class ShibbolethECP {
*/
private final static Logger LOGGER = Logger.getLogger(ShibbolethECP.class);
+ /**
+ * Static gson object for (de)serialization
+ */
+ private static final Gson GSON = new GsonBuilder().create();
+
/**
* Static URI to the SP.
*/
@@ -70,6 +85,7 @@ public class ShibbolethECP {
auth = new ECPAuthenticator(user, pass, new URI(idpUrl), BWLP_SP);
} catch (URISyntaxException e) {
LOGGER.error("Bad URI syntax, see trace: ", e);
+ return false;
}
if (auth == null) {
LOGGER.error("Initialising ECP authentication failed, aborting...");
@@ -81,8 +97,39 @@ public class ShibbolethECP {
LOGGER.error("ECP Authentication Exception, see trace: ", e);
return false;
}
+ // here test again for the SPURL
+ HttpGet testSp = new HttpGet("https://bwlp-masterserver.ruf.uni-freiburg.de/test.json");
+ HttpResponse response = null;
+ try {
+ response = auth.getHttpClient().execute(testSp);
+ } catch (ClientProtocolException e) {
+ LOGGER.error("Bad protocol, see trace: ", e);
+ return false;
+ } catch (IOException e) {
+ LOGGER.error("I/O error, see trace: ", e);
+ return false;
+ }
+ LOGGER.debug("SP request returned: " + response.getStatusLine());
+ String responseBody = null;
+ try {
+ responseBody = EntityUtils.toString(response.getEntity());
+ } catch (ParseException e) {
+ LOGGER.error("Parsing error, see trace: ", e);
+ return false;
+ } catch (IOException e) {
+ LOGGER.error("I/O error, see trace: ", e);
+ return false;
+ }
+ ServiceProviderResponse spr = null;
+ try {
+ spr = GSON.fromJson(responseBody, ServiceProviderResponse.class);
+ } catch (JsonSyntaxException e) {
+ LOGGER.error("Bad JSON syntax, see trace: ", e);
+ return false;
+ }
+ LOGGER.debug("SP JSON STATUS: " + spr.getStatus());
// TODO: here we will need to parse the answer accordingly.
// no errors, meaning everything worked fine.
- return true;
+ return spr.getStatus().equals("funzt") ? true : false;
}
}
--
cgit v1.2.3-55-g7522