1 package org.openecomp.sdc.common.session.impl;
3 import org.openecomp.sdc.common.errors.CoreException;
4 import org.openecomp.sdc.common.errors.ErrorCode;
5 import org.openecomp.sdc.common.session.SessionContext;
6 import org.openecomp.sdc.common.session.SessionContextProvider;
7 import org.openecomp.sdc.common.session.User;
9 public class AsdcSessionContextProvider implements SessionContextProvider {
11 private static final ThreadLocal<String> threadUserId = new ThreadLocal<>();
12 private static final ThreadLocal<String> threadTenant = new ThreadLocal<>();
15 public void create(String userId, String tenant) {
16 threadUserId.set(userId);
17 threadTenant.set(tenant);
21 public SessionContext get() {
22 if (threadUserId.get() == null) {
23 throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage("UserId was not set "
24 + "for this thread").build());
27 if (threadTenant.get() == null) {
28 throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage("Tenant was not set "
29 + "for this thread").build());
32 return new AsdcSessionContext(new User(threadUserId.get()), threadTenant.get());
37 threadUserId.remove();
38 threadTenant.remove();
41 private static class AsdcSessionContext implements SessionContext {
43 private final User user;
44 private final String tenant;
46 private AsdcSessionContext(User user, String tenant) {
52 public User getUser() {
57 public String getTenant() {