chore: 去掉部分代码

This commit is contained in:
CaptainB 2024-06-07 11:30:33 +08:00 committed by 刘瑞斌
parent 631f8c5f2c
commit c9dc268569
2 changed files with 1 additions and 30 deletions

View File

@ -7,13 +7,8 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.mapper.ExtCheckOwnerMapper; import io.metersphere.system.mapper.ExtCheckOwnerMapper;
import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.web.util.WebUtils;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
@ -25,8 +20,6 @@ import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
@ -50,16 +43,6 @@ public class CheckOwnerAspect {
@Before("pointcut()") @Before("pointcut()")
public void before(JoinPoint joinPoint) { public void before(JoinPoint joinPoint) {
// apikey 过来的请求
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes != null) {
HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
if (ApiKeyHandler.isApiKeyCall(request) && !SecurityUtils.getSubject().isAuthenticated()) {
String userId = ApiKeyHandler.getUser(WebUtils.toHttp(request));
SecurityUtils.getSubject().login(new UsernamePasswordToken(userId, "no_pass"));
}
}
//从切面织入点处通过反射机制获取织入点处的方法 //从切面织入点处通过反射机制获取织入点处的方法
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//获取切入点所在的方法 //获取切入点所在的方法
@ -158,17 +141,4 @@ public class CheckOwnerAspect {
} }
} }
} }
@After("pointcut()")
public void after() {
// apikey 过来的请求
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes != null) {
HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
// apikey 退出
if (ApiKeyHandler.isApiKeyCall(WebUtils.toHttp(request)) && SecurityUtils.getSubject().isAuthenticated()) {
SecurityUtils.getSubject().logout();
}
}
}
} }

View File

@ -164,6 +164,7 @@
<exclude>io/metersphere/*/job/**</exclude> <exclude>io/metersphere/*/job/**</exclude>
<exclude>io/metersphere/system/notice/**</exclude> <exclude>io/metersphere/system/notice/**</exclude>
<exclude>io/metersphere/system/schedule/**</exclude> <exclude>io/metersphere/system/schedule/**</exclude>
<exclude>io/metersphere/system/security/**</exclude>
</excludes> </excludes>
</configuration> </configuration>
<executions> <executions>