diff options
author | Simon Rettberg | 2015-08-13 15:45:10 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-13 15:45:10 +0200 |
commit | 9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7 (patch) | |
tree | fc32e08b30d5643cf1bbd1753ec6f1cc076a8217 /dozentenmodul/src/main/java/org/openslx/dozmod/thrift | |
parent | [client] Fix positioning of Wizard (diff) | |
download | tutor-module-9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7.tar.gz tutor-module-9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7.tar.xz tutor-module-9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7.zip |
[client] Layout tweaks, Change owner feature
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java | 64 | ||||
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftError.java | 62 |
2 files changed, 104 insertions, 22 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java index 0ff7cf76..2f5059b5 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java @@ -5,7 +5,6 @@ import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.ImagePermissions; import org.openslx.bwlp.thrift.iface.LecturePermissions; import org.openslx.bwlp.thrift.iface.SatelliteConfig; -import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.bwlp.thrift.iface.WhoamiInfo; import org.openslx.thrifthelper.ThriftManager; @@ -13,15 +12,7 @@ public class Session { private static final Logger LOGGER = Logger.getLogger(Session.class); - private static String firstName = null; - - private static String lastName = null; - - private static String eMail = null; - - private static String userId = null; - - private static String organizationId = null; + private static WhoamiInfo data = null; private static String satelliteToken = null; @@ -30,16 +21,15 @@ public class Session { private static String satelliteAddress = null; public static void initialize(WhoamiInfo whoami, String satAddress, String satToken, String masToken) { - UserInfo ui = whoami.getUser(); - if (userId != null && !userId.equals(ui.userId)) + if (whoami == null || whoami.user == null || whoami.user.userId == null) { + throw new IllegalArgumentException( + "Cannot initialize session: whoami-Information from satellite incomplete"); + } + if (data != null && !data.user.userId.equals(whoami.user.userId)) throw new IllegalArgumentException("Cannot set new session data with different user id"); if (satelliteAddress != null && !satelliteAddress.equals(satAddress)) throw new IllegalArgumentException("Cannot set new session data with different satellite address"); - firstName = ui.firstName; - lastName = ui.lastName; - eMail = ui.eMail; - userId = ui.userId; - organizationId = ui.organizationId; + data = whoami; masterToken = masToken; satelliteToken = satToken; satelliteAddress = satAddress; @@ -49,35 +39,65 @@ public class Session { * @return the first name */ public static String getFirstName() { - return firstName; + if (data == null) + return null; + return data.user.firstName; } /** * @return the last name */ public static String getLastName() { - return lastName; + if (data == null) + return null; + return data.user.lastName; } /** * @return the eMail */ public static String getEMail() { - return eMail; + if (data == null) + return null; + return data.user.eMail; } /** * @return the user id */ public static String getUserId() { - return userId; + if (data == null) + return null; + return data.user.userId; } /** * @return the organization id */ public static String getOrganizationId() { - return organizationId; + if (data == null) + return null; + return data.user.organizationId; + } + + /** + * @return whether user is superuser (has all permissions on everything, can + * declare an image a template) + */ + public static boolean isSuperUser() { + if (data == null) + return false; + return data.isSuperUser; + } + + /** + * @return whether user can see list of images. students will only be able + * to list lectures + */ + public static boolean canListImages() { + if (data == null) + return false; + return data.canListImages; } /** diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftError.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftError.java new file mode 100644 index 00000000..fcee1448 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftError.java @@ -0,0 +1,62 @@ +package org.openslx.dozmod.thrift; + +import java.awt.Component; + +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.AuthorizationError; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TInternalServerError; +import org.openslx.bwlp.thrift.iface.TNotFoundException; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.MessageType; + +public class ThriftError { + + public static void showMessage(Component parent, Logger logger, TException ex, String messageText) { + if (ex instanceof TNotFoundException) { + messageText += "\n\nNicht gefunden"; + } else if (ex instanceof TAuthorizationException) { + String reason = getString(((TAuthorizationException) ex).getNumber()); + messageText += "\n\nZugriff verweigert: " + reason + "\n" + ex.getMessage(); + } else if (ex instanceof TInternalServerError) { + messageText += "\n\nEin serverseitiger Fehler ist aufgetreten. Bitte kontaktieren Sie den lokalen Support."; + } else { + messageText += "\n\nUnerwartete Ausnahme " + ex.getClass().getSimpleName() + " ist aufgetreten."; + } + logger.warn("A thrift call raised an exception", ex); + Gui.showMessageBox(parent, messageText, MessageType.ERROR, null, null); + } + + public static String getString(AuthorizationError error) { + if (error == null) + return "(AuthorizationError=null)"; + switch (error) { + case ACCOUNT_SUSPENDED: + return "Das Benutzerkonto ist gesperrt"; + case BANNED_NETWORK: + return "Das Netzwerk, aus dem Sie operieren, ist gesperrt"; + case CHALLENGE_FAILED: + return "Challenge fehlgeschlagen"; + case GENERIC_ERROR: + return "Generischer Fehler"; + case INVALID_CREDENTIALS: + return "Ungültige Zugangsdaten"; + case INVALID_KEY: + return "Ungültiger Schlüssel"; + case INVALID_ORGANIZATION: + return "Ungültige oder unbekannte Organisation"; + case INVALID_TOKEN: + return "Ungültiges Sitzungstoken"; + case NOT_AUTHENTICATED: + return "Nicht authentifiziert"; + case NO_PERMISSION: + return "Keine ausreichenden Berechtigungen"; + case ORGANIZATION_SUSPENDED: + return "Ihre zugehörige Organisation ist gesperrt"; + default: + return "Unbekannter Fehlercode: " + error.toString(); + } + } + +} |