diff options
author | Jonathan Bauer | 2014-12-05 15:28:55 +0100 |
---|---|---|
committer | Jonathan Bauer | 2014-12-05 15:28:55 +0100 |
commit | 304ec65d1994bb408668b215d7680273d0d7c858 (patch) | |
tree | 35c284e4fcc00d4b57c189f12ef22b216a91b146 /dozentenmodul | |
parent | [client] sort list of IdP by displayName (diff) | |
download | tutor-module-304ec65d1994bb408668b215d7680273d0d7c858.tar.gz tutor-module-304ec65d1994bb408668b215d7680273d0d7c858.tar.xz tutor-module-304ec65d1994bb408668b215d7680273d0d7c858.zip |
[client] preparations for parsing the response of the SP
Diffstat (limited to 'dozentenmodul')
-rw-r--r-- | dozentenmodul/pom.xml | 6 | ||||
-rw-r--r-- | dozentenmodul/src/main/java/util/ServiceProviderResponse.java | 14 | ||||
-rw-r--r-- | dozentenmodul/src/main/java/util/ShibbolethECP.java | 49 |
3 files changed, 68 insertions, 1 deletions
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 @@ <artifactId>ecp-client-lean</artifactId> <version>0.0.2-SNAPSHOT</version> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.2.4</version> + <scope>compile</scope> + </dependency> </dependencies> </project> 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; @@ -17,6 +27,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. */ private final static URI BWLP_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; } } |