From 2eee1c291f08119d89c844f840f662cf356ca26c Mon Sep 17 00:00:00 2001
From: Jonathan Bauer
Date: Mon, 27 Jul 2015 18:13:25 +0200
Subject: [client] swingified LoginWindow (no functionality yet! just commented
them out for now)
---
.../src/main/java/org/openslx/dozmod/App.java | 6 +-
.../src/main/java/org/openslx/dozmod/gui/Gui.java | 2 +-
.../java/org/openslx/dozmod/gui/MainWindow.java | 1 +
.../org/openslx/dozmod/gui/window/LoginWindow.java | 670 ++++++++++-----------
.../gui/window/layout/LoginWindowLayout.java | 216 +++----
5 files changed, 437 insertions(+), 458 deletions(-)
(limited to 'dozentenmodul/src/main/java')
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, null 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 69800b4c..9319c6a2 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 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 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() {
- 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 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 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() {
+// 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);
}
--
cgit v1.2.3-55-g7522