diff options
| author | Jonathan Bauer | 2015-07-06 14:31:28 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-07-06 14:31:28 +0200 |
| commit | e270e212f3849b12e1a1d2e9f03a8243b1e9ecc7 (patch) | |
| tree | ae34be79ebfea206718a71e0f72712776c9bcb6c /dozentenmodul/src/main/java | |
| parent | [client] Add classes for caching of data fetched via thrift (diff) | |
| download | tutor-module-e270e212f3849b12e1a1d2e9f03a8243b1e9ecc7.tar.gz tutor-module-e270e212f3849b12e1a1d2e9f03a8243b1e9ecc7.tar.xz tutor-module-e270e212f3849b12e1a1d2e9f03a8243b1e9ecc7.zip | |
[client] reworked exceptions handling of BWIDM auth
Diffstat (limited to 'dozentenmodul/src/main/java')
4 files changed, 27 insertions, 23 deletions
diff --git a/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java b/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java index a5a99da7..e4da3cc3 100644 --- a/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java +++ b/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java @@ -2,13 +2,13 @@ package auth; import org.apache.log4j.Logger; import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.TAuthenticationException; import org.openslx.bwlp.thrift.iface.TInvalidTokenException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.thrifthelper.ThriftManager; import util.ShibbolethECP; import util.ShibbolethECP.ReturnCode; -import edu.kit.scc.dei.ecplean.ECPAuthenticationException; /** * @author Jonathan Bauer @@ -35,16 +35,11 @@ public class BWIDMAuthenticator implements BaseAuthenticator { @Override public void login(String username, String password, - AuthenticatorCallback callback) throws ECPAuthenticationException { + AuthenticatorCallback callback) throws TAuthenticationException { // sanity check on the ecpUrl, should have been set - ReturnCode ret; - try { - ret = ShibbolethECP.doLogin(this.ecpUrl, username, password); - } catch (ECPAuthenticationException e) { - LOGGER.error("Bad credentials, see trace: ", e); - throw e; - } + ReturnCode ret = ShibbolethECP.doLogin(this.ecpUrl, username, password); + if (ret == ReturnCode.NO_ERROR) { UserInfo userInfo; try { diff --git a/dozentenmodul/src/main/java/auth/BaseAuthenticator.java b/dozentenmodul/src/main/java/auth/BaseAuthenticator.java index bebbff02..d52c5343 100644 --- a/dozentenmodul/src/main/java/auth/BaseAuthenticator.java +++ b/dozentenmodul/src/main/java/auth/BaseAuthenticator.java @@ -1,9 +1,8 @@ package auth; +import org.openslx.bwlp.thrift.iface.TAuthenticationException; import org.openslx.bwlp.thrift.iface.UserInfo; -import edu.kit.scc.dei.ecplean.ECPAuthenticationException; - /** * @author Jonathan Bauer * @@ -27,5 +26,5 @@ public interface BaseAuthenticator { * @param callback The callback function to be called after the login * @throws ECPAuthenticationException */ - void login(String username, String password, AuthenticatorCallback callback) throws ECPAuthenticationException; + void login(String username, String password, AuthenticatorCallback callback) throws TAuthenticationException; }
\ No newline at end of file diff --git a/dozentenmodul/src/main/java/gui/core/LoginGUI.java b/dozentenmodul/src/main/java/gui/core/LoginGUI.java index 5c329d5d..6ca06518 100644 --- a/dozentenmodul/src/main/java/gui/core/LoginGUI.java +++ b/dozentenmodul/src/main/java/gui/core/LoginGUI.java @@ -10,6 +10,7 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Shell; import org.openslx.bwlp.thrift.iface.Organization; +import org.openslx.bwlp.thrift.iface.TAuthenticationException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.thrifthelper.ThriftManager; @@ -24,6 +25,7 @@ public class LoginGUI extends LoginComposite { private final String NO_USERNAME = "Kein Benutzername angegeben!"; private final String NO_PASSWORD = "Kein Passwort angegeben!"; + private final String BAD_AUTH = "Authentifizierung fehlgeschlagen!"; private String username = null; private String password = null; @@ -148,14 +150,20 @@ public class LoginGUI extends LoginComposite { case BWIDM: BWIDMAuthenticator bwidmAuth = new BWIDMAuthenticator( selectedOrg.getEcpUrl()); - bwidmAuth.login(username, password, new AuthenticatorCallback() { - @Override - public void postLogin(UserInfo user) { - LOGGER.info(user.firstName + " " + user.lastName); - if (user != null) - GuiManager.addContent(new DisclaimerComposite(getShell())); - } - }); + try { + bwidmAuth.login(username, password, new AuthenticatorCallback() { + @Override + public void postLogin(UserInfo user) { + LOGGER.info(user.firstName + " " + user.lastName); + if (user != null) + GuiManager.addContent(new DisclaimerComposite(getShell())); + } + }); + } catch (TAuthenticationException e) { + LOGGER.error("Authentication error, see trace: ", e); + GuiManager.showMessage(BAD_AUTH); + return; + } break; case BWLP: LOGGER.info("bwlp"); diff --git a/dozentenmodul/src/main/java/util/ShibbolethECP.java b/dozentenmodul/src/main/java/util/ShibbolethECP.java index f3e35400..67936906 100644 --- a/dozentenmodul/src/main/java/util/ShibbolethECP.java +++ b/dozentenmodul/src/main/java/util/ShibbolethECP.java @@ -12,6 +12,8 @@ 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 org.openslx.bwlp.thrift.iface.AuthenticationError; +import org.openslx.bwlp.thrift.iface.TAuthenticationException; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -98,9 +100,9 @@ public class ShibbolethECP { * Password as String. * @return * true if login worked, false otherwise. - * @throws ECPAuthenticationException + * @throws TAuthenticationException */ - public static ReturnCode doLogin(final String idpUrl, final String user, final String pass) throws ECPAuthenticationException { + public static ReturnCode doLogin(final String idpUrl, final String user, final String pass) throws TAuthenticationException { // first lets do some sanity checks if (BWLP_SP == null) { @@ -132,7 +134,7 @@ public class ShibbolethECP { auth.authenticate(); } catch (ECPAuthenticationException e) { LOGGER.error("ECP Authentication Exception, see trace: ", e); - throw e; + throw new TAuthenticationException(AuthenticationError.GENERIC_ERROR, "ECP client failed to authenticate."); } // here test again for the SPURL HttpGet testSp = new HttpGet(BWLP_SP); |
