summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/session/Session.java
blob: ed3627435ee37d526d30da030b64ddf824044d38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.openslx.imagemaster.session;

import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.imagemaster.Globals;

/**
 * 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 = Long.valueOf( Globals.getSessionTimeoutUser() ) * 1000L;

	private long timeOut = 0;
	private final UserInfo user;

	public Session( final UserInfo 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 this.timeOut == 0 || System.currentTimeMillis() > this.timeOut;
	}

	public synchronized void invalidate()
	{
		this.timeOut = 0;
	}

	public String getLogin()
	{
		return user.userId;
	}

	public String getFirstName()
	{
		return user.firstName;
	}

	public String getLastName()
	{
		return user.lastName;
	}

	public String getEMail()
	{
		return user.eMail;
	}

	public String getOrgenizationId()
	{
		return user.organizationId;
	}

	public UserInfo getUserInfo()
	{
		return user;
	}

}