summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/util/ShibbolethECP.java
diff options
context:
space:
mode:
authorJonathan Bauer2014-12-05 17:28:05 +0100
committerJonathan Bauer2014-12-05 17:28:05 +0100
commite6abb633dcb406eccc993fbc5a20e28427c7f4a2 (patch)
treec8313ec962e1425eba9640e7652e6e440ad1c3c9 /dozentenmodul/src/main/java/util/ShibbolethECP.java
parent[client] preparations for parsing the response of the SP (diff)
downloadtutor-module-e6abb633dcb406eccc993fbc5a20e28427c7f4a2.tar.gz
tutor-module-e6abb633dcb406eccc993fbc5a20e28427c7f4a2.tar.xz
tutor-module-e6abb633dcb406eccc993fbc5a20e28427c7f4a2.zip
[client] improved error handling of ShibboECP.
Now differentiate between auth error (ERROR_IDP) and resource error (ERROR_SP) NO_ERROR indicates it all worked. ERROR_OTHER indicates an internal error (~ Exception)
Diffstat (limited to 'dozentenmodul/src/main/java/util/ShibbolethECP.java')
-rw-r--r--dozentenmodul/src/main/java/util/ShibbolethECP.java59
1 files changed, 40 insertions, 19 deletions
diff --git a/dozentenmodul/src/main/java/util/ShibbolethECP.java b/dozentenmodul/src/main/java/util/ShibbolethECP.java
index 87f1c57a..3dea9e3e 100644
--- a/dozentenmodul/src/main/java/util/ShibbolethECP.java
+++ b/dozentenmodul/src/main/java/util/ShibbolethECP.java
@@ -18,7 +18,6 @@ import com.google.gson.JsonSyntaxException;
import edu.kit.scc.dei.ecplean.ECPAuthenticationException;
import edu.kit.scc.dei.ecplean.ECPAuthenticator;
-
public class ShibbolethECP {
/**
@@ -32,6 +31,32 @@ public class ShibbolethECP {
private static final Gson GSON = new GsonBuilder().create();
/**
+ * Return codes
+ */
+ public static enum ReturnCode {
+ NO_ERROR(0, "Authentication against the identity provider and request of the service provider resource worked."),
+ ERROR_IDP(1, "Authentication against the identity provider failed."),
+ ERROR_SP(2, "Invalid resource of the service provider."),
+ ERROR_OTHER(3, "Internal class error.");
+
+ private final int id;
+ private final String msg;
+
+ ReturnCode(int id, String msg) {
+ this.id = id;
+ this.msg = msg;
+ }
+
+ public int getId() {
+ return this.id;
+ }
+
+ public String getMsg() {
+ return this.msg;
+ }
+ }
+
+ /**
* Static URI to the SP.
*/
private final static URI BWLP_SP;
@@ -59,24 +84,24 @@ public class ShibbolethECP {
* @return
* true if login worked, false otherwise.
*/
- public static Boolean doLogin(final String idpUrl, final String user, final String pass) {
+ public static ReturnCode doLogin(final String idpUrl, final String user, final String pass) {
// first lets do some sanity checks
if (BWLP_SP == null) {
LOGGER.error("URI to service provider is not set. Check the initialization of 'BWLP_SP'.");
- return false;
+ return ReturnCode.ERROR_OTHER;
}
if (idpUrl == null) {
LOGGER.error("Identity provider is not set, did you initialize this class correctly?");
- return false;
+ return ReturnCode.ERROR_OTHER;
}
if (user == null) {
LOGGER.error("No username given, aborting...");
- return false;
+ return ReturnCode.ERROR_OTHER;
}
if (pass == null) {
LOGGER.error("No password given, aborting...");
- return false;
+ return ReturnCode.ERROR_OTHER;
}
// now init the authenticator for that idp and our static sp
@@ -85,29 +110,25 @@ 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;
+ return ReturnCode.ERROR_OTHER;
}
- if (auth == null) {
- LOGGER.error("Initialising ECP authentication failed, aborting...");
- return false;
- }
try {
auth.authenticate();
} catch (ECPAuthenticationException e) {
LOGGER.error("ECP Authentication Exception, see trace: ", e);
- return false;
+ return ReturnCode.ERROR_IDP;
}
// here test again for the SPURL
- HttpGet testSp = new HttpGet("https://bwlp-masterserver.ruf.uni-freiburg.de/test.json");
+ HttpGet testSp = new HttpGet(BWLP_SP);
HttpResponse response = null;
try {
response = auth.getHttpClient().execute(testSp);
} catch (ClientProtocolException e) {
LOGGER.error("Bad protocol, see trace: ", e);
- return false;
+ return ReturnCode.ERROR_OTHER;
} catch (IOException e) {
LOGGER.error("I/O error, see trace: ", e);
- return false;
+ return ReturnCode.ERROR_OTHER;
}
LOGGER.debug("SP request returned: " + response.getStatusLine());
String responseBody = null;
@@ -115,21 +136,21 @@ public class ShibbolethECP {
responseBody = EntityUtils.toString(response.getEntity());
} catch (ParseException e) {
LOGGER.error("Parsing error, see trace: ", e);
- return false;
+ return ReturnCode.ERROR_OTHER;
} catch (IOException e) {
LOGGER.error("I/O error, see trace: ", e);
- return false;
+ return ReturnCode.ERROR_OTHER;
}
ServiceProviderResponse spr = null;
try {
spr = GSON.fromJson(responseBody, ServiceProviderResponse.class);
} catch (JsonSyntaxException e) {
LOGGER.error("Bad JSON syntax, see trace: ", e);
- return false;
+ return ReturnCode.ERROR_SP;
}
LOGGER.debug("SP JSON STATUS: " + spr.getStatus());
// TODO: here we will need to parse the answer accordingly.
// no errors, meaning everything worked fine.
- return spr.getStatus().equals("funzt") ? true : false;
+ return spr.getStatus().equals("funzt") ? ReturnCode.NO_ERROR : ReturnCode.ERROR_SP;
}
}