diff options
author | Simon Rettberg | 2015-07-09 12:15:54 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-09 12:15:54 +0200 |
commit | 0c7260e879a2514203719146e20dd243b5493095 (patch) | |
tree | 82473c459df08d4c27f00adb64e41391baf7c29b /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java | |
parent | [server] Implement OS list fetching, caching, and fallback to local DB (diff) | |
download | tutor-module-0c7260e879a2514203719146e20dd243b5493095.tar.gz tutor-module-0c7260e879a2514203719146e20dd243b5493095.tar.xz tutor-module-0c7260e879a2514203719146e20dd243b5493095.zip |
[client] Clean up login, implement showMessageBox, fix formatting
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 | 179 |
1 files changed, 85 insertions, 94 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 62860fb5..f3c47dd7 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,13 +15,14 @@ import org.openslx.bwlp.thrift.iface.Organization; import org.openslx.bwlp.thrift.iface.TAuthenticationException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.Config; -import org.openslx.dozmod.authentication.BWIDMAuthenticator; -import org.openslx.dozmod.authentication.BWLPAuthenticator; -import org.openslx.dozmod.authentication.BaseAuthenticator.AuthenticatorCallback; -import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode; +import org.openslx.dozmod.authentication.Authenticator; +import org.openslx.dozmod.authentication.Authenticator.AuthenticatorCallback; +import org.openslx.dozmod.authentication.EcpAuthenticator; +import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode; +import org.openslx.dozmod.authentication.TestAccountAuthenticator; import org.openslx.dozmod.gui.helper.GuiManager; +import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.window.layout.LoginWindowLayout; -import org.openslx.dozmod.gui.window.layout.MainWindowLayout; import org.openslx.dozmod.thrift.OrganizationCache; import org.openslx.thrifthelper.ThriftManager; @@ -29,7 +30,7 @@ import edu.kit.scc.dei.ecplean.ECPAuthenticationException; /** * @author Jonathan Bauer - * + * */ public class LoginWindow extends LoginWindowLayout { @@ -39,15 +40,10 @@ public class LoginWindow extends LoginWindowLayout { private final String NO_USERNAME = "Kein Benutzername angegeben!"; private final String NO_PASSWORD = "Kein Passwort angegeben!"; - // user input variables - private String username = null; - private String password = null; - - /** * Constructor doing the setup of the logical GUI functions * Fetches the organization list for BWIDM logins and - * adds mouse/keyboard event listeners to various widgets. + * adds mouse/keyboard event listeners to various widgets. * * @param mainShell */ @@ -61,28 +57,28 @@ public class LoginWindow extends LoginWindowLayout { LOGGER.error("No organizations received from the cache."); idpCombo.add("No entries"); } - + // all fine, lets sort it Collections.sort(orgs, new Comparator<Organization>() { public int compare(Organization o1, Organization o2) { return o1.getDisplayName().compareTo(o2.getDisplayName()); } }); - + // now check if we had a saved identity provider String savedOrganizationId = Config.getIdentityProvider(); // add only organizations which have an ECP URL to the combobox for (Organization o : orgs) { - if (o.getEcpUrl() == null | o.getEcpUrl().isEmpty()) continue; + if (o.getEcpUrl() == null | o.getEcpUrl().isEmpty()) + continue; LOGGER.debug("Adding: " + o.toString()); idpCombo.add(o.displayName); idpCombo.setData(o.displayName, o); - if (savedOrganizationId != null && - !savedOrganizationId.isEmpty() && - savedOrganizationId.equals(o.getOrganizationId())) + if (savedOrganizationId != null && !savedOrganizationId.isEmpty() + && savedOrganizationId.equals(o.getOrganizationId())) // select the organization we just added, this seems kinda bad - is there a better way? idpCombo.select(idpCombo.getItemCount() - 1); - //idpCombo.select(idpCombo.indexOf(savedOrganizationId)); this is probably not optimal... but safer + //idpCombo.select(idpCombo.indexOf(savedOrganizationId)); this is probably not optimal... but safer } // if no organization was saved, none is selected, so select the first one in the combobox if (idpCombo.getSelectionIndex() == -1) @@ -104,10 +100,9 @@ public class LoginWindow extends LoginWindowLayout { } else { // default value for LOGIN_TYPE is BWIDM authButtons[LOGIN_TYPE.BWIDM.getId()].setSelection(true); - loginType = LOGIN_TYPE.BWIDM; + loginType = LOGIN_TYPE.BWIDM; } - - + // finally check if we had a saved username String savedUsername = Config.getUsername(); if (savedUsername != null && !savedUsername.isEmpty()) { @@ -164,11 +159,11 @@ public class LoginWindow extends LoginWindowLayout { loginType = LOGIN_TYPE.SAT; } }); - + // add a key listener to the password field to trigger login // when the user presses the ENTER key. passwordText.addKeyListener(new KeyListener() { - + @Override public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.CR) { @@ -176,14 +171,16 @@ public class LoginWindow extends LoginWindowLayout { doLogin(); } } + @Override - public void keyPressed(KeyEvent e) {} + public void keyPressed(KeyEvent e) { + } }); } /** * Saves various user choices to the config file. - * This gets triggered when the login button is activated. + * This gets triggered when the login button is activated. */ private void doSaveConfig() { // first we need to check if the "Remember me" button is active @@ -198,7 +195,8 @@ public class LoginWindow extends LoginWindowLayout { } // always save the authentication method and potentially the identity provider if (!Config.setAuthenticationMethod(loginType.getTag())) - LOGGER.error("Could not save authentication method '" + loginType.getTag() + "' to '" + Config.getPath() + "'."); + LOGGER.error("Could not save authentication method '" + loginType.getTag() + "' to '" + + Config.getPath() + "'."); // check if we are doing bwIDM authentication if (loginType == LOGIN_TYPE.BWIDM) { // save the selected identity provider @@ -210,106 +208,98 @@ public class LoginWindow extends LoginWindowLayout { if (!Config.store()) LOGGER.error("Could not save '" + Config.getPath() + "'!"); } + /** * Actually do the login using the username/password in the field using the * authentication mechanism corresponding to the selected authButton - * @throws ECPAuthenticationException + * + * @throws ECPAuthenticationException */ private void doLogin() { // sanity check on loginType. if (loginType == null) { - LOGGER.error("No login type set, a default should be set! Ignoring..."); + GuiManager.showMessageBox(this.getShell(), + "No login type set, a default should be set! Ignoring...", MessageType.ERROR, LOGGER, + null); return; } // here we only check for the fields - username = usernameText.getText(); - password = passwordText.getText(); + String username = usernameText.getText(); + String password = passwordText.getText(); // login clicked, lets first read the fields - if (username == null) { - // tell the GUIManager to show an error to the user - // TODO either popup or in the bottom status bar - GuiManager.showMessage(NO_USERNAME, SWT.ICON_ERROR); + if (username.isEmpty()) { + GuiManager.showMessageBox(this.getShell(), NO_USERNAME, MessageType.ERROR, null, null); return; } - if (password == null) { - // tell the GUIManager to show an error to the user - // TODO either popup or in the bottom status bar - GuiManager.showMessage(NO_PASSWORD, SWT.ICON_ERROR); + if (password.isEmpty()) { + GuiManager.showMessageBox(this.getShell(), NO_PASSWORD, MessageType.ERROR, null, null); return; } // determine which organization was selected by the user. + // TODO: Needed for test accounts? Organization selectedOrg = getSelectedOrganization(); + // Setup login callback + final LoginWindow me = this; + AuthenticatorCallback authenticatorCallback = new AuthenticatorCallback() { + @Override + public void postLogin(ReturnCode returnCode, UserInfo user) { + // TODO finish this + // handle errors first + if (returnCode != ReturnCode.NO_ERROR && user == null) { + switch (returnCode) { + case IDP_ERROR: + GuiManager.showMessageBox(me.getShell(), "IdP Error", MessageType.ERROR, null, null); + break; + default: + GuiManager.showMessageBox(me.getShell(), "Internal error!", MessageType.ERROR, null, + null); + break; + } + } else { + postSuccessfulLogin(); + } + } + }; + // now switch over the login types. + Authenticator authenticator; switch (loginType) { case BWIDM: - BWIDMAuthenticator bwidmAuth = new BWIDMAuthenticator( - selectedOrg.getEcpUrl()); - try { - bwidmAuth.login(username, password, new AuthenticatorCallback() { - @Override - public void postLogin(ReturnCode returnCode, UserInfo user) { - // TODO finish this - // handle errors first - if (returnCode != ReturnCode.NO_ERROR && user == null) { - switch(returnCode) { - case IDP_ERROR: - GuiManager.showMessage("IdP Error", SWT.ICON_ERROR); - break; - default: - GuiManager.showMessage("Internal error!", SWT.ICON_ERROR); - break; - } - } else - postSuccessfulLogin(); - } - }); - } catch (TAuthenticationException e) { - //LOGGER.error("Authentication error, see trace: ", e); - GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR); - return; - } + authenticator = new EcpAuthenticator(selectedOrg.getEcpUrl()); break; case BWLP: - LOGGER.info("bwlp"); - BWLPAuthenticator bwlpAuth = new BWLPAuthenticator(); - try { - bwlpAuth.login(username, password, new AuthenticatorCallback() { - @Override - public void postLogin(ReturnCode returnCode, UserInfo user) { - // handle errors first - if (returnCode != ReturnCode.NO_ERROR && user == null) { - LOGGER.error("BWLP login failed."); - GuiManager.showMessage("Login failed!", SWT.ICON_ERROR); - } - if (returnCode == ReturnCode.NO_ERROR && user != null) - postSuccessfulLogin(); - } - }); - } catch (TAuthenticationException e) { - GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR); - } + authenticator = new TestAccountAuthenticator(); break; case SAT: - LOGGER.warn("Direct satellite login is not yet supported."); - break; + GuiManager.showMessageBox(this.getShell(), "Not yet implemented", MessageType.ERROR, null, null); + return; default: - LOGGER.error("Unknown login type! Ignoring..."); - break; + GuiManager.showMessageBox(this.getShell(), "No login type selected!", MessageType.ERROR, null, + null); + return; + } + + // Excute login + try { + authenticator.login(username, password, authenticatorCallback); + } catch (TAuthenticationException e) { + GuiManager.showMessageBox(me.getShell(), "Authentication failed: " + e.getMessage(), + MessageType.ERROR, LOGGER, null); + return; } - return; } - + /** * Functions called by doLogin is the login process succeeded. */ private void postSuccessfulLogin() { LOGGER.info(loginType.getTag() + " succeeded."); - + // TODO HACK HACK - ThriftManager.setSatelliteAddress( "132.230.8.113" ); - + ThriftManager.setSatelliteAddress("132.230.8.113"); + // now read the config to see if the user already agreed to the disclaimer if (!Config.getDisclaimerAgreement()) GuiManager.addContent(new DisclaimerWindow(getShell())); @@ -317,9 +307,10 @@ public class LoginWindow extends LoginWindowLayout { GuiManager.addContent(new VirtualizerNoticeWindow(getShell())); // TODO: See MainWindowLayout comments } - + /** - * @return the organization currently selected in the combobox for identity providers + * @return the organization currently selected in the combobox for identity + * providers */ private final Organization getSelectedOrganization() { // get the index of the selected item in the combobox |