diff options
author | Simon Rettberg | 2024-05-15 16:51:50 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-05-15 16:51:50 +0200 |
commit | e9bdcfe9ffaf6974ce1fbf404279536b7c6368c2 (patch) | |
tree | c84e3b21bf6bd0cb5a46614ad2ae89cf83f5bcfd | |
parent | Update Database classes to match dmsd (diff) | |
download | masterserver-e9bdcfe9ffaf6974ce1fbf404279536b7c6368c2.tar.gz masterserver-e9bdcfe9ffaf6974ce1fbf404279536b7c6368c2.tar.xz masterserver-e9bdcfe9ffaf6974ce1fbf404279536b7c6368c2.zip |
RPC: Add option to set session timeout on creation
4 files changed, 21 insertions, 5 deletions
diff --git a/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java b/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java index 3dff32f..80a4f53 100644 --- a/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java +++ b/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java @@ -19,8 +19,9 @@ public class JsonUser private String lastName = null; private String mail = null; private String role = null; - private String status; - private String error; + private String status = null; + private String error = null; + private int timeoutSeconds = 0; private String accessCode; @@ -54,5 +55,10 @@ public class JsonUser { return this.accessCode; } + + public int timeoutSeconds() + { + return this.timeoutSeconds; + } } diff --git a/src/main/java/org/openslx/imagemaster/localrpc/NetworkHandler.java b/src/main/java/org/openslx/imagemaster/localrpc/NetworkHandler.java index 4416647..ebe6993 100644 --- a/src/main/java/org/openslx/imagemaster/localrpc/NetworkHandler.java +++ b/src/main/java/org/openslx/imagemaster/localrpc/NetworkHandler.java @@ -136,7 +136,7 @@ public class NetworkHandler implements Runnable log.warn( "Invalid or inomplete RPC data (" + payload + ")" ); return "Invalid or incomplete RPC data"; } - ClientSessionData sd = SessionManager.addSession( new Session( u ), ju.accessCode() ); + ClientSessionData sd = SessionManager.addSession( new Session( u, ju.timeoutSeconds() * 1000 ), ju.accessCode() ); return "TOKEN:" + sd.authToken + " SESSIONID:" + sd.sessionId; } } catch ( Throwable t ) { diff --git a/src/main/java/org/openslx/imagemaster/session/Session.java b/src/main/java/org/openslx/imagemaster/session/Session.java index 3cdcd0f..df6dd5c 100644 --- a/src/main/java/org/openslx/imagemaster/session/Session.java +++ b/src/main/java/org/openslx/imagemaster/session/Session.java @@ -14,11 +14,19 @@ public class Session private long timeOut = 0; private final UserInfo user; - + public Session( final UserInfo dbuser ) { + this( dbuser, TIMEOUT ); + } + + public Session( final UserInfo dbuser, long timeout ) + { + if ( timeout <= 0 ) { + timeout = TIMEOUT; + } this.user = dbuser; - this.timeOut = System.currentTimeMillis() + TIMEOUT; + this.timeOut = System.currentTimeMillis() + timeout; } public synchronized void refresh() diff --git a/src/main/java/org/openslx/imagemaster/session/SessionManager.java b/src/main/java/org/openslx/imagemaster/session/SessionManager.java index a7c7cb9..81b8530 100644 --- a/src/main/java/org/openslx/imagemaster/session/SessionManager.java +++ b/src/main/java/org/openslx/imagemaster/session/SessionManager.java @@ -65,6 +65,8 @@ public class SessionManager public static void addAuthError( TAuthorizationException ex, String accessToken ) { + if ( accessToken == null ) + return; accessCodes.put( accessToken, new AccessCode( null, ex ) ); } |