1. 注意解耦设计,要能够让应用服务集成后,对现有业务没有任何影响

2. 新建 GlobalUserContext 下沉到framework 中,期望代替项目中的 UserContext
3. 其他
This commit is contained in:
zhouman@axzo.cn 2022-03-07 13:47:40 +08:00
parent 24c68826c0
commit 6d527bb148
5 changed files with 70 additions and 0 deletions

View File

@ -10,6 +10,20 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>axzo-framework-header</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.19.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -0,0 +1,14 @@
package cn.axzo.framework.header;
public class GlobalUserContext {
public static final ThreadLocal<GlobalUserInfo> threadLocal = new ThreadLocal<>();
public static GlobalUserInfo get() {
return threadLocal.get();
}
public static void release() {
// TODO
threadLocal.remove();
}
}

View File

@ -0,0 +1,29 @@
package cn.axzo.framework.header;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
public class GlobalUserContextInterceptor {
protected void doBefore() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if(requestAttributes == null) {
return;
}
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
if(request == null) {
return;
}
String authorization = request.getHeader(HeaderConstant.KEY_AUTHORIZATION);
// TODO
// UserInfo tmp = Base64Decoder.decode(authorization);
//
// GlobalUserContext.get().setUserId(tmp.getUserId);
}
protected void doAfter() {
GlobalUserContext.release();
}
}

View File

@ -0,0 +1,7 @@
package cn.axzo.framework.header;
public class GlobalUserInfo {
// 此处放当前登录用户的基本信息
// TODO
}

View File

@ -0,0 +1,6 @@
package cn.axzo.framework.header;
public class HeaderConstant {
public static final String KEY_AUTHORIZATION = "Authorization";
}