blob: 1f4cf0b07e259825da6b2e015b0e2bf5527d4b20 (
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
package org.openslx.dozmod.thrift;
import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ClientSessionData;
import org.openslx.bwlp.thrift.iface.SessionData;
import org.openslx.bwlp.thrift.iface.TInvalidTokenException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.authentication.ServiceProviderResponse;
import org.openslx.thrifthelper.ThriftManager;
public class Session {
private static String firstName = null;
private static String lastName = null;
private static String eMail = null;
private static String userId = null;
private static String organizationId = null;
private static String satelliteToken = null;
private static String masterToken = null;
public static void fromClientSessionData(ClientSessionData session) {
if (userId != null && !userId.equals(session.userInfo.userId))
throw new IllegalArgumentException("Cannot set new session data with different user id!");
firstName = session.userInfo.firstName;
lastName = session.userInfo.lastName;
eMail = session.userInfo.eMail;
userId = session.userInfo.userId;
masterToken = session.sessionId;
satelliteToken = session.authToken;
}
public static void fromSessionData(SessionData session) throws TInvalidTokenException, TException {
// TODO: This is legacy API, switch to ClientSessionData asap
UserInfo ui = ThriftManager.getMasterClient().getUserFromToken(session.authToken);
if (userId != null && !userId.equals(ui.userId))
throw new IllegalArgumentException("Cannot set new session data with different user id!");
firstName = ui.firstName;
lastName = ui.lastName;
eMail = ui.eMail;
userId = ui.userId;
masterToken = session.sessionId;
satelliteToken = session.authToken;
}
public static void fromEcpLogin(ServiceProviderResponse response) {
if (userId != null && !userId.equals(response.userId))
throw new IllegalArgumentException("Cannot set new session data with different user id!");
firstName = response.firstName;
lastName = response.lastName;
eMail = response.mail;
userId = response.userId;
organizationId = response.organizationId;
masterToken = response.sessionId;
satelliteToken = response.token;
}
/**
* @return the first name
*/
public static String getFirstName() {
return firstName;
}
/**
* @return the last name
*/
public static String getLastName() {
return lastName;
}
/**
* @return the eMail
*/
public static String getEMail() {
return eMail;
}
/**
* @return the user id
*/
public static String getUserId() {
return userId;
}
/**
* @return the organization id
*/
public static String getOrganizationId() {
return organizationId;
}
/**
* @return the satellite token
*/
public static String getSatelliteToken() {
return satelliteToken;
}
/**
* @return the master token
*/
public static String getMasterToken() {
return masterToken;
}
}
|