summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2015-07-09 10:29:32 +0200
committerJonathan Bauer2015-07-09 10:29:32 +0200
commit58668cbdfb301b2aab6b3b6ad43363ac08f7d1fb (patch)
tree0927a362ffb59a0caeed9e3d7c9ccdcd38cc5c8b
parent[client] fix pom.xml after new package structure (diff)
downloadtutor-module-58668cbdfb301b2aab6b3b6ad43363ac08f7d1fb.tar.gz
tutor-module-58668cbdfb301b2aab6b3b6ad43363ac08f7d1fb.tar.xz
tutor-module-58668cbdfb301b2aab6b3b6ad43363ac08f7d1fb.zip
[client] implemented GuiManager.showMessagBox using MessageType and SWT'ed the whole thing
adapted rest of the classes further improved login error handling a bit
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java29
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java9
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethECP.java27
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java59
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java18
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java51
7 files changed, 124 insertions, 71 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java
index ece74088..7481dbdd 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java
@@ -12,6 +12,8 @@ import org.openslx.bwlp.thrift.iface.TAuthenticationException;
import org.openslx.bwlp.thrift.iface.TInvalidTokenException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode;
+import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.thrifthelper.ThriftManager;
import com.google.gson.JsonSyntaxException;
@@ -48,40 +50,57 @@ public class BWIDMAuthenticator implements BaseAuthenticator {
ret = ShibbolethECP.doLogin(this.ecpUrl, username, password);
} catch (JsonSyntaxException e) {
LOGGER.error("Could not parse JSON response from the service provider: ", e);
+ GuiManager.showMessageBox(e.getMessage(), MessageType.ERROR, LOGGER, e);
} catch (ClientProtocolException e) {
LOGGER.error("HTTP client protocol error: ", e);
+ GuiManager.showMessageBox(e.getMessage(), MessageType.ERROR, LOGGER, e);
} catch (ParseException e) {
LOGGER.error("Error parsing the raw response body from the service provider: ", e);
+ GuiManager.showMessageBox(e.getMessage(), MessageType.ERROR, LOGGER, e);
} catch (MalformedURLException e) {
LOGGER.error("Bad syntax of the registration URL returned by the service provider: ", e);
+ GuiManager.showMessageBox(e.getMessage(), MessageType.ERROR, LOGGER, e);
} catch (URISyntaxException e) {
LOGGER.error("Bad syntax of the URL to the identity provider: ", e);
+ GuiManager.showMessageBox(e.getMessage(), MessageType.ERROR, LOGGER, e);
} catch (IOException e) {
LOGGER.error("IO Error while communicating with the service provider: ", e);
+ GuiManager.showMessageBox(e.getMessage(), MessageType.ERROR, LOGGER, e);
}
// 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/BWLPAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java
index 7a9e718d..46129e21 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java
@@ -4,7 +4,6 @@ import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.SessionData;
import org.openslx.bwlp.thrift.iface.TAuthenticationException;
-import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode;
import org.openslx.thrifthelper.ThriftManager;
@@ -31,7 +30,7 @@ public class BWLPAuthenticator implements BaseAuthenticator {
} 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;
}
@@ -43,13 +42,13 @@ public class BWLPAuthenticator implements BaseAuthenticator {
} 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/authentication/BaseAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java
index 60602a3f..92333086 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java
@@ -19,7 +19,7 @@ public interface BaseAuthenticator {
* corresponding message to the user.
*/
interface AuthenticatorCallback {
- void postLogin(ReturnCode returnCode, UserInfo user);
+ void postLogin(ReturnCode returnCode, UserInfo user, Throwable t);
}
/**
* Definition of the generic login method.
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 0998c8af..2e249d6b 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/gui/helper/GuiManager.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java
index b79f306d..6fe7b35e 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
@@ -21,14 +21,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
@@ -55,24 +55,45 @@ public abstract class GuiManager {
private static void removeContent() {
if(contentComposite != null) {
GuiManager.contentComposite.dispose();
-
}
}
- // TODO use showMessageBox
- public static void showMessage(final String message, final int style) {
- MessageBox msgBox = new MessageBox(mainShell, style);
- msgBox.setText("Information");
+ /**
+ * Generic helper to show a message box to the user, and optionally log the message to the log file.
+ *
+ * @param message Message to display. Can be multi line.
+ * @param messageType Type of message (error, warning, information)
+ * @param logger Logger instance to log to. Can be null.
+ * @param exception Exception related to this message. Can be null.
+ */
+ public static void showMessageBox(String message, MessageType messageType, Logger logger,
+ Throwable exception) {
+ if (logger != null)
+ logger.log(messageType.logPriority, message, exception);
+ if (exception != null)
+ message += "\n\n" + exception.getClass().getSimpleName();
+ MessageBox msgBox = new MessageBox(mainShell, messageType.optionPaneId);
+ msgBox.setText(messageType.title);
msgBox.setMessage(message);
- int ret = msgBox.open();
- LOGGER.info("Message box return value: " + ret);
+ // ignoring return code of open() for now
+ msgBox.open();
}
+ /**
+ * @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);
@@ -87,13 +108,12 @@ 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(THRIFT_CONNECTION_DEAD, MessageType.ERROR, LOGGER, t);
return false;
+ // System.exit(1); ?
} else {
- msgBox.setMessage(THRIFT_ERROR);
+ showMessageBox(THRIFT_CONNECTION_ERROR, MessageType.ERROR, LOGGER, t);
return true;
}
}
@@ -122,6 +142,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 b0f55a5d..bd2bc7ae 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,21 +1,19 @@
package org.openslx.dozmod.gui.helper;
-import javax.swing.JOptionPane;
+import org.apache.log4j.Level;
+import org.eclipse.swt.SWT;
-import org.apache.log4j.Priority;
-
-@SuppressWarnings("deprecation")
public enum MessageType {
- DEBUG(JOptionPane.INFORMATION_MESSAGE, "Debug", Priority.DEBUG),
- INFO(JOptionPane.INFORMATION_MESSAGE, "Hinweis", Priority.INFO),
- WARNING(JOptionPane.WARNING_MESSAGE, "Warnung", Priority.WARN),
- ERROR(JOptionPane.ERROR_MESSAGE, "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 optionPaneId;
- public final Priority logPriority;
+ public final Level logPriority;
- private MessageType(int paneId, String title, Priority prio) {
+ private MessageType(int paneId, String title, Level prio) {
this.title = title;
this.optionPaneId = paneId;
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 62860fb5..75275700 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,10 +18,11 @@ import org.openslx.dozmod.Config;
import org.openslx.dozmod.authentication.BWIDMAuthenticator;
import org.openslx.dozmod.authentication.BWLPAuthenticator;
import org.openslx.dozmod.authentication.BaseAuthenticator.AuthenticatorCallback;
+import org.openslx.dozmod.authentication.ShibbolethECP;
import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode;
import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.window.layout.LoginWindowLayout;
-import org.openslx.dozmod.gui.window.layout.MainWindowLayout;
import org.openslx.dozmod.thrift.OrganizationCache;
import org.openslx.thrifthelper.ThriftManager;
@@ -228,17 +229,17 @@ public class LoginWindow extends LoginWindowLayout {
if (username == null) {
// tell the GUIManager to show an error to the user
// TODO either popup or in the bottom status bar
- GuiManager.showMessage(NO_USERNAME, SWT.ICON_ERROR);
+ GuiManager.showMessageBox(NO_USERNAME, MessageType.ERROR, LOGGER, null);
return;
}
if (password == null) {
// tell the GUIManager to show an error to the user
// TODO either popup or in the bottom status bar
- GuiManager.showMessage(NO_PASSWORD, SWT.ICON_ERROR);
+ GuiManager.showMessageBox(NO_PASSWORD, MessageType.ERROR, LOGGER, null);
return;
}
- // determine which organization was selected by the user.
+ // determine which organisation was selected by the user.
Organization selectedOrg = getSelectedOrganization();
// now switch over the login types.
@@ -249,46 +250,60 @@ public class LoginWindow extends LoginWindowLayout {
try {
bwidmAuth.login(username, password, new AuthenticatorCallback() {
@Override
- public void postLogin(ReturnCode returnCode, UserInfo user) {
- // TODO finish this
+ public void postLogin(ReturnCode returnCode, UserInfo user, Throwable t) {
// handle errors first
- if (returnCode != ReturnCode.NO_ERROR && user == null) {
+ // TODO the ReturnCode needs more elements probably
+ // IDENTITY_PROVIDER_ERROR not handled as its not yet thrown.
+ if (returnCode != ReturnCode.NO_ERROR) {
switch(returnCode) {
- case IDP_ERROR:
- GuiManager.showMessage("IdP Error", SWT.ICON_ERROR);
+ 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("Invalid token from the service provider!",
+ MessageType.ERROR, LOGGER, t == null ? null : t);
+ break;
+ case UNREGISTERED_ERROR:
+ GuiManager.showMessageBox("You are not registered to bwLehrpool."
+ + " Please visit " + ShibbolethECP.getRegistrationUrl()
+ + " and register first.", MessageType.ERROR, LOGGER, t);
break;
default:
- GuiManager.showMessage("Internal error!", SWT.ICON_ERROR);
+ GuiManager.showMessageBox("Internal error!", MessageType.ERROR, LOGGER, null);
break;
}
+ } else if (user == null) {
+ GuiManager.showMessageBox("User information received from the masterserver is corrupt!",
+ MessageType.ERROR, LOGGER, null);
+ return;
} else
+ // login successful
postSuccessfulLogin();
}
});
} catch (TAuthenticationException e) {
- //LOGGER.error("Authentication error, see trace: ", e);
- GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR);
+ GuiManager.showMessageBox(e.getMessage(), MessageType.ERROR, LOGGER, e);
return;
}
break;
case BWLP:
- LOGGER.info("bwlp");
BWLPAuthenticator bwlpAuth = new BWLPAuthenticator();
try {
bwlpAuth.login(username, password, new AuthenticatorCallback() {
@Override
- public void postLogin(ReturnCode returnCode, UserInfo user) {
+ public void postLogin(ReturnCode returnCode, UserInfo user, Throwable t) {
// handle errors first
if (returnCode != ReturnCode.NO_ERROR && user == null) {
- LOGGER.error("BWLP login failed.");
- GuiManager.showMessage("Login failed!", SWT.ICON_ERROR);
+ GuiManager.showMessageBox(t.getMessage(), MessageType.ERROR, LOGGER, t);
+ return;
}
+ // success?
if (returnCode == ReturnCode.NO_ERROR && user != null)
postSuccessfulLogin();
}
});
} catch (TAuthenticationException e) {
- GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR);
+ GuiManager.showMessageBox(e.getMessage(), MessageType.ERROR, LOGGER, e);
+ return;
}
break;
case SAT:
@@ -302,7 +317,7 @@ public class LoginWindow extends LoginWindowLayout {
}
/**
- * Functions called by doLogin is the login process succeeded.
+ * Function called by doLogin if the login process succeeded.
*/
private void postSuccessfulLogin() {
LOGGER.info(loginType.getTag() + " succeeded.");