Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] function校验失败和不允许 UNKNOWN 用户的 GET 请求 #702

Open
xuming9 opened this issue Apr 12, 2024 · 1 comment
Open

Comments

@xuming9
Copy link

xuming9 commented Apr 12, 2024

APIJSON Version/APIJSON 版本号

6.4.0-springboot3

Database Type & Version/数据库类型及版本号

postgresql16.2和mysql5.7

Environment/环境信息

- JDK/基础库:JDK21
- OS/系统:WINDOWS

APIAuto Screenshots/APIAuto 请求与结果完整截屏

{ "EX_sys_users": { "id": 1 }, "ok": false, "code": 401, "msg": "EX_sys_users 不允许 UNKNOWN 用户的 GET 请求!", "debug:info|help": "浏览器打开以下链接查看解答。。。。}

Current Behavior/问题描述

学习demo中的APIJSONSimpleDemo-SpringBoot3时。遇到2个问题,虽然用曲线救国的方式绕过去了,但感觉作者应该是有专业的解决方式,后续希望能把apijson应用上生产,所以求解惑。

1、APIJSONApplication.init(false);如果改参数为true,必提示function校验失败,不止一个funciton校验失败,检查了看数据库内容感觉不是脚本问题。
报错内容如下:
----------
字符 deleteCommentOfMoment(momentId) 对应的远程函数 deleteCommentOfMoment(JSONObject request, String momentId) 不在后端 apijson.framework.APIJSONFunctionParser 内,也不在父类中!如果需要则先新增对应方法!
请检查函数名和参数数量是否与已定义的函数一致!
且必须为 function(key0,key1,...) 这种单函数格式!
----------
虽然把deleteCommentOfMoment函数的参数改为String后就不报错了,但感觉不应该是String。而且改完这个函数又有其他函数报错。

2、添加表后,在access中增加数据后,就算重启服务也无法自动识别新增表。我的解决方法是:
在启动后增加增加代码APIJSONVerifier.initAccess(false, APIJSONApplication.DEFAULT_APIJSON_CREATOR);
文档中是说无需access,会自动识别,但我暂时没测试出来


代码都是demo中的代码,仅修改了依赖和数据库配置。

Expected Behavior/期望结果

No response

Any additional comments?/其它补充说明?

No response

@xuming9 xuming9 changed the title [Bug] [Bug] function校验失败和不允许 UNKNOWN 用户的 GET 请求 Apr 12, 2024
@TommyLemon
Copy link
Collaborator

TommyLemon commented Apr 19, 2024

@xuming9

1.所有远程函数,在 Function 表配置的参数值都是 String 类型,一般只传 key 名或路径,对应 DemoFunctionParser 中的 Java 方法,第 0 个参数为 JSONObject curObj, 后面的都是 String key0, String key1..., 通过 Long value0 = curObj.getLong(key0) 或 getArgVal(key0) 这样的方式取值

具体见:
#101

2.Access, Function, Request 这些 APIJSON 系统配置表,要么通过重启项目来更新到内存,要么调 /reload 接口来更新。

这个 Demo 是 setNeedVerify(true),默认需要配置 Access 和 Request 表,改成 false 就不用了,但也没了对应的安全检查,只推荐测试时使用:
https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONSimpleDemo-SpringBoot3/src/main/java/com/example/apijsondemo/controller/DemoController.java#L62C1-L63C1

具体见:
https://github.com/APIJSON/apijson_todo_demo/blob/master/FULLTEXT.md#%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6%E8%A7%92%E8%89%B2%E5%92%8C-access-%E8%A1%A8

重启也识别不到变更,这个早期版本是因为超过了 Parser.getMaxQueryCount (默认 100)的限制导致,后面版本在 AbstractSQLConfig.SYSTEM_ACCESS_MAP 中默认配置了 Access 等表,已经不限制加载数量了,可以断点调试下 limitSQLCount 的返回值,对 Access 等配置表应该为 return false:
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L884-L887

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants