diff options
| author | Simon Rettberg | 2015-07-27 18:30:28 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-07-27 18:30:28 +0200 |
| commit | 941d94b3c9f09eeae92955779dfeca9728f39808 (patch) | |
| tree | 3eba723170809a6dee2cb6ad0e5744c0ec47ffd9 | |
| parent | dfg (diff) | |
| parent | [client] swingified LoginWindow (no functionality yet! just commented them ou... (diff) | |
| download | tutor-module-941d94b3c9f09eeae92955779dfeca9728f39808.tar.gz tutor-module-941d94b3c9f09eeae92955779dfeca9728f39808.tar.xz tutor-module-941d94b3c9f09eeae92955779dfeca9728f39808.zip | |
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
6 files changed, 503 insertions, 497 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index 25213b0f..50a43aa3 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -14,8 +14,8 @@ import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; import org.apache.log4j.spi.LoggingEvent; 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.LoginWindow; import org.openslx.dozmod.util.ProxyConfigurator; import org.openslx.thrifthelper.ThriftManager; @@ -126,7 +126,9 @@ public class App { // Set master server to use (TODO: make configurable via command line) ThriftManager.setMasterServerAddress("bwlp-masterserver.ruf.uni-freiburg.de"); - MainWindow.open(); +// MainWindow.open(); + LoginWindow.open(); + } /** diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java index bd4171fb..54d4ab4a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java @@ -136,7 +136,7 @@ public class Gui { * primary monitor if true, <code>null</code> otherwise * @return the {@link Monitor} */ - private static GraphicsDevice getMonitorFromRectangle(Rectangle rect, boolean defaultToPrimary) { + public static GraphicsDevice getMonitorFromRectangle(Rectangle rect, boolean defaultToPrimary) { // Make sure rectangle is in bounds. This is not completely accurate // in case there are multiple monitors that have different resolutions. GraphicsDevice[] screens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); 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 de6a26bb..859ae870 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -137,6 +137,7 @@ public abstract class MainWindow { askApplicationQuit(); event.consume(); } + return event.isConsumed(); } }); 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 af794873..c150da66 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,36 +1,7 @@ package org.openslx.dozmod.gui.window; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - import org.apache.log4j.Logger; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -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.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 @@ -51,327 +22,330 @@ public class LoginWindow extends LoginWindowLayout { * * @param mainShell */ - public LoginWindow(final Shell mainShell) { - // call the constructor of the superclass - super(mainShell); - - // fetch the list of the identity providers as an async Thread - // else the GUI is blocked until this is done. - 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(); - } - } - }); - } - - 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; - } + public static void open() { + new LoginWindow().setVisible(true); } + public LoginWindow() { + // call the constructor of the superclass + super(); - /** - * 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 - 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); +// // fetch the list of the identity providers as an async Thread +// // else the GUI is blocked until this is done. +// 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(); +// } +// } +// }); } - /** - * @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)); - } +// 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 +// 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)); +// } } 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 ae665e23..81a4ffce 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,23 +1,27 @@ package org.openslx.dozmod.gui.window.layout; +import java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Image; + +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JRadioButton; +import javax.swing.JTextField; +import javax.swing.UIManager; +import javax.swing.border.TitledBorder; + import org.apache.log4j.Logger; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.util.ResourceLoader; -public abstract class LoginWindowLayout extends Composite { +public abstract class LoginWindowLayout extends JFrame { private static final Logger LOGGER = Logger.getLogger(LoginWindowLayout.class); @@ -37,18 +41,6 @@ public abstract class LoginWindowLayout extends Composite { // authentication method to use for login attempts protected LOGIN_TYPE loginType = null; - // textfields for the username/password - protected Text usernameText; - protected Text passwordText; - - // ComboBox/label for the IDP - protected final Combo idpCombo; - protected final Label idpText; - - // buttons - protected final Button loginButton; - protected final Button saveUsernameCheck; - protected final Button[] authButtons; private static final String title = "bwSuite - Login"; private static final String authenticationGroupLabel = "Authentifizierungsart"; @@ -59,95 +51,105 @@ public abstract class LoginWindowLayout extends Composite { * @param mainShell * The shell it should be added to */ - public LoginWindowLayout(final Shell mainShell) { - super(mainShell, SWT.NONE); - - // title for composite - mainShell.setText(title); - - // left authentication selection and right loginmask - GridLayout gridLayout = new GridLayout(2, true); - this.setLayout(gridLayout); - - Label titlePicture = new Label(this, SWT.NONE); - titlePicture.setImage(loadImage()); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); - gridData.horizontalAlignment = SWT.CENTER; - titlePicture.setLayoutData(gridData); - - // group for the authentication method. - // groups have borders and a title - Group authGroup = new Group(this, SWT.NONE); - authGroup.setText(authenticationGroupLabel); - gridLayout = new GridLayout(); - gridLayout.numColumns = 1; - authGroup.setLayout(gridLayout); - gridData = new GridData(GridData.FILL, GridData.FILL, false, false); - gridData.heightHint = 150; - authGroup.setLayoutData(gridData); - - // add the authentication method selection buttons - authButtons = new Button[3]; - authButtons[LOGIN_TYPE.ECP.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.ECP.id].setText("Authentifizierung über bwIDM"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.ECP.id].setLayoutData(gridData); - - authButtons[LOGIN_TYPE.TEST_ACCOUNT.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.TEST_ACCOUNT.id].setText("Test-Zugang mit festem Benutzernamen"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.TEST_ACCOUNT.id].setLayoutData(gridData); - - authButtons[LOGIN_TYPE.DIRECT_CONNECT.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.DIRECT_CONNECT.id].setText("Direkte Verbindung zum Satelliten"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.DIRECT_CONNECT.id].setLayoutData(gridData); - - // group for the login mask - final Group loginGroup = new Group(this, SWT.NONE); - loginGroup.setText("Zugangsdaten"); - gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - loginGroup.setLayout(gridLayout); - gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); - gridData.heightHint = 150; - loginGroup.setLayoutData(gridData); - - idpText = new Label(loginGroup, SWT.NONE); - idpText.setText("IdP:"); - - idpCombo = new Combo(loginGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - idpCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - - new Label(loginGroup, SWT.NONE).setText("Benutzername:"); - usernameText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER); - usernameText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - - new Label(loginGroup, SWT.NONE).setText("Passwort:"); - passwordText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD); - passwordText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - // login button - loginButton = new Button(loginGroup, SWT.PUSH); - loginButton.setText("Login"); - saveUsernameCheck = new Button(loginGroup, SWT.CHECK); - saveUsernameCheck.setText("Benutzername speichern"); - + public LoginWindowLayout() { + super(); + setTitle("Simple example"); + setSize(600, 300); + setLocationRelativeTo(null); + setResizable(false); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + GridBagLayout bag = new GridBagLayout(); + GridBagConstraints con = new GridBagConstraints(); + setLayout(bag); + con.fill = GridBagConstraints.BOTH; + con.gridwidth = GridBagConstraints.REMAINDER; + con.weightx = 1; + con.weighty = 1; + JLabel pic = new JLabel(loadImage()); + bag.setConstraints(pic, con); + add(pic); + + // login type panel + JPanel loginTypePanel = new JPanel(); + loginTypePanel.setLayout(new BoxLayout(loginTypePanel, BoxLayout.PAGE_AXIS)); + loginTypePanel.setBorder(new TitledBorder(UIManager + .getBorder("TitledBorder.border"), "Authentifizierungsart", + TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); + // radio button group for login type + ButtonGroup bg = new ButtonGroup(); + JRadioButton radioButtonTest = new JRadioButton("Test-Zugang mit festem Benutzer"); + JRadioButton radioButtonECP = new JRadioButton("Authentifizierung über bwIDM"); + JRadioButton radioButtonSat = new JRadioButton("Direkter Zugang zum Satelliten"); + bg.add(radioButtonTest); + bg.add(radioButtonECP); + bg.add(radioButtonSat); + loginTypePanel.add(radioButtonTest); + loginTypePanel.add(radioButtonECP); + loginTypePanel.add(radioButtonSat); + con.gridwidth = 1; + bag.setConstraints(loginTypePanel, con); + add(loginTypePanel); + + // login form panel + JPanel loginFormPanel = new JPanel(); + GridBagLayout formBag = new GridBagLayout(); + GridBagConstraints formCon = new GridBagConstraints(); + formCon.fill = GridBagConstraints.BOTH; + formCon.gridwidth = 1; + loginFormPanel.setLayout(new BoxLayout(loginFormPanel, BoxLayout.PAGE_AXIS)); + loginFormPanel.setBorder(new TitledBorder(UIManager + .getBorder("TitledBorder.border"), "Authentifizierungsart", + TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); + // label + field for username + JLabel labelUsername = new JLabel("Benutzername:"); + JTextField loginUsernameField = new JTextField(); + loginUsernameField + .setToolTipText("Bitte geben Sie Ihren Benutzernamen ein."); + loginUsernameField.setColumns(10); + formBag.setConstraints(labelUsername, formCon); + formCon.gridwidth = GridBagConstraints.REMAINDER; + formBag.setConstraints(loginUsernameField, formCon); + loginFormPanel.add(labelUsername); + loginFormPanel.add(loginUsernameField); + + loginFormPanel.setLayout(formBag); + // label + field for password + JLabel labelPassword = new JLabel("Passwort:"); + JPasswordField loginPasswordField = new JPasswordField(); + loginPasswordField + .setToolTipText("Bitte geben Sie Ihren Passwort ein."); + loginPasswordField.setColumns(10); + formCon.gridwidth = 1; + formBag.setConstraints(labelPassword, formCon); + loginFormPanel.add(labelPassword); + formCon.gridwidth = GridBagConstraints.REMAINDER; + formBag.setConstraints(loginPasswordField, formCon); + loginFormPanel.add(loginPasswordField); + JButton loginButton = new JButton("Login"); + formCon.gridwidth = 1; + formCon.gridx = 1; + formBag.setConstraints(loginButton, formCon); + loginFormPanel.add(loginButton); + + con.gridwidth = GridBagConstraints.REMAINDER; + bag.setConstraints(loginFormPanel, con); + add(loginFormPanel); } - private Image loadImage() { + private ImageIcon loadImage() { try { - ImageData image = ResourceLoader.getImage("/img/Logo_bwLehrpool.png"); - Rectangle screenSize = Gui.getMonitorFromRectangle(getShell().getBounds(), true).getBounds(); - float scaleX = (float)screenSize.width / (float)image.width; - float scaleY = (float)screenSize.height / (float)image.height; + ImageIcon image = ResourceLoader.getIcon("/img/Logo_bwLehrpool.png"); + java.awt.Rectangle screenSize = getBounds(); + float scaleX = (float)screenSize.width / (float)image.getIconWidth(); + float scaleY = (float)screenSize.height / (float)image.getIconHeight(); final float scaling; if (scaleX < scaleY) { scaling = scaleX / 2; } else { scaling = scaleY / 2; } - image = image.scaledTo((int)(image.width * scaling), (int)(image.height * scaling)); - return new Image(Gui.display, image); + image = new ImageIcon(image.getImage().getScaledInstance((int)(image.getIconWidth() * scaling), (int)(image.getIconHeight()* scaling), 0)); + return image; } catch (Exception e) { LOGGER.warn("Cannot load image", e); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java index ebed9f8e..f22f5282 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java @@ -1,22 +1,22 @@ package org.openslx.dozmod.util; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.font.FontRenderContext; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; import java.net.URL; +import javax.swing.ImageIcon; + import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; -import org.eclipse.swt.graphics.Point; -import org.openslx.dozmod.gui.Gui; /** - * Helper class for loading resources. This should be error safe loaders with a - * fall back in case the requested resource can't be found, or isn't of the - * expected type. + * Helper class for loading resources. + * This should be error safe loaders with a fall back in case the + * requested resource can't be found, or isn't of the expected type. */ public class ResourceLoader { @@ -25,56 +25,83 @@ public class ResourceLoader { */ private final static Logger LOGGER = Logger.getLogger(ResourceLoader.class); - public static ImageData getImage(String path) { + /** + * Load the given resource as an ImageIcon. + * This is guaranteed to never throw an Exception and always return + * an ImageIcon. If the requested resource could not be loaded, + * an icon is generated, containing an error message. If even that + * fails, an empty icon is returned. + * @param path Resource path to load + * @param description Icon description + * @return ImageIcon instance + */ + public static ImageIcon getIcon(String path, String description) { URL url = ResourceLoader.class.getResource(path); if (url == null) { LOGGER.error("Resource not found: " + path); } else { try { - return new ImageData(url.openStream()); + return new ImageIcon(url, description); } catch (Exception e) { - LOGGER.error("Resource not loadable: " + path, e); + LOGGER.error("Resource not loadable: " + path); } } - // If we reach here loading failed, create image containing error message + // If we reach here loading failed, create image containing error + // message try { - return errorIcon("Invalid Resource: " + path).getImageData(); + return errorIcon("Invalid Resource: " + path); } catch (Throwable t) { - // Empty image is best we can do - LOGGER.error("Could not create error image", t); - return new ImageData(10, 10, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000)); + return new ImageIcon(); } } + + /** + * Load the given resource as an ImageIcon. + * This is guaranteed to never throw an Exception and always return + * an ImageIcon. If the requested resource could not be loaded, + * an icon is generated, containing an error message. If even that + * fails, an empty icon is returned. + * @param path Resource path to load + * @return ImageIcon instance + */ + public static ImageIcon getIcon(String path) { + return getIcon(path, path); + } /** * Helper that will create an icon with given text. - * * @param errorText Text to render to icon * @return the icon */ - private static Image errorIcon(String errorText) { - GC gc = new GC(Gui.display); - Font font = new Font(Gui.display, "Tahoma", 20, SWT.BOLD); - gc.setFont(font); - Point size = gc.stringExtent(errorText); - gc.dispose(); + private static ImageIcon errorIcon(String errorText) { + Font font = new Font("Tahoma", Font.PLAIN, 20); + // get dimensions of text - Image image = new Image(Gui.display, size.x, size.y); - gc = new GC(image); - gc.setBackground(Gui.display.getSystemColor(SWT.COLOR_RED)); - gc.setForeground(Gui.display.getSystemColor(SWT.COLOR_YELLOW)); - gc.setFont(font); - gc.drawText(errorText, 0, 0); - gc.dispose(); - font.dispose(); - return image; + FontRenderContext frc = new FontRenderContext(null, true, true); + Rectangle2D bounds = font.getStringBounds(errorText, frc); + int w = (int) bounds.getWidth(); + int h = (int) bounds.getHeight(); + + // create a BufferedImage object + BufferedImage image = new BufferedImage(w, h, + BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + + // set color and other parameters + g.setColor(Color.WHITE); + g.fillRect(0, 0, w, h); + g.setColor(Color.RED); + g.setFont(font); + + g.drawString(errorText, (float) bounds.getX(), (float) -bounds.getY()); + + g.dispose(); + return new ImageIcon(image, "ERROR"); } /** * Tries to load the given resource treating it as a text file - * - * @param path - * Resource path to load + * @param path Resource path to load * @return content of the loaded resource as String */ public static String getTextFile(String path) { @@ -91,4 +118,4 @@ public class ResourceLoader { return "Resource '" + path + "' not found."; } } -} +}
\ No newline at end of file |
