|
@@ -33,9 +33,10 @@ public class AuthAop {
|
|
|
@Value("${authorUrl}")
|
|
|
private String url;
|
|
|
@Autowired
|
|
|
- private CacheUtils cacheUtils ;
|
|
|
+ private CacheUtils cacheUtils;
|
|
|
@Autowired
|
|
|
- private LoginUtils loginUtils ;
|
|
|
+ private LoginUtils loginUtils;
|
|
|
+
|
|
|
/**
|
|
|
* 定义切点
|
|
|
*/
|
|
@@ -43,6 +44,7 @@ public class AuthAop {
|
|
|
public void annotationPointcut() {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
@Before("annotationPointcut()")
|
|
|
public void beforePointcut(JoinPoint joinPoint) {
|
|
|
// 此处进入到方法前 可以实现一些业务逻辑
|
|
@@ -52,73 +54,74 @@ public class AuthAop {
|
|
|
|
|
|
@Around("annotationPointcut()")
|
|
|
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
- Boolean isPass =true;
|
|
|
+ Boolean isPass = true;
|
|
|
// 获得注解上的参数值
|
|
|
MethodSignature ms = (MethodSignature) joinPoint.getSignature();
|
|
|
Method method = ms.getMethod();
|
|
|
checkAuth myAnnotation = method.getAnnotation(checkAuth.class);
|
|
|
- String functionId =myAnnotation.FunId();
|
|
|
+ String functionId = myAnnotation.FunId();
|
|
|
//RequestContextHolder:持有上下文的Request容器,获取到当前请求的request
|
|
|
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
|
|
|
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
|
|
|
HttpServletRequest httpRequest = sra.getRequest();
|
|
|
- String tem =httpRequest.getHeader("Cookie");//获得请求里的token
|
|
|
+ String tem = httpRequest.getHeader("Cookie");//获得请求里的token
|
|
|
Object[] args = joinPoint.getArgs();
|
|
|
//根据登录人的id以及功能id获得计算逻辑
|
|
|
- RequestBody requestBody = new FormBody.Builder()
|
|
|
+ RequestBody requestBody = new FormBody.Builder()
|
|
|
.add("loginId", loginUtils.getId().toString())
|
|
|
- .add("functionId",functionId)
|
|
|
+ .add("functionId", functionId)
|
|
|
.build();
|
|
|
OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
- .url(url+"/permission/api/data/queryDataRule")
|
|
|
- .addHeader("Cookie",tem)
|
|
|
+ .url(url + "/permission/api/data/queryDataRule")
|
|
|
+ .addHeader("Cookie", tem)
|
|
|
.post(requestBody)
|
|
|
.build();
|
|
|
String resBody = okHttpClient.newCall(request).execute().body().string();
|
|
|
JSONArray jsonArray = JSONArray.parseArray(resBody);
|
|
|
- if(jsonArray.get(0).toString().equals("-1")){
|
|
|
- return Response.error("没有该功能");
|
|
|
+ if (jsonArray.get(0).toString().equals("-1")) {
|
|
|
+ return Response.error("没有该功能");
|
|
|
}
|
|
|
//判断是否含有功能并且是不做限制
|
|
|
- else if(jsonArray.size()==1&&jsonArray.get(0).equals("0")){
|
|
|
+ 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")
|
|
|
- .build();
|
|
|
- //处理jsonObject,变为(x==y)&&(z==t)的形式 ,并用js引擎进行boolean判断
|
|
|
- //建立连接
|
|
|
- OkHttpClient okHttpClientSou = new OkHttpClient();
|
|
|
- Request requestSou = new Request.Builder()
|
|
|
- .url(url+"/permission/api/data/getDataSource")
|
|
|
- .post(reBodySource)
|
|
|
- .addHeader("Cookie",LoginUtils.getToken())
|
|
|
- .build();
|
|
|
- //获得请求返回
|
|
|
- String resSource = okHttpClientSou.newCall(requestSou).execute().body().string();
|
|
|
-
|
|
|
- JSONArray jsonArray1 = JSON.parseArray(resSource);
|
|
|
- // 获得字典
|
|
|
- List<DataSource> dataSources=jsonArray1.toJavaList(DataSource.class);
|
|
|
- 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;
|
|
|
- }
|
|
|
- //js引擎进行判断
|
|
|
- ScriptEngineManager manager = new ScriptEngineManager();
|
|
|
- ScriptEngine engine = manager.getEngineByName("javascript");//根据名字获得引擎
|
|
|
- Object result = engine.eval(sqls);//进行判断
|
|
|
- isPass =(Boolean) result;
|
|
|
- }
|
|
|
+ if (jsonArray.size() > 0) { // 如果查询结果的size大于0证明有限制逻辑
|
|
|
+ RequestBody reBodySource = new FormBody.Builder()
|
|
|
+ .add("tableName", "local")
|
|
|
+ .build();
|
|
|
+ //处理jsonObject,变为(x==y)&&(z==t)的形式 ,并用js引擎进行boolean判断
|
|
|
+ //建立连接
|
|
|
+ OkHttpClient okHttpClientSou = new OkHttpClient();
|
|
|
+ Request requestSou = new Request.Builder()
|
|
|
+ .url(url + "/permission/api/data/getDataSource")
|
|
|
+ .post(reBodySource)
|
|
|
+ .addHeader("Cookie", LoginUtils.getToken())
|
|
|
+ .build();
|
|
|
+ //获得请求返回
|
|
|
+ String resSource = okHttpClientSou.newCall(requestSou).execute().body().string();
|
|
|
+
|
|
|
+ JSONArray jsonArray1 = JSON.parseArray(resSource);
|
|
|
+ // 获得字典
|
|
|
+ List<DataSource> dataSources = jsonArray1.toJavaList(DataSource.class);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ //js引擎进行判断
|
|
|
+ ScriptEngineManager manager = new ScriptEngineManager();
|
|
|
+ ScriptEngine engine = manager.getEngineByName("javascript");//根据名字获得引擎
|
|
|
+ Object result = engine.eval(sqls);//进行判断
|
|
|
+ isPass = (Boolean) result;
|
|
|
+ }
|
|
|
|
|
|
//判断不通过通过
|
|
|
- if(!isPass){
|
|
|
- return Response.error("没有权限进行该操作"); }
|
|
|
+ if (!isPass) {
|
|
|
+ return Response.error("没有权限进行该操作");
|
|
|
+ }
|
|
|
|
|
|
//判断通过
|
|
|
return joinPoint.proceed();
|
|
@@ -126,6 +129,7 @@ public class AuthAop {
|
|
|
|
|
|
/**
|
|
|
* 在切入点return内容之后切入内容(可以用来对处理返回值做一些加工处理)
|
|
|
+ *
|
|
|
* @param joinPoint
|
|
|
*/
|
|
|
@AfterReturning("annotationPointcut()")
|