diff options
author | Jonathan Bauer | 2015-08-28 15:51:57 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-08-28 15:51:57 +0200 |
commit | d03ff198454503716d0654d361d99f859326b904 (patch) | |
tree | 2edf0af0f59bd7321aa8e4d74c14ef8d76684014 /dozentenmodul | |
parent | [server] Thrift API changed (diff) | |
download | tutor-module-d03ff198454503716d0654d361d99f859326b904.tar.gz tutor-module-d03ff198454503716d0654d361d99f859326b904.tar.xz tutor-module-d03ff198454503716d0654d361d99f859326b904.zip |
[client] merged the session initializing stuff in ThriftActions.initSession
Diffstat (limited to 'dozentenmodul')
3 files changed, 95 insertions, 65 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java index bd6775a7..7da7ccdc 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -50,6 +50,7 @@ import org.openslx.dozmod.gui.window.VirtualizerNoticeWindow; import org.openslx.dozmod.state.UploadWizardState; import org.openslx.dozmod.thrift.GuiErrorCallback; import org.openslx.dozmod.thrift.Session; +import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.util.FormatHelper; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; @@ -214,30 +215,12 @@ public abstract class MainWindow { mainWindow.setLocationRelativeTo(null); mainWindow.setVisible(true); - // here we can check for Session information - SavedSession session = Config.getSavedSession(); - if (session != null) { - // Wait for proxy server init - App.waitForInit(); - try { - WhoamiInfo whoami = ThriftManager.getNewSatelliteClient( - GraphicalCertHandler.getSslContext(session.address), session.address, - App.THRIFT_SSL_PORT, App.THRIFT_TIMEOUT_MS).whoami(session.token); - Session.initialize(whoami, session.address, session.token, session.masterToken); - ThriftManager.setSatelliteAddress( - GraphicalCertHandler.getSslContext(Session.getSatelliteAddress()), - Session.getSatelliteAddress(), App.THRIFT_SSL_PORT, App.THRIFT_TIMEOUT_MS); - LOGGER.info("Saved session used for resume."); - } catch (Exception e1) { - LOGGER.info("Session resume failed.", e1); - } - } - - // Session resume probably failed, show login window - if (Session.getSatelliteToken() == null) { - // User did not login, show the login mask + // now try to init the session with the saved configuration (by giving it null as 2nd param) + if (!ThriftActions.initSession(mainWindow, null)) { + // session resume failed, so do the normal login procedure LoginWindow.open(mainWindow); } + mainWindow.setTitle("bwLehrstuhl - " + Session.getFirstName() + " " + Session.getLastName() + " [" + Session.getSatelliteAddress() + "]"); @@ -390,7 +373,7 @@ public abstract class MainWindow { SatelliteStatus status = ThriftManager.getSatClient().getStatus(); txt += " [" + FormatHelper.bytes(status.availableStorageBytes, false) + "]"; } catch (TException e) { - // + // } } final String labelText = txt; 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 3068f8a1..11699b6c 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 @@ -15,6 +15,7 @@ import java.util.List; import javax.swing.DefaultComboBoxModel; import javax.swing.JFrame; +import javax.swing.JOptionPane; import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.Organization; @@ -38,6 +39,7 @@ import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.window.layout.LoginWindowLayout; import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.Sorters; +import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.cache.OrganizationCache; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; @@ -326,45 +328,8 @@ public class LoginWindow extends LoginWindowLayout { */ private void postSuccessfulLogin(AuthenticationData data) { LOGGER.info(loginType.toString() + " succeeded, token " + data.satelliteToken); - - // TODO: Show satellite selection if > 1 - //String satAddress = data.satellites.get(0).addressList.get(0); - String satAddress = "132.230.8.113"; // TODO: HACK HACK - Client client = ThriftManager.getNewSatelliteClient(GraphicalCertHandler.getSslContext(satAddress), - satAddress, App.THRIFT_SSL_PORT, App.THRIFT_TIMEOUT_MS); - 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 { - 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 (TInvocationException 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( - GraphicalCertHandler.getSslContext(Session.getSatelliteAddress()), - Session.getSatelliteAddress(), App.THRIFT_SSL_PORT, App.THRIFT_TIMEOUT_MS); - // now read the config to see if the user already agreed to the disclaimer - // if (DisclaimerWindow.shouldBeShown()) - // VirtualizerNoticeWindow.open(); - // Save session (TODO: Extra checkbox) + // now try to init the session with the data received + if (ThriftActions.initSession(JOptionPane.getFrameForComponent(this), data)) { if (saveUsernameCheck.isSelected()) { Config.saveCurrentSession(Session.getSatelliteAddress(), Session.getSatelliteToken(), Session.getMasterToken()); @@ -372,9 +337,10 @@ public class LoginWindow extends LoginWindowLayout { dispose(); return; } - Gui.showMessageBox(this, - "Authentifizierung erfolgreich, aber der Satellit akzeptiert das Sitzungstoken nicht.", - MessageType.ERROR, LOGGER, e); +// // did not work +// Gui.showMessageBox(this, +// "Authentifizierung erfolgreich, aber der Satellit akzeptiert das Sitzungstoken nicht.", +// MessageType.ERROR, LOGGER, null); } @SuppressWarnings("deprecation") diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java index e31a2852..ddac7c67 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -23,13 +23,20 @@ import org.openslx.bwlp.thrift.iface.LecturePermissions; import org.openslx.bwlp.thrift.iface.LectureRead; import org.openslx.bwlp.thrift.iface.LectureSummary; import org.openslx.bwlp.thrift.iface.LectureWrite; +import org.openslx.bwlp.thrift.iface.SatelliteServer.Client; import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TInvocationException; import org.openslx.bwlp.thrift.iface.TransferInformation; import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.bwlp.thrift.iface.WhoamiInfo; +import org.openslx.dozmod.App; import org.openslx.dozmod.Config; +import org.openslx.dozmod.Config.SavedSession; +import org.openslx.dozmod.authentication.Authenticator.AuthenticationData; import org.openslx.dozmod.filetransfer.AsyncHashGenerator; import org.openslx.dozmod.filetransfer.DownloadTask; import org.openslx.dozmod.filetransfer.UploadTask; +import org.openslx.dozmod.gui.GraphicalCertHandler; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.Gui.GuiCallable; import org.openslx.dozmod.gui.MainWindow; @@ -46,6 +53,80 @@ public class ThriftActions { /* ******************************************************************************* * + * LOGIN + * + * Login methods + * + ********************************************************************************/ + /** + * @param frame to show user feedback on + * @param data AuthenticationData as received from a successfull login, or null if trying to resume a saved sessions + * @return true if initiliazing the session worked, false otherwise + */ + public static boolean initSession(final Frame frame, AuthenticationData data) { + Client client = null; + WhoamiInfo whoami = null; + String address = null; + String satToken = null; + String masterToken = null; + if (data == null) { + // in session resume + SavedSession session = Config.getSavedSession(); + if (session != null) { + address = session.address; + satToken = session.token; + masterToken = session.masterToken; + + } else { + // fail + return false; + } + } else { + // after login + address = "132.230.8.113"; + satToken = data.satelliteToken; + masterToken = data.masterToken; + } + // try to get a new client + client = ThriftManager.getNewSatelliteClient(GraphicalCertHandler.getSslContext(address), + address, App.THRIFT_SSL_PORT, App.THRIFT_TIMEOUT_MS); + if (client == null) + return false; + + // all good, try to get the whoami info + try { + whoami = client.whoami(satToken); + } catch (TAuthorizationException e) { + Gui.showMessageBox(frame, + "Authentifizierung erfolgreich, der Satellit verweigert jedoch die Verbindung.\n\n" + + "Grund: " + e.number.toString() + " (" + e.message + ")", MessageType.ERROR, + null, null); + return false; + } catch (TInvocationException e) { + Gui.showMessageBox( + frame, + "Authentifizierung erfolgreich, bei der Kommunikation mit dem Satelliten trat jedoch ein interner Server-Fehler auf.", + MessageType.ERROR, LOGGER, e); + return false; + } catch (Exception e) { + Gui.showMessageBox( + frame, + "Authentifizierung erfolgreich, aber der Satellit akzeptiert das Sitzungstoken nicht.", + MessageType.ERROR, LOGGER, e); + return false; + } + + if (whoami != null) { + Session.initialize(whoami, address, satToken, masterToken); + ThriftManager.setSatelliteAddress( + GraphicalCertHandler.getSslContext(Session.getSatelliteAddress()), + Session.getSatelliteAddress(), App.THRIFT_SSL_PORT, App.THRIFT_TIMEOUT_MS); + return true; + } + return false; + } + /* ******************************************************************************* + * * IMAGE CREATION * * Creates a base image with the given name |