summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/core/LoginGUI.java
diff options
context:
space:
mode:
authorJonathan Bauer2015-07-08 16:58:02 +0200
committerJonathan Bauer2015-07-08 16:58:02 +0200
commit73989b5cd12313d5192601ab453552ee3d26da10 (patch)
tree505b4c2bad9855aeecbeef4ed8780a6d431bc574 /dozentenmodul/src/main/java/gui/core/LoginGUI.java
parent[client] user feedback when login fails. (diff)
downloadtutor-module-73989b5cd12313d5192601ab453552ee3d26da10.tar.gz
tutor-module-73989b5cd12313d5192601ab453552ee3d26da10.tar.xz
tutor-module-73989b5cd12313d5192601ab453552ee3d26da10.zip
[client] implemented login -> disclaimer -> vmwarelicense logic
Diffstat (limited to 'dozentenmodul/src/main/java/gui/core/LoginGUI.java')
-rw-r--r--dozentenmodul/src/main/java/gui/core/LoginGUI.java168
1 files changed, 137 insertions, 31 deletions
diff --git a/dozentenmodul/src/main/java/gui/core/LoginGUI.java b/dozentenmodul/src/main/java/gui/core/LoginGUI.java
index e85f83cc..321942d5 100644
--- a/dozentenmodul/src/main/java/gui/core/LoginGUI.java
+++ b/dozentenmodul/src/main/java/gui/core/LoginGUI.java
@@ -14,7 +14,6 @@ import org.eclipse.swt.widgets.Shell;
import org.openslx.bwlp.dozmod.thrift.OrganizationCache;
import org.openslx.bwlp.thrift.iface.Organization;
import org.openslx.bwlp.thrift.iface.TAuthenticationException;
-import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.thrifthelper.ThriftManager;
@@ -22,21 +21,32 @@ import util.ShibbolethECP.ReturnCode;
import auth.BWIDMAuthenticator;
import auth.BWLPAuthenticator;
import auth.BaseAuthenticator.AuthenticatorCallback;
+import config.Config;
import edu.kit.scc.dei.ecplean.ECPAuthenticationException;
import gui.GuiManager;
+/**
+ * @author Jonathan Bauer
+ *
+ */
public class LoginGUI extends LoginComposite {
private final static Logger LOGGER = Logger.getLogger(LoginGUI.class);
+ // text constants
private final String NO_USERNAME = "Kein Benutzername angegeben!";
private final String NO_PASSWORD = "Kein Passwort angegeben!";
- private final String BAD_AUTH = "Authentifizierung fehlgeschlagen!";
+ // 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.
+ *
* @param mainShell
*/
public LoginGUI(final Shell mainShell) {
@@ -56,18 +66,61 @@ public class LoginGUI extends LoginComposite {
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;
+ LOGGER.debug("Adding: " + o.toString());
idpCombo.add(o.displayName);
idpCombo.setData(o.displayName, o);
+ 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
+ }
+ // if no organization was saved, none is selected, so select the first one in the combobox
+ if (idpCombo.getSelectionIndex() == -1)
+ idpCombo.select(0);
+ // check if we had saved an authentication method
+ String savedAuthMethod = Config.getAuthenticationMethod();
+ if (savedAuthMethod != null && !savedAuthMethod.isEmpty()) {
+ LOGIN_TYPE savedLoginType = LOGIN_TYPE.getEnum(savedAuthMethod);
+ // if no valid LOGIN_TYPE was saved, just enable the BWIDM button
+ if (savedLoginType == null) {
+ authButtons[LOGIN_TYPE.BWIDM.getId()].setSelection(true);
+ loginType = LOGIN_TYPE.BWIDM;
+ } else {
+ authButtons[savedLoginType.getId()].setSelection(true);
+ loginType = savedLoginType;
+ idpText.setVisible(savedLoginType == LOGIN_TYPE.BWIDM);
+ idpCombo.setVisible(savedLoginType == LOGIN_TYPE.BWIDM);
+ }
+ } else {
+ // default value for LOGIN_TYPE is BWIDM
+ authButtons[LOGIN_TYPE.BWIDM.getId()].setSelection(true);
+ loginType = LOGIN_TYPE.BWIDM;
}
- idpCombo.select(0);
+
+
+ // finally check if we had a saved username
+ String savedUsername = Config.getUsername();
+ if (savedUsername != null && !savedUsername.isEmpty()) {
+ usernameText.setText(savedUsername);
+ saveUsernameCheck.setSelection(true);
+ passwordText.setFocus();
+ } else
+ usernameText.setFocus();
// actions of the login button
loginButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- doLogin(loginType);
+ doSaveConfig();
+ doLogin();
}
});
@@ -109,27 +162,63 @@ public class LoginGUI extends LoginComposite {
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) {
- // TODO Auto-generated method stub
if (e.keyCode == SWT.CR) {
- doLogin(loginType);
+ doSaveConfig();
+ doLogin();
}
}
-
@Override
public void keyPressed(KeyEvent e) {}
});
}
/**
+ * Saves various user choices to the config file.
+ * This gets triggered when the login button is activated.
+ */
+ private void doSaveConfig() {
+ // first we need to check if the "Remember me" button is active
+ if (saveUsernameCheck.isEnabled()) {
+ // save username
+ String username = usernameText.getText();
+ if (username != null && !username.isEmpty()) {
+ // all good, save it
+ if (!Config.setUsername(username))
+ LOGGER.error("Could not save username '" + username + "' to '" + Config.getPath() + "'.");
+ }
+ }
+ // 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() + "'.");
+ // check if we are doing bwIDM authentication
+ if (loginType == LOGIN_TYPE.BWIDM) {
+ // save the selected identity provider
+ Organization selectedOrg = getSelectedOrganization();
+ if (!Config.setIdentityProvider(selectedOrg.organizationId))
+ LOGGER.error("Could not save the identity provider '" + selectedOrg.organizationId + "'!");
+ }
+ // finalize by actually storing the config file
+ 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
*/
- private void doLogin(LOGIN_TYPE loginType) {
+ private void doLogin() {
+ // sanity check on loginType.
+ if (loginType == null) {
+ LOGGER.error("No login type set, a default should be set! Ignoring...");
+ return;
+ }
// here we only check for the fields
username = usernameText.getText();
password = passwordText.getText();
@@ -146,15 +235,9 @@ public class LoginGUI extends LoginComposite {
GuiManager.showMessage(NO_PASSWORD);
return;
}
- // get the index of the selected item in the combobox
- int selectionIndex = idpCombo.getSelectionIndex();
- if (selectionIndex == -1) {
- LOGGER
- .error("No IdP is selected in the combobox. There should be a default value!");
- return;
- }
- Organization selectedOrg =
- (Organization) idpCombo.getData(idpCombo.getItem(selectionIndex));
+
+ // determine which organization was selected by the user.
+ Organization selectedOrg = getSelectedOrganization();
// now switch over the login types.
switch (loginType) {
@@ -165,21 +248,19 @@ public class LoginGUI extends LoginComposite {
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("");
+ GuiManager.showMessage("IdP Error");
break;
default:
GuiManager.showMessage("Internal error!");
break;
}
- } else {
- // TODO: FOR DEBUGGING/DEV PURPOSES!
- ThriftManager.setSatelliteAddress( "132.230.8.113" );
- GuiManager.addContent(new DisclaimerComposite(getShell()));
- }
+ } else
+ postSuccessfulLogin();
}
});
} catch (TAuthenticationException e) {
@@ -200,12 +281,8 @@ public class LoginGUI extends LoginComposite {
LOGGER.error("BWLP login failed.");
GuiManager.showMessage("Login failed!");
}
- if (returnCode == ReturnCode.NO_ERROR && user != null) {
- LOGGER.error("BWLP login failed.");
- // TODO: FOR DEBUGGING/DEV PURPOSES!
- ThriftManager.setSatelliteAddress( "132.230.8.113" );
- GuiManager.addContent(new DisclaimerComposite(getShell()));
- }
+ if (returnCode == ReturnCode.NO_ERROR && user != null)
+ postSuccessfulLogin();
}
});
} catch (TAuthenticationException e) {
@@ -216,10 +293,39 @@ public class LoginGUI extends LoginComposite {
LOGGER.info("sat");
break;
default:
- LOGGER.error("derp");
+ LOGGER.error("Unknown login type! Ignoring...");
break;
}
return;
-
+ }
+
+ /**
+ * Functions called by doLogin is the login process succeeded.
+ */
+ private void postSuccessfulLogin() {
+ LOGGER.info(loginType.getTag() + " succeeded.");
+
+ 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 DisclaimerGUI(getShell()));
+ else if (!Config.getVmwareLicenseAgreement())
+ GuiManager.addContent(new VMWareInfoGUI(getShell()));
+ else
+ GuiManager.addContent(new MainWindowComposite(getShell()));
+ }
+
+ /**
+ * @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
+ int selectionIndex = idpCombo.getSelectionIndex();
+ if (selectionIndex == -1) {
+ LOGGER.error("No identity provider is selected in the combobox. There should be a default value!");
+ return null;
+ }
+ return (Organization) idpCombo.getData(idpCombo.getItem(selectionIndex));
}
}