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/src/main/java/util/ShibbolethECP.java | |
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/src/main/java/util/ShibbolethECP.java')
-rw-r--r-- | dozentenmodul/src/main/java/util/ShibbolethECP.java | 49 |
1 files changed, 48 insertions, 1 deletions
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; } } |