parent
8c887eb350
commit
2798c5f879
|
@ -0,0 +1,22 @@
|
|||
package cc.iotkit.common.web.config;
|
||||
|
||||
import cc.iotkit.common.web.interceptor.TenantInterceptor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* 注册租户ID拦截器.
|
||||
*
|
||||
* @author Tiger Chen
|
||||
* created on 2023/7/15 14:48
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class TenantConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new TenantInterceptor());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package cc.iotkit.common.web.interceptor;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 新增租户拦截器,拦截请求头中的租户id
|
||||
*
|
||||
* @author Tiger Chen
|
||||
* created on 2023/7/15 14:26
|
||||
*/
|
||||
|
||||
|
||||
public class TenantInterceptor implements HandlerInterceptor {
|
||||
|
||||
public static final String TENANT_ID = "Tenant-Id";
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
if (request.getHeader(TENANT_ID) != null) {
|
||||
String tenantId = request.getHeader(TENANT_ID);
|
||||
SaHolder.getStorage().set("tenantId", tenantId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
}
|
||||
}
|
|
@ -212,8 +212,6 @@
|
|||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
<version>5.8.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue