From d684cd4dbdadb11a0017556e802bdf3141336f2b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 10 Jun 2015 20:22:04 +0200 Subject: [server] db stuff, new interface, ... --- .../src/main/java/server/SessionManager.java | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'dozentenmodulserver/src/main/java/server/SessionManager.java') diff --git a/dozentenmodulserver/src/main/java/server/SessionManager.java b/dozentenmodulserver/src/main/java/server/SessionManager.java index 75336de0..3f4d4257 100644 --- a/dozentenmodulserver/src/main/java/server/SessionManager.java +++ b/dozentenmodulserver/src/main/java/server/SessionManager.java @@ -5,7 +5,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import org.apache.log4j.Logger; -import org.openslx.imagemaster.thrift.iface.UserInfo; +import org.openslx.bwlp.thrift.iface.AuthorizationError; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.thrifthelper.ThriftManager; /** @@ -34,12 +36,27 @@ public class SessionManager { // saves the current tokens and the mapped userdata, returning from the server private static Map tokenManager = new ConcurrentHashMap<>(); + /** + * Get the user corresponding to the given token. + * + * @param token user's token + * @return UserInfo for the matching user + * @throws TAuthorizationException if the token is not known or the session + * expired + */ + public static UserInfo getOrFail(String token) throws TAuthorizationException { + UserInfo ui = get(token); + if (ui != null) + return ui; + throw new TAuthorizationException(AuthorizationError.NOT_AUTHENTICATED, + "Your session token is not known to the server"); + } + /** * Get the user corresponding to the given token. Returns null if the token * is not known, or the session already timed out. * - * @param token - * user's token + * @param token user's token * @return UserInfo for the matching user */ public static UserInfo get(String token) { -- cgit v1.2.3-55-g7522