From 23da82d6eef17e2bd4ec2de497495b32fd338659 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 6 Jul 2015 17:20:22 +0200 Subject: [client] more error handling changes for BWIDM Auth --- .../src/main/java/auth/BWIDMAuthenticator.java | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java') diff --git a/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java b/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java index e4da3cc3..40c1d2eb 100644 --- a/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java +++ b/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java @@ -1,5 +1,11 @@ package auth; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; + +import org.apache.http.ParseException; +import org.apache.http.client.ClientProtocolException; import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.TAuthenticationException; @@ -7,6 +13,8 @@ import org.openslx.bwlp.thrift.iface.TInvalidTokenException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.thrifthelper.ThriftManager; +import com.google.gson.JsonSyntaxException; + import util.ShibbolethECP; import util.ShibbolethECP.ReturnCode; @@ -36,10 +44,30 @@ public class BWIDMAuthenticator implements BaseAuthenticator { @Override public void login(String username, String password, AuthenticatorCallback callback) throws TAuthenticationException { - // sanity check on the ecpUrl, should have been set - - ReturnCode ret = ShibbolethECP.doLogin(this.ecpUrl, username, password); + // try to login + ReturnCode ret = null; + try { + ret = ShibbolethECP.doLogin(this.ecpUrl, username, password); + } catch (JsonSyntaxException e) { + LOGGER.error("Could not parse JSON response from the service provider: ", e); + } catch (ClientProtocolException e) { + LOGGER.error("HTTP client protocol error: ", e); + } catch (ParseException e) { + LOGGER.error("Error parsing the raw response body from the service provider: ", e); + } catch (MalformedURLException e) { + LOGGER.error("Bad syntax of the registration URL returned by the service provider: ", e); + } catch (URISyntaxException e) { + LOGGER.error("Bad syntax of the URL to the identity provider: ", e); + } catch (IOException e) { + LOGGER.error("IO Error while communicating with the service provider: ", e); + } + // if ret is still null, some exception happened, so abort. + if (ret == null) { + LOGGER.error("Error during the ECP authentication process."); + return; + } + // else, we do have a valid ReturnCode if (ret == ReturnCode.NO_ERROR) { UserInfo userInfo; try { @@ -51,7 +79,11 @@ public class BWIDMAuthenticator implements BaseAuthenticator { LOGGER.error("Thrift transport error, see trace: ", e); return; } - callback.postLogin(userInfo); + callback.postLogin(ReturnCode.NO_ERROR, userInfo); + } else { + // else just return the ReturnCode to the GUI + // it should then show a corresponding error message! + callback.postLogin(ret, null); } } } -- cgit v1.2.3-55-g7522