merge
This commit is contained in:
parent
d688a68cde
commit
b2c4d121bf
@ -0,0 +1,28 @@
|
|||||||
|
package cn.axzo.framework.auth.domain;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.TypeReference;
|
||||||
|
import cn.hutool.core.util.TypeUtil;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象类型 用于支持类型转换 如 integer -> long
|
||||||
|
* @author zhangtianyu
|
||||||
|
* @date 2022/4/26 3:46 PM
|
||||||
|
**/
|
||||||
|
public class ObjectType<T> extends TypeReference<T> {
|
||||||
|
private final Type objectType;
|
||||||
|
|
||||||
|
public ObjectType(Class<?> clazz) {
|
||||||
|
this.objectType = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectType() {
|
||||||
|
this.objectType = TypeUtil.getTypeArgument(getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getType() {
|
||||||
|
return objectType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package cn.axzo.framework.auth.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求数据
|
||||||
|
* @author zhangtianyu
|
||||||
|
* @date 2022/4/25 10:10 AM
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class RequestInfo {
|
||||||
|
/**
|
||||||
|
* 租户id
|
||||||
|
*/
|
||||||
|
private String tenantId;
|
||||||
|
private String systemType;
|
||||||
|
private String deviceKind;
|
||||||
|
private String deviceNo;
|
||||||
|
private String appVersion;
|
||||||
|
private String token;
|
||||||
|
private String visitTo;
|
||||||
|
/**
|
||||||
|
* 使用http request 设置自定义字段
|
||||||
|
* @param request http请求
|
||||||
|
*/
|
||||||
|
public void buildCustomRequestInfo(HttpServletRequest request) {}
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
package cn.axzo.framework.auth.domain;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存从request header 中获取的UserInfo
|
||||||
|
*
|
||||||
|
* @author zhangtianyu
|
||||||
|
* @date 2022/4/26 2:15 PM
|
||||||
|
**/
|
||||||
|
public class UserInfoMap {
|
||||||
|
private final Map<String, Object> map;
|
||||||
|
|
||||||
|
public UserInfoMap(Map<String, Object> map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取string类型
|
||||||
|
*/
|
||||||
|
public String get(String name) {
|
||||||
|
return get(name, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T get(String name, ObjectType<T> type) {
|
||||||
|
return Convert.convertWithCheck(type, map.get(name), null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取基本类型 例如Long Integer Double
|
||||||
|
*/
|
||||||
|
public <T> T get(String name, Class<T> clazz) {
|
||||||
|
return Convert.convertWithCheck(new ObjectType(clazz), map.get(name), null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取引用类型 例如List<String> List<Long>
|
||||||
|
*/
|
||||||
|
public <T> T getReference(String name) {
|
||||||
|
return Convert.convertWithCheck(new ObjectType<T>(), map.get(name), null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Map<String, Object> getMap() {
|
||||||
|
return this.map;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -46,23 +46,11 @@ public class BuilderUserInfoAspect {
|
|||||||
log.error("can not get request,there is a error occurrence ==>" + exception.getCause().getMessage());
|
log.error("can not get request,there is a error occurrence ==>" + exception.getCause().getMessage());
|
||||||
}
|
}
|
||||||
Assert.notNull(httpRequest, "httpReqeust cant be null, this is error");
|
Assert.notNull(httpRequest, "httpReqeust cant be null, this is error");
|
||||||
this.fillInUserInfoDetail(httpRequest, pjp);
|
|
||||||
//todo request 为null
|
|
||||||
assert httpRequest != null;
|
|
||||||
this.fillInUserInfoDetail(httpRequest, pjp, preBuildUser.requestInfo());
|
this.fillInUserInfoDetail(httpRequest, pjp, preBuildUser.requestInfo());
|
||||||
return pjp.proceed();
|
return pjp.proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillInUserInfoDetail(HttpServletRequest request, ProceedingJoinPoint pjp) {
|
public void fillInUserInfoDetail(HttpServletRequest request, ProceedingJoinPoint pjp, Class<? extends RequestInfo> requestInfoClass) {
|
||||||
//请求头获取数据
|
|
||||||
String tenantId = request.getHeader(AopConstants.HEADER_TENANT);
|
|
||||||
String systemType = request.getHeader(AopConstants.HEADER_SYSTEM_TYPE);
|
|
||||||
String authorization = request.getHeader(AopConstants.HEADER_AUTH);
|
|
||||||
String deviceKind = request.getHeader(AopConstants.HAEDER_DEVICE_KIND);
|
|
||||||
String deviceNo = request.getHeader(AopConstants.HAEDER_DEVICE_NO);
|
|
||||||
String appVersion = request.getHeader(AopConstants.HAEDER_APP_VERSION);
|
|
||||||
String visitTo = request.getHeader(AopConstants.VISIT_TO);
|
|
||||||
|
|
||||||
String userinfoJson = "";
|
String userinfoJson = "";
|
||||||
//本地运行 分两种情况 postMan/junit
|
//本地运行 分两种情况 postMan/junit
|
||||||
//判断本地环境
|
//判断本地环境
|
||||||
@ -111,26 +99,13 @@ public class BuilderUserInfoAspect {
|
|||||||
for (int i = 0; i < parameterTypes.length; i++) {
|
for (int i = 0; i < parameterTypes.length; i++) {
|
||||||
if (parameterTypes[i].isAssignableFrom(UserInfo.class)) {
|
if (parameterTypes[i].isAssignableFrom(UserInfo.class)) {
|
||||||
UserInfo pjpArg = (UserInfo) pjpArgs[i];
|
UserInfo pjpArg = (UserInfo) pjpArgs[i];
|
||||||
buildUserInfoWithAspect(pjpArg, userinfoJson);
|
buildRequestInfo(pjpArg, request, requestInfoClass);
|
||||||
//塞一些系统参数
|
buildUserInfo(pjpArg, userinfoJson);
|
||||||
pjpArg.setAppVersion(appVersion);
|
|
||||||
pjpArg.setDeviceKind(deviceKind);
|
|
||||||
pjpArg.setDeviceNo(deviceNo);
|
|
||||||
pjpArg.setSystemType(systemType);
|
|
||||||
pjpArg.setTenantId(tenantId);
|
|
||||||
pjpArg.setVisitTo(visitTo);
|
|
||||||
pjpArg.setToken(authorization);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildUserInfoWithAspect(UserInfo userInfo, String userJsonInfo) {
|
|
||||||
//todo 直接获取用户信息。
|
|
||||||
Map map = JSONUtil.toBean(userJsonInfo, Map.class);
|
|
||||||
BeanUtil.fillBeanWithMap(map, userInfo, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
//从env/properties 获取my_pod_namespace 的value
|
//从env/properties 获取my_pod_namespace 的value
|
||||||
public String getSystemProperties() {
|
public String getSystemProperties() {
|
||||||
PodNamespacePropertyDefiner podNamespacePropertyDefiner = new PodNamespacePropertyDefiner();
|
PodNamespacePropertyDefiner podNamespacePropertyDefiner = new PodNamespacePropertyDefiner();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user