| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fc32205 commit 989ef75
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,7 +126,10 @@ public static boolean verify(SQLConfig config, User visitor) throws Exception { | |||
| 126 | 126 | return true; | |
| 127 | 127 | } | |
| 128 | 128 | RequestRole role = config.getRole(); | |
| 129 | - | ||
| 129 | + if (role == null) { | ||
| 130 | + role = RequestRole.UNKNOWN; | ||
| 131 | + } | ||
| 132 | + | ||
| 130 | 133 | long userId = visitor == null ? 0 : visitor.getId(); | |
| 131 | 134 | //TODO 暂时去掉,方便测试 | |
| 132 | 135 | if (role != RequestRole.UNKNOWN) {//未登录的角色 | |
@@ -143,9 +146,7 @@ public static boolean verify(SQLConfig config, User visitor) throws Exception { | |||
| 143 | 146 | String userIdkey = Controller.USER_.equals(config.getTable()) || Controller.PRIVACY_.equals(config.getTable()) | |
| 144 | 147 | ? Controller.ID : Controller.USER_ID; | |
| 145 | 148 | ||
| 146 | - if (role == null) { | ||
| 147 | - role = RequestRole.UNKNOWN; | ||
| 148 | - } | ||
| 149 | + Number requestId; | ||
| 149 | 150 | switch (role) { | |
| 150 | 151 | case LOGIN://verifyRole通过就行 | |
| 151 | 152 | break; | |
@@ -160,7 +161,7 @@ public static boolean verify(SQLConfig config, User visitor) throws Exception { | |||
| 160 | 161 | } | |
| 161 | 162 | ||
| 162 | 163 | //key!{}:[] 或 其它没有明确id的条件 等 可以和key{}:list组合。类型错误就报错 | |
| 163 | - Number requestId = (Number) config.getWhere(userIdkey, true);//JSON里数值不能保证是Long,可能是Integer | ||
| 164 | + requestId = (Number) config.getWhere(userIdkey, true);//JSON里数值不能保证是Long,可能是Integer | ||
| 164 | 165 | JSONArray requestIdArray = (JSONArray) config.getWhere(userIdkey + "{}", true);//不能是 &{}, |{} 不要传,直接{} | |
| 165 | 166 | if (requestId != null) { | |
| 166 | 167 | if (requestIdArray == null) { | |
@@ -181,16 +182,18 @@ public static boolean verify(SQLConfig config, User visitor) throws Exception { | |||
| 181 | 182 | throw new UnsupportedDataTypeException(table + ".id类型错误,id类型必须是Long!"); | |
| 182 | 183 | } | |
| 183 | 184 | if (list.contains(new Long("" + id)) == false) {//Integer等转为Long才能正确判断。强转崩溃 | |
| 184 | - if (method == null) { | ||
| 185 | - method = GET; | ||
| 186 | - } | ||
| 187 | 185 | throw new IllegalAccessException(userIdkey + " = " + id + " 的 " + table | |
| 188 | 186 | + " 不允许 " + role.name() + " 用户的 " + method.name() + " 请求!"); | |
| 189 | 187 | } | |
| 190 | 188 | } | |
| 191 | 189 | } | |
| 192 | 190 | break; | |
| 193 | 191 | case OWNER: | |
| 192 | + requestId = (Number) config.getWhere(userIdkey, true);//JSON里数值不能保证是Long,可能是Integer | ||
| 193 | + if (requestId != null && requestId.longValue() != userId) { | ||
| 194 | + throw new IllegalAccessException(userIdkey + " = " + requestId + " 的 " + table | ||
| 195 | + + " 不允许 " + role.name() + " 用户的 " + method.name() + " 请求!"); | ||
| 196 | + } | ||
| 194 | 197 | config.addWhere(userIdkey, userId); | |
| 195 | 198 | break; | |
| 196 | 199 | case ADMIN://这里不好做,在特定接口内部判断? TODO /get/admin + 固定秘钥 Parser#noVerify,之后全局跳过验证 | |
@@ -253,9 +256,9 @@ public static void verifyLogin(Long userId) throws Exception { | |||
| 253 | 256 | throw new NotLoggedInException("未登录,请登录后再操作!"); | |
| 254 | 257 | } | |
| 255 | 258 | } | |
| 256 | - | ||
| 257 | - | ||
| 258 | - | ||
| 259 | + | ||
| 260 | + | ||
| 261 | + | ||
| 259 | 262 | /**验证是否重复 | |
| 260 | 263 | * @param table | |
| 261 | 264 | * @param key | |
@@ -296,7 +299,7 @@ public static void verifyRepeat(String table, String key, Object value, long exc | |||
| 296 | 299 | throw new ConflictException(key + ": " + value + " 已经存在,不能重复!"); | |
| 297 | 300 | } | |
| 298 | 301 | } | |
| 299 | - | ||
| 302 | + | ||
| 300 | 303 | ||
| 301 | 304 | /**获取来访用户的id | |
| 302 | 305 | * @author Lemon | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,6 +160,7 @@ public SQLConfig(RequestMethod method, int count, int page) { | |||
| 160 | 160 | setPage(page); | |
| 161 | 161 | } | |
| 162 | 162 | ||
| 163 | + @NotNull | ||
| 163 | 164 | public RequestMethod getMethod() { | |
| 164 | 165 | if (method == null) { | |
| 165 | 166 | method = GET; | |
@@ -182,6 +183,7 @@ public SQLConfig setId(long id) { | |||
| 182 | 183 | } | |
| 183 | 184 | ||
| 184 | 185 | public RequestRole getRole() { | |
| 186 | + //不能 @NotNull , Parser#getSQLObject 内当getRole() == null时填充默认值 | ||
| 185 | 187 | return role; | |
| 186 | 188 | } | |
| 187 | 189 | public SQLConfig setRole(String roleName) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments