diff options
author | Simon Rettberg | 2015-08-11 16:32:07 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-11 16:32:07 +0200 |
commit | 3a91f090eab386ea37f8c4379f27a26378fbaa04 (patch) | |
tree | d3ae74dbd17e81a8183cb81518458142b5c0a77f /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java | |
parent | [server] Create proper path for file download (diff) | |
download | tutor-module-3a91f090eab386ea37f8c4379f27a26378fbaa04.tar.gz tutor-module-3a91f090eab386ea37f8c4379f27a26378fbaa04.tar.xz tutor-module-3a91f090eab386ea37f8c4379f27a26378fbaa04.zip |
[client] Improve authentication handling
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java index f944311b..60c901b2 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java @@ -10,7 +10,6 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; @@ -23,9 +22,14 @@ import javax.swing.JList; import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.Organization; +import org.openslx.bwlp.thrift.iface.SatelliteServer.Client; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TInternalServerError; +import org.openslx.bwlp.thrift.iface.WhoamiInfo; import org.openslx.dozmod.App; import org.openslx.dozmod.Config; import org.openslx.dozmod.authentication.Authenticator; +import org.openslx.dozmod.authentication.Authenticator.AuthenticationData; import org.openslx.dozmod.authentication.Authenticator.AuthenticatorCallback; import org.openslx.dozmod.authentication.EcpAuthenticator; import org.openslx.dozmod.authentication.ShibbolethEcp; @@ -273,10 +277,10 @@ public class LoginWindow extends LoginWindowLayout { final LoginWindow me = this; AuthenticatorCallback authenticatorCallback = new AuthenticatorCallback() { @Override - public void postLogin(ReturnCode returnCode, Throwable t) { + public void postLogin(ReturnCode returnCode, AuthenticationData data, Throwable t) { switch (returnCode) { case NO_ERROR: - postSuccessfulLogin(); + postSuccessfulLogin(data); break; case IDENTITY_PROVIDER_ERROR: Gui.showMessageBox(me, "IdP Error", MessageType.ERROR, LOGGER, null); @@ -332,32 +336,56 @@ public class LoginWindow extends LoginWindowLayout { /** * Functions called by doLogin is the login process succeeded. + * + * @param data */ - private void postSuccessfulLogin() { - LOGGER.info(loginType.toString() + " succeeded."); + private void postSuccessfulLogin(AuthenticationData data) { + LOGGER.info(loginType.toString() + " succeeded, token " + data.satelliteToken); - // TODO HACK HACK - Session.setSatelliteAddress("132.230.8.113"); - // TODO: Set in proper place, clear saved address if different - ThriftManager.setSatelliteAddress(Session.getSatelliteAddress()); - // Something like ThriftManager.setSatelliteAddress(Session.getSatelliteAddress()); (might need selection box) + // TODO: Show satellite selection if > 1 + //String satAddress = data.satellites.get(0).addressList.get(0); + String satAddress = "132.230.8.113"; + Client client = ThriftManager.getNewSatClient(satAddress); + if (client == null) { + Gui.showMessageBox(this, "Login erfolgreich, aber der Satellit antwortet nicht", + MessageType.ERROR, LOGGER, null); + return; + } + WhoamiInfo whoami = null; Exception e = null; try { - ThriftManager.getSatClient().isAuthenticated(Session.getSatelliteToken()); + whoami = client.whoami(data.satelliteToken); + } catch (TAuthorizationException e1) { + Gui.showMessageBox(this, + "Authentifizierung erfolgreich, der Satellit verweigert jedoch die Verbindung.\n\n" + + "Grund: " + e1.number.toString() + " (" + e1.message + ")", MessageType.ERROR, + null, null); + return; + } catch (TInternalServerError e1) { + Gui.showMessageBox( + this, + "Authentifizierung erfolgreich, bei der Kommunikation mit dem Satelliten trat jedoch ein interner Server-Fehler auf.", + MessageType.ERROR, LOGGER, e); + return; + } catch (Exception ex) { + e = ex; + } + if (whoami != null) { + Session.initialize(whoami, satAddress, data.satelliteToken, data.masterToken); + ThriftManager.setSatelliteAddress(Session.getSatelliteAddress()); // now read the config to see if the user already agreed to the disclaimer // if (DisclaimerWindow.shouldBeShown()) // VirtualizerNoticeWindow.open(); // Save session (TODO: Extra checkbox) if (saveUsernameCheck.isSelected()) { - Config.saveCurrentSession(Session.getSatelliteAddress(), Session.getSatelliteToken()); + Config.saveCurrentSession(Session.getSatelliteAddress(), Session.getSatelliteToken(), + Session.getMasterToken()); } - LOGGER.debug("Closing..."); dispose(); return; - } catch (Exception ex) { - e = ex; } - Gui.showMessageBox(this, "Login succeeded, but Satellite rejected the session token. :-(", + Gui.showMessageBox(this, + "Authentifizierung erfolgreich, aber der Satellit akzeptiert das Sitzungstoken nicht.", MessageType.ERROR, LOGGER, e); } |