45 lines
1.0 KiB
Java
45 lines
1.0 KiB
Java
package com.linhelp.common.security;
|
|
|
|
public final class TenantContext {
|
|
private static final ThreadLocal<Scope> SCOPE = new ThreadLocal<Scope>();
|
|
|
|
private TenantContext() {
|
|
}
|
|
|
|
public static void set(Long tenantId, Long communityId) {
|
|
SCOPE.set(new Scope(tenantId, communityId));
|
|
}
|
|
|
|
public static Long tenantId() {
|
|
Scope scope = SCOPE.get();
|
|
return scope == null ? null : scope.tenantId();
|
|
}
|
|
|
|
public static Long communityId() {
|
|
Scope scope = SCOPE.get();
|
|
return scope == null ? null : scope.communityId();
|
|
}
|
|
|
|
public static void clear() {
|
|
SCOPE.remove();
|
|
}
|
|
|
|
private static class Scope {
|
|
private final Long tenantId;
|
|
private final Long communityId;
|
|
|
|
private Scope(Long tenantId, Long communityId) {
|
|
this.tenantId = tenantId;
|
|
this.communityId = communityId;
|
|
}
|
|
|
|
private Long tenantId() {
|
|
return tenantId;
|
|
}
|
|
|
|
private Long communityId() {
|
|
return communityId;
|
|
}
|
|
}
|
|
}
|