diff options
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/session/Session.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/session/Session.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/imagemaster/session/Session.java b/src/main/java/org/openslx/imagemaster/session/Session.java new file mode 100644 index 0000000..8dc7f2b --- /dev/null +++ b/src/main/java/org/openslx/imagemaster/session/Session.java @@ -0,0 +1,58 @@ +package org.openslx.imagemaster.session; + +/** + * Simple representation of a user session. Contains user-related data and + * information on whether the session is still valid. + * + */ +public class Session +{ + private static final long TIMEOUT = 600L * 1000L; // TODO: config + + private long timeOut = 0; + private final User user; + + public Session(final User dbuser) + { + this.user = dbuser; + this.timeOut = System.currentTimeMillis() + TIMEOUT; + } + + public synchronized void refresh() + { + if ( timedOut() ) + return; // Don't allow refreshing timed out session + this.timeOut = System.currentTimeMillis() + TIMEOUT; + } + + public synchronized boolean timedOut() + { + return System.currentTimeMillis() > this.timeOut; + } + + public String getSatelliteAddress() + { + return user.satelliteAddress; + } + + public String getUserId() + { + return user.username + "@" + user.organization; + } + + public String getFirstName() + { + return user.firstName; + } + + public String getLastName() + { + return user.lastName; + } + + public String getEMail() + { + return user.eMail; + } + +} |