blob: 53a40a163f5f3778d62352ff8befb2abc5268839 (
plain)
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
|
package org.openecomp.sdc.common.session.impl;
import org.openecomp.sdc.common.session.SessionContext;
import org.openecomp.sdc.common.session.SessionContextProvider;
import org.openecomp.sdc.common.session.User;
public class AsdcSessionContextProvider implements SessionContextProvider {
private static final ThreadLocal<String> threadUserId = new ThreadLocal<>();
@Override
public void create(String userId) {
threadUserId.set(userId);
}
@Override
public SessionContext get() {
if (threadUserId.get() == null) {
throw new RuntimeException("UserId was not set for this thread");
}
return new AsdcSessionContext(new User(threadUserId.get()), "dox");
}
@Override
public void close() {
threadUserId.remove();
}
private static class AsdcSessionContext implements SessionContext {
private final User user;
private final String tenant;
private AsdcSessionContext(User user, String tenant) {
this.user = user;
this.tenant = tenant;
}
@Override
public User getUser() {
return user;
}
@Override
public String getTenant() {
return tenant;
}
}
}
|