diff options
author | Simon Rettberg | 2015-07-09 12:36:37 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-09 12:36:37 +0200 |
commit | 06b5236c58dde31bbc910a644aa2c676197ca2a8 (patch) | |
tree | 9b94b474cf34e25b73a5d092b945dd37e0973977 /dozentenmodul/src/main/java/org | |
parent | [client] Clean up login, implement showMessageBox, fix formatting (diff) | |
parent | [client] GuiManager.openPopup first steps (diff) | |
download | tutor-module-06b5236c58dde31bbc910a644aa2c676197ca2a8.tar.gz tutor-module-06b5236c58dde31bbc910a644aa2c676197ca2a8.tar.xz tutor-module-06b5236c58dde31bbc910a644aa2c676197ca2a8.zip |
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
Conflicts:
dozentenmodul/src/main/java/org/openslx/dozmod/authentication/EcpAuthenticator.java
dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java
dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java
dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
(Hopefully resolved)
Diffstat (limited to 'dozentenmodul/src/main/java/org')
8 files changed, 138 insertions, 76 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/Authenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/Authenticator.java index 78c1528a..430d0001 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/Authenticator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/Authenticator.java @@ -19,7 +19,7 @@ public interface Authenticator { * corresponding message to the user. */ interface AuthenticatorCallback { - void postLogin(ReturnCode returnCode, UserInfo user); + void postLogin(ReturnCode returnCode, UserInfo user, Throwable t); } /** diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/EcpAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/EcpAuthenticator.java index 2494914a..fbc26c5d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/EcpAuthenticator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/EcpAuthenticator.java @@ -1,11 +1,5 @@ package org.openslx.dozmod.authentication; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URISyntaxException; - -import org.apache.http.ParseException; -import org.apache.http.client.ClientProtocolException; import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.TAuthenticationException; @@ -14,8 +8,6 @@ import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode; import org.openslx.thrifthelper.ThriftManager; -import com.google.gson.JsonSyntaxException; - /** * @author Jonathan Bauer * @@ -46,42 +38,43 @@ public class EcpAuthenticator implements Authenticator { ReturnCode ret = null; try { ret = ShibbolethEcp.doLogin(this.ecpUrl, username, password); - } catch (JsonSyntaxException e) { - LOGGER.error("Could not parse JSON response from the service provider: ", e); - } catch (ClientProtocolException e) { - LOGGER.error("HTTP client protocol error: ", e); - } catch (ParseException e) { - LOGGER.error("Error parsing the raw response body from the service provider: ", e); - } catch (MalformedURLException e) { - LOGGER.error("Bad syntax of the registration URL returned by the service provider: ", e); - } catch (URISyntaxException e) { - LOGGER.error("Bad syntax of the URL to the identity provider: ", e); - } catch (IOException e) { - LOGGER.error("IO Error while communicating with the service provider: ", e); + } catch (Exception e) { + // TODO: This class should not do any GUI interaction.... } // if ret is still null, some exception happened, so abort. if (ret == null) { LOGGER.error("Error during the ECP authentication process."); + callback.postLogin(ReturnCode.GENERIC_ERROR, null, null); return; } - // else, we do have a valid ReturnCode + // else, we do have a valid ReturnCode? if (ret == ReturnCode.NO_ERROR) { - UserInfo userInfo; + final UserInfo userInfo; + // we have a token? + final String token = ShibbolethEcp.getResponse().token; + if (token == null || token.isEmpty()) { + // bad token + LOGGER.error("No token received from the service provider!"); + callback.postLogin(ReturnCode.SERVICE_PROVIDER_ERROR, null, null); + } try { - userInfo = ThriftManager.getMasterClient().getUserFromToken(ShibbolethEcp.getResponse().token); + // valid token? + userInfo = ThriftManager.getMasterClient().getUserFromToken(token); } catch (TInvalidTokenException e) { LOGGER.error("Masterserver does not accepts the token received from the Service Provider. See trace: ", e); + callback.postLogin(ReturnCode.SERVICE_PROVIDER_ERROR, null, e); return; } catch (TException e) { LOGGER.error("Thrift transport error, see trace: ", e); + callback.postLogin(ReturnCode.GENERIC_ERROR, null, e); return; } - callback.postLogin(ReturnCode.NO_ERROR, userInfo); + callback.postLogin(ReturnCode.NO_ERROR, userInfo, null); } else { // else just return the ReturnCode to the GUI // it should then show a corresponding error message! - callback.postLogin(ret, null); + callback.postLogin(ret, null, null); } } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java index 22638b52..e0eabb91 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java @@ -46,12 +46,13 @@ public class ShibbolethEcp { * Return codes */ public static enum ReturnCode { + // TODO rework this... NO_ERROR(0, "Authentication against the identity provider and request of the service provider resource worked."), - IDP_ERROR(1, "Authentication against the identity provider failed."), - UNREG_ERROR(2, "User not registered to use bwLehrpool."), - ERROR_SP(3, "Invalid resource of the service provider."), - ERROR_URL(4, "Invalid URL received from master server."), - ERROR_OTHER(5, "Internal error."); + IDENTITY_PROVIDER_ERROR(1, "Authentication against the identity provider failed."), + UNREGISTERED_ERROR(2, "User not registered to use bwLehrpool."), + SERVICE_PROVIDER_ERROR(3, "Invalid resource of the service provider."), + INVALID_URL_ERROR(4, "Invalid URL received from master server."), + GENERIC_ERROR(5, "Internal error."); private final int id; private final String msg; @@ -109,19 +110,19 @@ public class ShibbolethEcp { // first lets do some sanity checks if (BWLP_SP == null) { LOGGER.error("URI to service provider is not set. Check the initialization of 'BWLP_SP'."); - return ReturnCode.ERROR_OTHER; + return ReturnCode.GENERIC_ERROR; } if (idpUrl == null) { LOGGER.error("Identity provider is not set, did you initialize this class correctly?"); - return ReturnCode.ERROR_OTHER; + return ReturnCode.GENERIC_ERROR; } if (user == null) { LOGGER.error("No username given, aborting..."); - return ReturnCode.ERROR_OTHER; + return ReturnCode.GENERIC_ERROR; } if (pass == null) { LOGGER.error("No password given, aborting..."); - return ReturnCode.ERROR_OTHER; + return ReturnCode.GENERIC_ERROR; } // now init the authenticator for that idp and our static sp @@ -146,22 +147,22 @@ public class ShibbolethEcp { // no errors, meaning everything worked fine. if (lastResponse.status.equals("unregistered")) { registrationUrl = new URL(lastResponse.url); - return ReturnCode.UNREG_ERROR; + return ReturnCode.UNREGISTERED_ERROR; } // TODO the rest of the cases... if (lastResponse.status.equals("error")) { LOGGER.error("Server side error: " + lastResponse.error); - return ReturnCode.ERROR_OTHER; + return ReturnCode.GENERIC_ERROR; } if (lastResponse.status.equals("anonymous")) { LOGGER.error("IdP did not forward user account information to SP. Contact developper."); - return ReturnCode.ERROR_OTHER; + return ReturnCode.GENERIC_ERROR; } if (lastResponse.status.equals("ok")) { return ReturnCode.NO_ERROR; } // still here? then something else went wrong - return ReturnCode.ERROR_OTHER; + return ReturnCode.GENERIC_ERROR; } /** * @return Registration URL given by the SP. diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java index 9ca67609..bdb92023 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java @@ -30,7 +30,7 @@ public class TestAccountAuthenticator implements Authenticator { } catch (TException e) { LOGGER.error("Thrift communication error: ", e); // TODO authenticate has to return a TAuthenticationException! - callback.postLogin(ReturnCode.ERROR_OTHER, null); + callback.postLogin(ReturnCode.GENERIC_ERROR, null, e); return; } @@ -42,13 +42,13 @@ public class TestAccountAuthenticator implements Authenticator { } catch (TException e) { LOGGER.error("Thrift communication error: ", e); // TODO authenticate has to return a TAuthenticationException! - callback.postLogin(ReturnCode.ERROR_OTHER, null); + callback.postLogin(ReturnCode.GENERIC_ERROR, null, e); return; } - callback.postLogin(ReturnCode.NO_ERROR, userInfo); + callback.postLogin(ReturnCode.NO_ERROR, userInfo, null); } else { // it should then show a corresponding error message! - callback.postLogin(ReturnCode.ERROR_OTHER, null); + callback.postLogin(ReturnCode.GENERIC_ERROR, null, null); } } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java index 5fc53d5c..28da0824 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java @@ -1,5 +1,8 @@ package org.openslx.dozmod.gui.helper; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + import org.apache.log4j.Logger; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -21,14 +24,14 @@ public abstract class GuiManager { private final static Logger LOGGER = Logger.getLogger(GuiManager.class); - static Shell mainShell; - static Composite contentComposite; - static Display display; + private static Shell mainShell; + private static Composite contentComposite; + private static Display display; - static final int THRIFT_ERROR_RETRY_COUNT = 3; - static final String THRIFT_ERROR = "Lost connection to the masterserver. Click OK to retry."; - static final String THRIFT_FINAL_ERROR = "Could not re-establish connection to the masterserver after " - + THRIFT_ERROR_RETRY_COUNT + " tries. Contact an administrator/developer. Exiting application."; + private static final int THRIFT_RECONNECT_MAX_TRIES = 3; + private static final String THRIFT_CONNECTION_ERROR = "Lost connection to the masterserver."; + private static final String THRIFT_CONNECTION_DEAD = "Could not re-establish connection to the masterserver after " + + THRIFT_RECONNECT_MAX_TRIES + " tries. Contact an administrator/developer. Exiting application."; /** * Add a new composite with content to the main Shell @@ -56,15 +59,53 @@ public abstract class GuiManager { private static void removeContent() { if (contentComposite != null) { GuiManager.contentComposite.dispose(); + } + } + public static void openPopup(Class<?> clazz) { + Shell dialogShell = new Shell(display); + // populate dialogShell + dialogShell.setLayout(new GridLayout(1, false)); + LOGGER.debug(clazz.getDeclaredClasses()); + Constructor<?> con = null; + try { + con = clazz.getConstructor(Shell.class); + } catch (NoSuchMethodException | SecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + con.newInstance(dialogShell); + } catch (InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + dialogShell.layout(); + dialogShell.pack(); + dialogShell.open(); + while (!dialogShell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } } } + /** + * @return The instance of SWT display currently in use + */ public static Display getDisplay() { return display; } + /** + * Initialises the GUI by creating the main window, adding the menu and + * creating the login mask as the first content window. + * Further sets up the global thrift error callback to catch any + * connection errors during the communication with the servers. + */ public static void initGui() { + // init SWT stuffs display = new Display(); mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER); @@ -79,13 +120,13 @@ public abstract class GuiManager { public boolean thriftError(int failCount, String method, Throwable t) { // first check if we failed 3 reconnects, if so just let the user know // that we are closing the application due to connection problems. - MessageBox msgBox = new MessageBox(mainShell, SWT.ICON_ERROR); - msgBox.setText("Critical error"); - if (failCount > THRIFT_ERROR_RETRY_COUNT) { - msgBox.setMessage(THRIFT_FINAL_ERROR); + if (failCount > THRIFT_RECONNECT_MAX_TRIES) { + showMessageBox(mainShell, THRIFT_CONNECTION_DEAD, MessageType.ERROR, LOGGER, t); return false; + // System.exit(1); ? } else { - msgBox.setMessage(THRIFT_ERROR); + showMessageBox(mainShell, THRIFT_CONNECTION_ERROR, MessageType.ERROR, LOGGER, t); + // TODO how to actualy reconnect? return true; } } @@ -114,6 +155,7 @@ public abstract class GuiManager { // Set layout for the mainshell, items added to the shell should get a gridData mainShell.setLayout(new GridLayout(1, true)); + // Add LoginWindow as the first window to be shown addContent(new org.openslx.dozmod.gui.window.LoginWindow(mainShell)); // center the window on the primary monitor diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java index a5dc8b7b..9c2ae0b7 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java @@ -1,20 +1,19 @@ package org.openslx.dozmod.gui.helper; -import org.apache.log4j.Priority; +import org.apache.log4j.Level; import org.eclipse.swt.SWT; -@SuppressWarnings("deprecation") public enum MessageType { - DEBUG(SWT.ICON_INFORMATION, "Debug", Priority.DEBUG), - INFO(SWT.ICON_INFORMATION, "Hinweis", Priority.INFO), - WARNING(SWT.ICON_WARNING, "Warnung", Priority.WARN), - ERROR(SWT.ICON_ERROR, "Fehler", Priority.ERROR); + DEBUG(SWT.ICON_INFORMATION, "Debug", Level.DEBUG), + INFO(SWT.ICON_INFORMATION, "Hinweis", Level.INFO), + WARNING(SWT.ICON_WARNING, "Warnung", Level.WARN), + ERROR(SWT.ICON_ERROR, "Fehler", Level.ERROR); public final String title; public final int style; - public final Priority logPriority; + public final Level logPriority; - private MessageType(int style, String title, Priority prio) { + private MessageType(int style, String title, Level prio) { this.title = title; this.style = style; this.logPriority = prio; 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 f3c47dd7..3a87c73d 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 @@ -18,6 +18,7 @@ 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.helper.GuiManager; @@ -244,21 +245,34 @@ public class LoginWindow extends LoginWindowLayout { final LoginWindow me = this; AuthenticatorCallback authenticatorCallback = new AuthenticatorCallback() { @Override - public void postLogin(ReturnCode returnCode, UserInfo user) { + public void postLogin(ReturnCode returnCode, UserInfo user, Throwable t) { // TODO finish this - // handle errors first - if (returnCode != ReturnCode.NO_ERROR && user == null) { - switch (returnCode) { - case IDP_ERROR: - GuiManager.showMessageBox(me.getShell(), "IdP Error", MessageType.ERROR, null, null); - break; - default: - GuiManager.showMessageBox(me.getShell(), "Internal error!", MessageType.ERROR, null, - null); - break; - } - } else { + if (user == null) { + GuiManager.showMessageBox(me.getShell(), "User information received from the masterserver is corrupt!", + MessageType.ERROR, LOGGER, null); + return; + } + switch (returnCode) { + case NO_ERROR: postSuccessfulLogin(); + break; + case IDENTITY_PROVIDER_ERROR: + GuiManager.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. + GuiManager.showMessageBox(me.getShell(), "Invalid token from the service provider!", MessageType.ERROR, + LOGGER, t); + break; + case UNREGISTERED_ERROR: + GuiManager.showMessageBox(me.getShell(), "You are not registered to bwLehrpool. Please visit " + + ShibbolethEcp.getRegistrationUrl() + " and register first.", MessageType.ERROR, + LOGGER, t); + break; + default: + GuiManager.showMessageBox(me.getShell(), "Internal error!", MessageType.ERROR, null, null); + break; } } }; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainWindow.java new file mode 100644 index 00000000..86e7caea --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainWindow.java @@ -0,0 +1,13 @@ +package org.openslx.dozmod.gui.window; + +import org.eclipse.swt.widgets.Shell; +import org.openslx.dozmod.gui.window.layout.MainWindowLayout; + +public class MainWindow extends MainWindowLayout { + + public MainWindow(Shell mainShell) { + super(mainShell); + // TODO Auto-generated constructor stub + } + +} |