summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/util/ShibbolethECP.java
diff options
context:
space:
mode:
authorJonathan Bauer2015-07-06 17:20:22 +0200
committerJonathan Bauer2015-07-06 17:20:22 +0200
commit23da82d6eef17e2bd4ec2de497495b32fd338659 (patch)
tree3d48cb028951586989786db4e8a0f020e39f6576 /dozentenmodul/src/main/java/util/ShibbolethECP.java
parent[client] reworked exceptions handling of BWIDM auth (diff)
downloadtutor-module-23da82d6eef17e2bd4ec2de497495b32fd338659.tar.gz
tutor-module-23da82d6eef17e2bd4ec2de497495b32fd338659.tar.xz
tutor-module-23da82d6eef17e2bd4ec2de497495b32fd338659.zip
[client] more error handling changes for BWIDM Auth
Diffstat (limited to 'dozentenmodul/src/main/java/util/ShibbolethECP.java')
-rw-r--r--dozentenmodul/src/main/java/util/ShibbolethECP.java90
1 files changed, 32 insertions, 58 deletions
diff --git a/dozentenmodul/src/main/java/util/ShibbolethECP.java b/dozentenmodul/src/main/java/util/ShibbolethECP.java
index 67936906..7844a51e 100644
--- a/dozentenmodul/src/main/java/util/ShibbolethECP.java
+++ b/dozentenmodul/src/main/java/util/ShibbolethECP.java
@@ -35,23 +35,23 @@ public class ShibbolethECP {
private static final Gson GSON = new GsonBuilder().create();
/**
- *
+ * ServiceProviderResponse Object representing the last response we received
*/
- private static ServiceProviderResponse _lastResponse = null;
+ private static ServiceProviderResponse lastResponse = null;
/**
* URL for bwLehrpool registration
*/
- private static URL _registrationUrl = null;
+ private static URL registrationUrl = null;
/**
* 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_UNREG(2, "User not registered to use bwLehrpool"),
+ IDP_ERROR(1, "Authentication against the identity provider failed."),
+ UNREG_ERROR(2, "User not registered to use bwLehrpool."),
ERROR_SP(3, "Invalid resource of the service provider."),
ERROR_URL(4, "Invalid URL received from master server."),
- ERROR_OTHER(5, "Internal class error.");
+ ERROR_OTHER(5, "Internal error.");
private final int id;
private final String msg;
@@ -87,7 +87,7 @@ public class ShibbolethECP {
}
public static ServiceProviderResponse getResponse() {
- return _lastResponse;
+ return lastResponse;
}
/**
* Fetches the resource
@@ -102,7 +102,9 @@ public class ShibbolethECP {
* true if login worked, false otherwise.
* @throws TAuthenticationException
*/
- public static ReturnCode doLogin(final String idpUrl, final String user, final String pass) throws TAuthenticationException {
+ public static ReturnCode doLogin(final String idpUrl, final String user, final String pass)
+ throws TAuthenticationException, URISyntaxException, ClientProtocolException, IOException,
+ ParseException, JsonSyntaxException, MalformedURLException {
// first lets do some sanity checks
if (BWLP_SP == null) {
@@ -123,76 +125,48 @@ public class ShibbolethECP {
}
// now init the authenticator for that idp and our static sp
- ECPAuthenticator auth = null;
- try {
- auth = new ECPAuthenticator(user, pass, new URI(idpUrl), BWLP_SP);
- } catch (URISyntaxException e) {
- LOGGER.error("Bad URI syntax, see trace: ", e);
- return ReturnCode.ERROR_OTHER;
- }
+ final ECPAuthenticator auth = new ECPAuthenticator(user, pass, new URI(idpUrl), BWLP_SP);
+
try {
auth.authenticate();
} catch (ECPAuthenticationException e) {
LOGGER.error("ECP Authentication Exception, see trace: ", e);
- throw new TAuthenticationException(AuthenticationError.GENERIC_ERROR, "ECP client failed to authenticate.");
+ throw new TAuthenticationException(AuthenticationError.GENERIC_ERROR, e.getMessage());
}
- // here test again for the SPURL
- 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 ReturnCode.ERROR_OTHER;
- } catch (IOException e) {
- LOGGER.error("I/O error, see trace: ", e);
- return ReturnCode.ERROR_OTHER;
- }
+ // here test again for the SP's URL
+ final HttpGet testSp = new HttpGet(BWLP_SP);
+ final HttpResponse response = auth.getHttpClient().execute(testSp);
+
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 ReturnCode.ERROR_OTHER;
- } catch (IOException e) {
- LOGGER.error("I/O error, see trace: ", e);
- return ReturnCode.ERROR_OTHER;
- }
- _lastResponse = null;
- try {
- _lastResponse = GSON.fromJson(responseBody, ServiceProviderResponse.class);
- } catch (JsonSyntaxException e) {
- LOGGER.error("Bad JSON syntax, see trace: ", e);
- return ReturnCode.ERROR_SP;
- }
+ final String responseBody = EntityUtils.toString(response.getEntity());
+
+ lastResponse = GSON.fromJson(responseBody, ServiceProviderResponse.class);
+
// TODO: here we will need to parse the answer accordingly.
// no errors, meaning everything worked fine.
- if (_lastResponse.status.equals("unregistered")) {
- try {
- _registrationUrl = new URL(_lastResponse.url);
- } catch (MalformedURLException e) {
- LOGGER.error("URL returned by masterserver is malformed, see trace: " + e);
- return ReturnCode.ERROR_URL;
- }
- return ReturnCode.ERROR_UNREG;
+ if (lastResponse.status.equals("unregistered")) {
+ registrationUrl = new URL(lastResponse.url);
+ return ReturnCode.UNREG_ERROR;
}
// TODO the rest of the cases...
- if (_lastResponse.status.equals("error")) {
- LOGGER.error("Server side error: " + _lastResponse.error);
+ if (lastResponse.status.equals("error")) {
+ LOGGER.error("Server side error: " + lastResponse.error);
return ReturnCode.ERROR_OTHER;
}
- if (_lastResponse.status.equals("anonymous")) {
+ if (lastResponse.status.equals("anonymous")) {
LOGGER.error("IdP did not forward user account information to SP. Contact developper.");
return ReturnCode.ERROR_OTHER;
}
- if (_lastResponse.status.equals("ok")) {
+ if (lastResponse.status.equals("ok")) {
return ReturnCode.NO_ERROR;
}
// still here? then something else went wrong
return ReturnCode.ERROR_OTHER;
}
+ /**
+ * @return Registration URL given by the SP.
+ */
public static URL getRegistrationUrl() {
- return _registrationUrl;
+ return registrationUrl;
}
}