添加context info Handler
This commit is contained in:
parent
519f0c9e13
commit
fed63c5607
@ -7,10 +7,13 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import cn.axzo.framework.auth.domain.ContextInfo;
|
import cn.axzo.framework.auth.domain.ContextInfo;
|
||||||
|
import cn.axzo.framework.auth.domain.contextvalidate.ContextInfoHandler;
|
||||||
|
|
||||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
public @interface PreBuildContext {
|
public @interface PreBuildContext {
|
||||||
Class<? extends ContextInfo> value() default ContextInfo.class;
|
Class<? extends ContextInfo> value() default ContextInfo.class;
|
||||||
|
|
||||||
|
Class<? extends ContextInfoHandler>[] filter() default {};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
package cn.axzo.framework.auth.domain.contextvalidate;
|
||||||
|
|
||||||
|
import cn.axzo.framework.auth.domain.ContextInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tanjie@axzo.cn
|
||||||
|
* @date 2023/3/29 10:59
|
||||||
|
*/
|
||||||
|
public interface ContextInfoHandler {
|
||||||
|
|
||||||
|
void handler(ContextInfo contextInfo);
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package cn.axzo.framework.auth.domain.contextvalidate;
|
||||||
|
|
||||||
|
import cn.axzo.framework.auth.AuthException;
|
||||||
|
import cn.axzo.framework.auth.domain.ContextInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tanjie@axzo.cn
|
||||||
|
* @date 2023/3/29 11:12
|
||||||
|
*/
|
||||||
|
public class VerifyContext implements ContextInfoHandler{
|
||||||
|
@Override
|
||||||
|
public void handler(ContextInfo contextInfo) {
|
||||||
|
Integer verifiedStatus = contextInfo.getUserInfo().getVerifiedStatus();
|
||||||
|
if (2 != verifiedStatus) {
|
||||||
|
throw new AuthException("该功能需要实名认证之后才可使用");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,6 +11,7 @@ import cn.axzo.framework.auth.domain.SystemAndDeviceInfo;
|
|||||||
import cn.axzo.framework.auth.domain.TerminalInfo;
|
import cn.axzo.framework.auth.domain.TerminalInfo;
|
||||||
import cn.axzo.framework.auth.domain.UserInfo;
|
import cn.axzo.framework.auth.domain.UserInfo;
|
||||||
import cn.axzo.framework.auth.domain.UserInfoMap;
|
import cn.axzo.framework.auth.domain.UserInfoMap;
|
||||||
|
import cn.axzo.framework.auth.domain.contextvalidate.ContextInfoHandler;
|
||||||
import cn.axzo.framework.auth.enums.EnvEnum;
|
import cn.axzo.framework.auth.enums.EnvEnum;
|
||||||
import cn.azxo.framework.common.logger.logback.PodNamespacePropertyDefiner;
|
import cn.azxo.framework.common.logger.logback.PodNamespacePropertyDefiner;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
@ -124,7 +125,10 @@ public class ContextInfoBuilderAspect {
|
|||||||
|
|
||||||
// 定制一些信息的处理
|
// 定制一些信息的处理
|
||||||
contextInfo.buildCustomInfo(httpRequest, contextInfo.getUserInfoMap());
|
contextInfo.buildCustomInfo(httpRequest, contextInfo.getUserInfoMap());
|
||||||
|
//针对contextInfo拦截。或修改参数等
|
||||||
|
for (Class<? extends ContextInfoHandler> filter : preBuildContext.filter()) {
|
||||||
|
filter.newInstance().handler(contextInfo);
|
||||||
|
}
|
||||||
// 把ContextInfo放到ThreadLocal中
|
// 把ContextInfo放到ThreadLocal中
|
||||||
ContextInfoHolder.set(contextInfo);
|
ContextInfoHolder.set(contextInfo);
|
||||||
Object[] args = parseContextInfoAndReturnArgs(httpRequest, pjp, contextInfo);
|
Object[] args = parseContextInfoAndReturnArgs(httpRequest, pjp, contextInfo);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user