From e9bdcfe9ffaf6974ce1fbf404279536b7c6368c2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 15 May 2024 16:51:50 +0200 Subject: RPC: Add option to set session timeout on creation --- src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java | 10 ++++++++-- .../org/openslx/imagemaster/localrpc/NetworkHandler.java | 2 +- src/main/java/org/openslx/imagemaster/session/Session.java | 12 ++++++++++-- .../java/org/openslx/imagemaster/session/SessionManager.java | 2 ++ 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 ) ); } -- cgit v1.2.3-55-g7522