feat: add authentication and tenant context
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user