diff options
| author | Jonathan Bauer | 2015-07-28 17:58:04 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-07-28 17:58:04 +0200 |
| commit | 8aa607235562a7ef0275ce603da3867c3b1d5f92 (patch) | |
| tree | 64235a673df5027319d45c9615223783f1287401 /dozentenmodul/src/main/java | |
| parent | Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff) | |
| download | tutor-module-8aa607235562a7ef0275ce603da3867c3b1d5f92.tar.gz tutor-module-8aa607235562a7ef0275ce603da3867c3b1d5f92.tar.xz tutor-module-8aa607235562a7ef0275ce603da3867c3b1d5f92.zip | |
[client] login window rises from the swt ashes
Diffstat (limited to 'dozentenmodul/src/main/java')
| -rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java | 636 | ||||
| -rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java | 86 |
2 files changed, 357 insertions, 365 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 f3fc079c..491aed9f 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 @@ -1,10 +1,43 @@ package org.openslx.dozmod.gui.window; +import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.Organization; +import org.openslx.dozmod.App; +import org.openslx.dozmod.Config; +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; +import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode; +import org.openslx.dozmod.authentication.TestAccountAuthenticator; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.MainWindow; +import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.window.layout.LoginWindowLayout; +import org.openslx.dozmod.thrift.OrganizationCache; +import org.openslx.dozmod.thrift.Session; +import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; + +import edu.kit.scc.dei.ecplean.ECPAuthenticationException; /** * @author Jonathan Bauer @@ -38,343 +71,286 @@ public class LoginWindow extends LoginWindowLayout { super(); // first do all listeners stuff - radioButtonECP.setActionCommand(LOGIN_TYPE.ECP.toString()); - radioButtonTest.setActionCommand(LOGIN_TYPE.TEST_ACCOUNT.toString()); - radioButtonSat.setActionCommand(LOGIN_TYPE.DIRECT_CONNECT.toString()); - // ugly but no way around it according to stackoverflow - final ActionListener loginTypeToggler = new ActionListener() { + for (final LOGIN_TYPE type : LOGIN_TYPE.values()) { + loginTypes[type.id].setActionCommand(type.toString()); + loginTypes[type.id].addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + idpLabel.setVisible(type == LOGIN_TYPE.ECP); + idpCombo.setVisible(type == LOGIN_TYPE.ECP); + loginType = type; + } + } + }); + } + + // check if we had saved an authentication method + String savedAuthMethod = Config.getAuthenticationMethod(); + LOGIN_TYPE savedLoginType; + try { + savedLoginType = LOGIN_TYPE.valueOf(savedAuthMethod); + } catch (Exception e) { + // if no valid LOGIN_TYPE was saved, just enable the BWIDM button + savedLoginType = LOGIN_TYPE.ECP; + } + + if (savedLoginType == LOGIN_TYPE.ECP) { + // disable login button til the idp list is here + loginButton.setEnabled(false); + } + // enable the corresponding button + loginTypes[savedLoginType.id].setSelected(true); + loginType = savedLoginType; + + QuickTimer.scheduleOnce(new Task() { + List<Organization> orgs = null; + + @Override + public void fire() { + try { + // Wait for proxy server init + App.waitForInit(); + orgs = OrganizationCache.getAll(); + } catch (Exception e) { + LoginWindow.LOGGER.error("Error during execution: ", e); + } + // filter out every organisation without ecp + Iterator<Organization> iterator = orgs.iterator(); + while (iterator.hasNext()) { + Organization current = iterator.next(); + if (current == null | !current.isSetEcpUrl() | current.getEcpUrl().isEmpty()) + iterator.remove(); + } + // 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 send the organisations back to the LoginWindow + // through populateIdpCombo() + Gui.asyncExec(new Runnable() { + @Override + public void run() { + populateIdpCombo(orgs); + loginButton.setEnabled(true); + } + }); + } + }); + + loginButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - loginType = LOGIN_TYPE.valueOf(e.getActionCommand()); - labelIdp.setVisible(loginType == LOGIN_TYPE.ECP); - idpCombo.setVisible(loginType == LOGIN_TYPE.ECP); + doLogin(); + } + }); + // add a key listener to the password field to trigger login + // when the user presses the ENTER key. + passwordField.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + super.keyReleased(e); + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + doLogin(); + } + + } + }); + + // finally check if we had a saved username + String savedUsername = Config.getUsername(); + if (savedUsername != null && !savedUsername.isEmpty()) { + usernameField.setText(savedUsername); + saveUsernameCheck.setSelected(true); + passwordField.requestFocus(); + } else { + usernameField.requestFocus(); + } + } + + /** + * Called by the thread fetching the organization list from the cache + * + * @param orgs list of organization to show in the combo box + */ + public void populateIdpCombo(List<Organization> orgs) { + + // sanity checks on orgs + if (orgs == null) { + LOGGER.error("No organizations received from the cache."); + return; + } + for (Organization org : orgs) { LOGGER.debug(org); } + + idpCombo.setModel(new DefaultComboBoxModel<Organization>(orgs.toArray(new Organization[orgs.size()]))); + idpCombo.setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList<?> list, + Object value, int index, boolean isSelected, + boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, + isSelected, cellHasFocus); + if (value instanceof Organization) { + Organization org = (Organization) value; + setText(org.getDisplayName()); + } + return this; + } + }); + // now check if we had a saved identity provider + String savedOrganizationId = Config.getIdentityProvider(); + idpCombo.setSelectedItem(OrganizationCache.find(savedOrganizationId)); + + } + + /** + * 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.isSelected()) { + // save username + String username = usernameField.getText(); + if (!username.isEmpty()) { + Config.setUsername(username); + } + } else { + Config.setUsername(""); + } + // always save the authentication method and potentially the identity provider + Config.setAuthenticationMethod(loginType.toString()); + // save the selected identity provider + Organization selectedOrg = idpCombo.getItemAt(idpCombo.getSelectedIndex()); + if (selectedOrg != null) { + Config.setIdentityProvider(selectedOrg.organizationId); + } + } + + /** + * 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() { + // sanity check on loginType. + if (loginType == null) { + Gui.showMessageBox(this, "No login type set, a default should be set! Ignoring...", + MessageType.ERROR, LOGGER, null); + return; + } + // we are doing the login soon, first save the config + doSaveConfig(); + // here we only check for the fields + String username = usernameField.getText(); + String password = String.copyValueOf(passwordField.getPassword()); + // login clicked, lets first read the fields + if (username.isEmpty()) { + Gui.showMessageBox(this, NO_USERNAME, MessageType.ERROR, LOGGER, null); + return; + } + if (password.isEmpty()) { + Gui.showMessageBox(this, NO_PASSWORD, MessageType.ERROR, LOGGER, null); + return; + } + + // determine which organization was selected by the user. + Organization selectedOrg = idpCombo.getItemAt(idpCombo.getSelectedIndex()); + + // Setup login callback + final LoginWindow me = this; + AuthenticatorCallback authenticatorCallback = new AuthenticatorCallback() { + @Override + public void postLogin(ReturnCode returnCode, Throwable t) { + switch (returnCode) { + case NO_ERROR: + postSuccessfulLogin(); + break; + case IDENTITY_PROVIDER_ERROR: + Gui.showMessageBox(me, "IdP Error", MessageType.ERROR, LOGGER, null); + break; + case SERVICE_PROVIDER_ERROR: + // here if we have t != null then we have not received a token + // if we have t, then the token is invalid. + Gui.showMessageBox(me, "Invalid token from the service provider!", + MessageType.ERROR, LOGGER, t); + break; + case UNREGISTERED_ERROR: + Gui.showMessageBox(me, "You are not registered to bwLehrpool. Please visit " + + ShibbolethEcp.getRegistrationUrl() + " and register first.", MessageType.ERROR, + LOGGER, t); + break; + case INVALID_URL_ERROR: + Gui.showMessageBox(me, "ECP Authenticator says: Invalid URL.", + MessageType.ERROR, LOGGER, t); + break; + case GENERIC_ERROR: + default: + Gui.showMessageBox(me, "Internal error!", MessageType.ERROR, LOGGER, null); + break; + } } }; - radioButtonECP.addActionListener(loginTypeToggler); - radioButtonTest.addActionListener(loginTypeToggler); - radioButtonSat.addActionListener(loginTypeToggler); - - -// // fetch the list of the identity providers as an async Thread -// // else the GUI is blocked until this is done. -// idpCombo. -// idpCombo.add("Initialisiere..."); -// idpCombo.select(0); -// idpCombo.setEnabled(false); -// loginButton.setEnabled(false); -// QuickTimer.scheduleOnce(new Task() { -// List<Organization> orgs = null; -// -// @Override -// public void fire() { -// try { -// // Wait for proxy server init -// App.waitForInit(); -// orgs = OrganizationCache.getAll(); -// } catch (Exception e) { -// LoginWindow.LOGGER.error("Error during execution: ", e); -// } -// // now send the organisations back to the LoginWindow -// // through populateIdpCombo() -// Gui.display.asyncExec(new Runnable() { -// @Override -// public void run() { -// if (isDisposed()) -// return; -// populateIdpCombo(orgs); -// loginButton.setEnabled(true); -// } -// }); -// } -// }); -// -// // check if we had saved an authentication method -// String savedAuthMethod = Config.getAuthenticationMethod(); -// LOGIN_TYPE savedLoginType; -// try { -// savedLoginType = LOGIN_TYPE.valueOf(savedAuthMethod); -// } catch (Exception e) { -// // if no valid LOGIN_TYPE was saved, just enable the BWIDM button -// savedLoginType = LOGIN_TYPE.ECP; -// } -// authButtons[savedLoginType.id].setSelection(true); -// loginType = savedLoginType; -// // enable the IDP combo only if we actually have items in it -// idpText.setVisible(savedLoginType == LOGIN_TYPE.ECP); -// idpCombo.setVisible(savedLoginType == LOGIN_TYPE.ECP); -// -// // 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) { -// doSaveConfig(); -// doLogin(); -// } -// }); -// -// // 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.setEnabled(true); -// idpCombo.setVisible(true); -// loginType = LOGIN_TYPE.ECP; -// } -// }); -// -// // 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.TEST_ACCOUNT; -// } -// }); -// -// 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.DIRECT_CONNECT; -// } -// }); -// -// // add a key listener to the password field to trigger login -// // when the user presses the ENTER key. -// passwordText.addKeyListener(new KeyAdapter() { -// @Override -// public void keyReleased(KeyEvent e) { -// if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { -// doSaveConfig(); -// doLogin(); -// } -// } -// }); + + // now switch over the login types. + Authenticator authenticator; + switch (loginType) { + case ECP: + authenticator = new EcpAuthenticator(selectedOrg.getEcpUrl()); + break; + case TEST_ACCOUNT: + authenticator = new TestAccountAuthenticator(); + break; + case DIRECT_CONNECT: + Gui.showMessageBox(this, "Not yet implemented", MessageType.ERROR, LOGGER, null); + return; + default: + Gui.showMessageBox(this, "No login type selected!", MessageType.ERROR, LOGGER, null); + return; + } + + // Excute login + try { + authenticator.login(username, password, authenticatorCallback); + } catch (Exception e) { + Gui.showMessageBox(this, "Authentication failed: " + e.getMessage(), MessageType.ERROR, + LOGGER, e); + return; + } } -// public void populateIdpCombo(List<Organization> orgs) { -// -// // safety check to see if the login window still exists -// // when this function gets called by the other thread -// if (this.isDisposed()) -// return; -// // always clearup the list first -// idpCombo.removeAll(); -// -// // sanity checks on orgs -// if (orgs == null) { -// LOGGER.error("No organizations received from the cache."); -// idpCombo.add("No entries"); -// return; -// } -// -// // 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; -// 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); -// // finally re-enable it -// if (idpCombo.isVisible()) -// idpCombo.setEnabled(true); -// } -// -// /** -// * 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.isEmpty()) { -// Config.setUsername(username); -// } -// } else { -// Config.setUsername(""); -// } -// // always save the authentication method and potentially the identity provider -// Config.setAuthenticationMethod(loginType.toString()); -// // save the selected identity provider -// Organization selectedOrg = getSelectedOrganization(); -// if (selectedOrg != null) { -// Config.setIdentityProvider(selectedOrg.organizationId); -// } -// } -// -// /** -// * 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() { -// // sanity check on loginType. -// if (loginType == null) { -// Gui.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 -// String username = usernameText.getText(); -// String password = passwordText.getText(); -// // login clicked, lets first read the fields -// if (username.isEmpty()) { -// Gui.showMessageBox(this.getShell(), NO_USERNAME, MessageType.ERROR, null, null); -// return; -// } -// if (password.isEmpty()) { -// Gui.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, Throwable t) { -// switch (returnCode) { -// case NO_ERROR: -// postSuccessfulLogin(); -// break; -// case IDENTITY_PROVIDER_ERROR: -// Gui.showMessageBox(me.getShell(), "IdP Error", MessageType.ERROR, null, null); -// break; -// case SERVICE_PROVIDER_ERROR: -// // here if we have t != null then we have not received a token -// // if we have t, then the token is invalid. -// Gui.showMessageBox(me.getShell(), "Invalid token from the service provider!", -// MessageType.ERROR, LOGGER, t); -// break; -// case UNREGISTERED_ERROR: -// Gui.showMessageBox(me.getShell(), "You are not registered to bwLehrpool. Please visit " -// + ShibbolethEcp.getRegistrationUrl() + " and register first.", MessageType.ERROR, -// LOGGER, t); -// break; -// case INVALID_URL_ERROR: -// Gui.showMessageBox(me.getShell(), "ECP Authenticator says: Invalid URL.", -// MessageType.ERROR, LOGGER, t); -// break; -// case GENERIC_ERROR: -// default: -// Gui.showMessageBox(me.getShell(), "Internal error!", MessageType.ERROR, null, null); -// break; -// } -// } -// }; -// -// // now switch over the login types. -// Authenticator authenticator; -// switch (loginType) { -// case ECP: -// authenticator = new EcpAuthenticator(selectedOrg.getEcpUrl()); -// break; -// case TEST_ACCOUNT: -// authenticator = new TestAccountAuthenticator(); -// break; -// case DIRECT_CONNECT: -// Gui.showMessageBox(this.getShell(), "Not yet implemented", MessageType.ERROR, null, null); -// return; -// default: -// Gui.showMessageBox(this.getShell(), "No login type selected!", MessageType.ERROR, null, null); -// return; -// } -// -// // Excute login -// try { -// authenticator.login(username, password, authenticatorCallback); -// } catch (Exception e) { -// Gui.showMessageBox(me.getShell(), "Authentication failed: " + e.getMessage(), MessageType.ERROR, -// LOGGER, e); -// return; -// } -// } -// -// /** -// * Functions called by doLogin is the login process succeeded. -// * -// * @param user user who logged in -// */ -// private void postSuccessfulLogin() { -// LOGGER.info(loginType.toString() + " succeeded."); -// -// // TODO HACK HACK -// Session.setSatelliteAddress("132.230.8.113"); -// ThriftManager.setSatelliteAddress(Session.getSatelliteAddress()); -// // Something like ThriftManager.setSatelliteAddress(Session.getSatelliteAddress()); (might need selection box) -// Exception e = null; -// try { -// ThriftManager.getSatClient().isAuthenticated(Session.getSatelliteToken()); -// // now read the config to see if the user already agreed to the disclaimer + /** + * Functions called by doLogin is the login process succeeded. + */ + private void postSuccessfulLogin() { + LOGGER.info(loginType.toString() + " succeeded."); + + // TODO HACK HACK + Session.setSatelliteAddress("132.230.8.113"); + ThriftManager.setSatelliteAddress(Session.getSatelliteAddress()); + // Something like ThriftManager.setSatelliteAddress(Session.getSatelliteAddress()); (might need selection box) + Exception e = null; + try { + ThriftManager.getSatClient().isAuthenticated(Session.getSatelliteToken()); + // now read the config to see if the user already agreed to the disclaimer // if (DisclaimerWindow.shouldBeShown()) -// MainWindow.openPopup(DisclaimerWindow.class, true, true); -// getShell().dispose(); -// return; -// } catch (Exception ex) { -// e = ex; -// } -// Gui.showMessageBox(this.getShell(), "Login succeeded, but Satellite rejected the session token. :-(", -// MessageType.ERROR, LOGGER, e); -// } -// -// /** -// * @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)); -// } +// VirtualizerNoticeWindow.open(); + LOGGER.debug("Closing..."); + dispose(); + return; + } catch (Exception ex) { + e = ex; + } + Gui.showMessageBox(this, "Login succeeded, but Satellite rejected the session token. :-(", + MessageType.ERROR, LOGGER, e); + } + + /** + * Opens the login window + */ public static void open() { new LoginWindow().setVisible(true); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java index e092e8f9..1494967f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java @@ -1,11 +1,13 @@ package org.openslx.dozmod.gui.window.layout; import java.awt.Color; +import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; +import javax.swing.DefaultListCellRenderer; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -13,6 +15,7 @@ import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JRadioButton; @@ -53,16 +56,15 @@ public abstract class LoginWindowLayout extends JDialog { // login type panel protected JPanel loginTypePanel; protected ButtonGroup loginTypeButtonGroup; - protected JRadioButton radioButtonSat; - protected JRadioButton radioButtonECP; - protected JRadioButton radioButtonTest; + protected JRadioButton[] loginTypes = new JRadioButton[3]; + // login form panel - protected JLabel labelIdp; + protected JLabel idpLabel; protected JComboBox<Organization> idpCombo; - protected JTextField loginUsernameField; - protected JPasswordField loginPasswordField; - protected JCheckBox saveUsernameCheckbox; + protected JTextField usernameField; + protected JPasswordField passwordField; + protected JCheckBox saveUsernameCheck; protected JButton loginButton; @@ -97,17 +99,18 @@ public abstract class LoginWindowLayout extends JDialog { loginTypePanel.setBorder(new TitledBorder(UIManager .getBorder("TitledBorder.border"), AUTH_TYPE_LABEL, TitledBorder.LEADING, TitledBorder.TOP, null, Color.WHITE)); - loginTypeButtonGroup = new ButtonGroup(); - radioButtonECP = new JRadioButton("Authentifizierung über bwIDM"); - radioButtonTest = new JRadioButton("Test-Zugang mit festem Benutzer"); - radioButtonSat = new JRadioButton("Direkter Zugang zum Satelliten"); - - loginTypeButtonGroup.add(radioButtonECP); - loginTypeButtonGroup.add(radioButtonTest); - loginTypeButtonGroup.add(radioButtonSat); - loginTypePanel.add(radioButtonECP); - loginTypePanel.add(radioButtonTest); - loginTypePanel.add(radioButtonSat); + loginTypeButtonGroup = new ButtonGroup() { + + }; + + loginTypes[0] = new JRadioButton("Authentifizierung über bwIDM"); + loginTypes[1] = new JRadioButton("Test-Zugang mit festem Benutzer"); + loginTypes[2] = new JRadioButton("Direkter Zugang zum Satelliten"); + for (int i = 0; i < loginTypes.length; i++) { + loginTypeButtonGroup.add(loginTypes[i]); + loginTypePanel.add(loginTypes[i]); + } + con.gridwidth = 1; bag.setConstraints(loginTypePanel, con); add(loginTypePanel); @@ -122,48 +125,61 @@ public abstract class LoginWindowLayout extends JDialog { loginFormPanel.setBorder(new TitledBorder(UIManager .getBorder("TitledBorder.border"), LOGIN_FORM_LABEL, TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); - labelIdp = new JLabel("Identity Provider:"); - formBag.setConstraints(labelIdp, formCon); - loginFormPanel.add(labelIdp); + idpLabel = new JLabel("Identity Provider:"); + formBag.setConstraints(idpLabel, formCon); + loginFormPanel.add(idpLabel); idpCombo = new JComboBox<Organization>(); + idpCombo.setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList<?> list, + Object value, int index, boolean isSelected, + boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, + isSelected, cellHasFocus); + setText("Initialisiere..."); + return this; + } + }); formCon.gridwidth = GridBagConstraints.REMAINDER; formBag.setConstraints(idpCombo, formCon); loginFormPanel.add(idpCombo); + // label + field for username JLabel labelUsername = new JLabel("Benutzername:"); - loginUsernameField = new JTextField(); - loginUsernameField.setToolTipText("Bitte geben Sie Ihren Benutzernamen ein."); - loginUsernameField.setColumns(10); + usernameField = new JTextField(); + usernameField.setToolTipText("Bitte geben Sie Ihren Benutzernamen ein."); + usernameField.setColumns(10); formCon.gridwidth = 1; formBag.setConstraints(labelUsername, formCon); formCon.gridwidth = GridBagConstraints.REMAINDER; - formBag.setConstraints(loginUsernameField, formCon); + formBag.setConstraints(usernameField, formCon); loginFormPanel.add(labelUsername); - loginFormPanel.add(loginUsernameField); - + loginFormPanel.add(usernameField); loginFormPanel.setLayout(formBag); + // label + field for password JLabel labelPassword = new JLabel("Passwort:"); - loginPasswordField = new JPasswordField(); - loginPasswordField.setToolTipText("Bitte geben Sie Ihren Passwort ein."); - loginPasswordField.setColumns(10); + passwordField = new JPasswordField(); + passwordField.setToolTipText("Bitte geben Sie Ihren Passwort ein."); + passwordField.setColumns(10); formCon.gridwidth = 1; formBag.setConstraints(labelPassword, formCon); loginFormPanel.add(labelPassword); formCon.gridwidth = GridBagConstraints.REMAINDER; - formBag.setConstraints(loginPasswordField, formCon); - loginFormPanel.add(loginPasswordField); + formBag.setConstraints(passwordField, formCon); + loginFormPanel.add(passwordField); loginButton = new JButton("Login"); formCon.gridwidth = 1; formCon.gridx = 1; formBag.setConstraints(loginButton, formCon); loginFormPanel.add(loginButton); - saveUsernameCheckbox = new JCheckBox("Benutzername speichern"); + saveUsernameCheck = new JCheckBox("Benutzername speichern"); formCon.gridwidth = 1; formCon.gridx = 2; - formBag.setConstraints(saveUsernameCheckbox, formCon); - loginFormPanel.add(saveUsernameCheckbox); + formBag.setConstraints(saveUsernameCheck, formCon); + loginFormPanel.add(saveUsernameCheck); + // finally add the form itself to the main panel con.gridwidth = GridBagConstraints.REMAINDER; bag.setConstraints(loginFormPanel, con); add(loginFormPanel); |
