diff options
author | Jonathan Bauer | 2015-07-03 18:47:55 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-07-03 18:47:55 +0200 |
commit | 66080be14336a7d0b06bc244249fcf0d528ea449 (patch) | |
tree | 3f5a81734bfea8837efbb4793c5263b805c40fc2 /dozentenmodul/src/main/java/gui/core/LoginGUI.java | |
parent | Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff) | |
download | tutor-module-66080be14336a7d0b06bc244249fcf0d528ea449.tar.gz tutor-module-66080be14336a7d0b06bc244249fcf0d528ea449.tar.xz tutor-module-66080be14336a7d0b06bc244249fcf0d528ea449.zip |
[client] bwIDM Authentication implemented, yet to be finalized.
Diffstat (limited to 'dozentenmodul/src/main/java/gui/core/LoginGUI.java')
-rw-r--r-- | dozentenmodul/src/main/java/gui/core/LoginGUI.java | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/gui/core/LoginGUI.java b/dozentenmodul/src/main/java/gui/core/LoginGUI.java new file mode 100644 index 00000000..5c329d5d --- /dev/null +++ b/dozentenmodul/src/main/java/gui/core/LoginGUI.java @@ -0,0 +1,173 @@ +package gui.core; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +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.UserInfo; +import org.openslx.thrifthelper.ThriftManager; + +import auth.BWIDMAuthenticator; +import auth.BaseAuthenticator.AuthenticatorCallback; +import edu.kit.scc.dei.ecplean.ECPAuthenticationException; +import gui.GuiManager; + +public class LoginGUI extends LoginComposite { + + private final static Logger LOGGER = Logger.getLogger(LoginGUI.class); + + private final String NO_USERNAME = "Kein Benutzername angegeben!"; + private final String NO_PASSWORD = "Kein Passwort angegeben!"; + + private String username = null; + private String password = null; + + /** + * @param mainShell + */ + public LoginGUI(final Shell mainShell) { + // call the constructor of the superclass + super(mainShell); + + // entries in the combo + List<Organization> orgs = null; + try { + orgs = ThriftManager.getMasterClient().getOrganizations(); + } catch (TException e) { + LOGGER.error( + "Could not fetch the IdP list from the masterserver! See trace:", e); + // in this case, we can just call the default fillIdPCombo method of the + // superclass + 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()); + } + }); + for (Organization o : orgs) { + idpCombo.add(o.displayName); + idpCombo.setData(o.displayName, o); + } + idpCombo.select(0); + + // actions of the login button + loginButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + try { + doLogin(loginType); + } catch (ECPAuthenticationException ae) { + LOGGER.error("Authentication error, see trace: ", ae); + GuiManager.showMessage(ae.getMessage()); + } + } + }); + + // for save username checkbox. + saveUsernameCheck.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + // clickedSaveUsernameCheck(); + } + }); + + // selecting the "Authentifizierung über bwIDM" radio button + authButtons[0].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + idpText.setVisible(true); + idpCombo.setVisible(true); + loginType = LOGIN_TYPE.BWIDM; + } + }); + + // selecting the "Test-Zugang mit festem Benutzer" radio button + authButtons[1].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + idpText.setVisible(false); + idpCombo.setVisible(false); + loginType = LOGIN_TYPE.BWLP; + } + }); + + authButtons[2].setEnabled(false); + // selecting the "Direkte Verbindung zum Satteliten" radio button + authButtons[2].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + idpText.setVisible(false); + idpCombo.setVisible(false); + loginType = LOGIN_TYPE.SAT; + } + }); + } + + /** + * 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) throws ECPAuthenticationException { + // here we only check for the fields + username = usernameText.getText(); + 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); + 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); + 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)); + + // now switch over the login types. + switch (loginType) { + 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())); + } + }); + break; + case BWLP: + LOGGER.info("bwlp"); + break; + case SAT: + LOGGER.info("sat"); + break; + default: + LOGGER.error("derp"); + break; + } + return; + + } +} |