package com.linhelp.common.security; public final class TenantContext { private static final ThreadLocal SCOPE = new ThreadLocal(); 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; } } }