|
@@ -5,8 +5,6 @@ import cn.cslg.pas.common.model.PersonnelVO;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
import cn.cslg.pas.common.utils.Response;
|
|
|
import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
|
|
|
-import cn.dev33.satoken.exception.NotLoginException;
|
|
|
-import cn.hutool.json.JSONString;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -14,11 +12,9 @@ import okhttp3.*;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.*;
|
|
|
-import org.aspectj.lang.reflect.CodeSignature;
|
|
|
import org.aspectj.lang.reflect.MethodSignature;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.context.request.RequestAttributes;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
@@ -27,7 +23,6 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
import javax.script.ScriptEngine;
|
|
|
import javax.script.ScriptEngineManager;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.lang.reflect.Field;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -57,37 +52,22 @@ public class AuthAop {
|
|
|
|
|
|
@Around("annotationPointcut()")
|
|
|
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ Boolean isPass =true;
|
|
|
// 获得注解上的参数值
|
|
|
MethodSignature ms = (MethodSignature) joinPoint.getSignature();
|
|
|
Method method = ms.getMethod();
|
|
|
checkAuth myAnnotation = method.getAnnotation(checkAuth.class);
|
|
|
- Integer functionId =myAnnotation.FunId();
|
|
|
- // 将请求里的token保存到字段token里
|
|
|
+ String functionId =myAnnotation.FunId();
|
|
|
//RequestContextHolder:持有上下文的Request容器,获取到当前请求的request
|
|
|
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
|
|
|
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
|
|
|
HttpServletRequest httpRequest = sra.getRequest();
|
|
|
- String tem =httpRequest.getHeader("Cookie");
|
|
|
+ String tem =httpRequest.getHeader("Cookie");//获得请求里的token
|
|
|
Object[] args = joinPoint.getArgs();
|
|
|
- //遍历参数 修改带有需求字段对象的值
|
|
|
- for (Object obj : args) {
|
|
|
- try {
|
|
|
- Class<?> resultClz = obj.getClass();
|
|
|
- //获取class里的所有字段 父类字段获取不到
|
|
|
- Field[] fieldInfo = resultClz.getFields();
|
|
|
- for (Field field : fieldInfo) {
|
|
|
- if ("token".equals(field.getName())) {
|
|
|
- field.set(obj,tem);
|
|
|
- break; }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
//根据登录人的id以及功能id获得计算逻辑
|
|
|
RequestBody requestBody = new FormBody.Builder()
|
|
|
.add("loginId", loginUtils.getId().toString())
|
|
|
- .add("functionId",functionId.toString())
|
|
|
+ .add("functionId",functionId)
|
|
|
.build();
|
|
|
OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
|
|
@@ -98,8 +78,13 @@ public class AuthAop {
|
|
|
.build();
|
|
|
String resBody = okHttpClient.newCall(request).execute().body().string();
|
|
|
JSONArray jsonArray = JSONArray.parseArray(resBody);
|
|
|
-
|
|
|
- Boolean isPass =true;
|
|
|
+ if(jsonArray.get(0).toString().equals("-1")){
|
|
|
+ return Response.error("没有该功能");
|
|
|
+ }
|
|
|
+ //判断是否含有功能并且是不做限制
|
|
|
+ else if(jsonArray.size()==1&&jsonArray.get(0).equals("0")){
|
|
|
+ return joinPoint.proceed();
|
|
|
+ }
|
|
|
if(jsonArray.size()>0){ // 如果查询结果的size大于0证明有限制逻辑
|
|
|
RequestBody reBodySource = new FormBody.Builder()
|
|
|
.add("tableName", "local")
|
|
@@ -121,7 +106,6 @@ public class AuthAop {
|
|
|
PersonnelVO personnelVO =cacheUtils.getLoginUserPersonnel(loginUtils.getId());
|
|
|
String sqls ="";
|
|
|
for(int i=0;i<jsonArray.size();i++){
|
|
|
-
|
|
|
String sql=TreeUtils.reCompute(JSONObject.parseObject(jsonArray.get(i).toString()),args,dataSources,personnelVO);
|
|
|
sqls += jsonArray.size()!=i+1 ? sql+" || ":sql;
|
|
|
}
|