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

fix auth plugin Page #11300

Merged
merged 22 commits into from
Nov 24, 2023
Merged

fix auth plugin Page #11300

merged 22 commits into from
Nov 24, 2023

Conversation

huangkemingyyds
Copy link
Contributor

@huangkemingyyds huangkemingyyds commented Oct 29, 2023

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

#11299
1.修复auth模块用户,角色,权限查询分页失效的问题。

Brief changelog

  1. auth模块调整为根据数据源选择适配器,进行分页辅助查询。
  2. 默认提供辅助查询三个适配器,msyql、derby、default(不做任何处理)。
  3. 使用AuthPaginationHelper 替换 PaginationHelper,尽可能得保持解耦persistence service。

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

Copy link
Collaborator

@KomachiSion KomachiSion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI not passed

@huangkemingyyds
Copy link
Contributor Author

CI not passed

本次修改没有修改到core模块哦。 Ci异常是某个测试类没有通过。

@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2023

Codecov Report

Merging #11300 (6f8167d) into develop (f42b296) will decrease coverage by 0.80%.
Report is 16 commits behind head on develop.
The diff coverage is 19.25%.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             develop   #11300      +/-   ##
=============================================
- Coverage      58.42%   57.62%   -0.80%     
- Complexity      5752     6429     +677     
=============================================
  Files            885     1059     +174     
  Lines          27356    31354    +3998     
  Branches        2890     3243     +353     
=============================================
+ Hits           15982    18067    +2085     
- Misses         10156    11974    +1818     
- Partials        1218     1313      +95     
Files Coverage Δ
...cos/persistence/constants/PersistenceConstant.java 0.00% <ø> (ø)
...ntrol/connection/response/ConnectionCheckCode.java 0.00% <ø> (ø)
...ository/embedded/EmbeddedPaginationHelperImpl.java 0.00% <0.00%> (ø)
...y/extrnal/ExternalStoragePaginationHelperImpl.java 0.00% <0.00%> (ø)
...os/plugin/auth/impl/constant/AuthPageConstant.java 0.00% <0.00%> (ø)
...pl/persistence/EmbeddedRolePersistServiceImpl.java 56.25% <83.33%> (ø)
...pl/persistence/EmbeddedUserPersistServiceImpl.java 57.40% <66.66%> (ø)
...pl/persistence/ExternalRolePersistServiceImpl.java 44.82% <90.00%> (ø)
...pl/persistence/ExternalUserPersistServiceImpl.java 41.55% <87.50%> (ø)
...sistence/EmbeddedPermissionPersistServiceImpl.java 38.29% <60.00%> (ø)
... and 8 more

... and 259 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f42b296...6f8167d. Read the comment docs.

@KomachiSion
Copy link
Collaborator

其他的CI可以通过,只有你修改后的PR不通过的话, 应该是修改的地方间接影响到了对应的UT,需要修复代码。而不是直接改UT

@huangkemingyyds
Copy link
Contributor Author

huangkemingyyds commented Oct 30, 2023

其他的CI可以通过,只有你修改后的PR不通过的话, 应该是修改的地方间接影响到了对应的UT,需要修复代码。而不是直接改UT

1.我需要确认,我未提交PR之前。这两个DefaultTlsContextBuilderTest,DefaultTlsProtocolNegotiatorBuilderTest是否能正常运行?
2.我未提交PR之前,我本地这两个DefaultTlsContextBuilderTest,DefaultTlsProtocolNegotiatorBuilderTest不能正常确认。所以我提了两个PR.
3. @KomachiSion 我需要确定第一点。

@KomachiSion
Copy link
Collaborator

DefaultTlsContextBuilderTest.java

这个文件在另外一个PR合并了, 这个PR应该rebase一下develop分支。

@huangkemingyyds
Copy link
Contributor Author

DefaultTlsContextBuilderTest.java

这个文件在另外一个PR合并了, 这个PR应该rebase一下develop分支。

done

*
* @author hkm
*/
public class DialectFactory {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个设计不太好, 实际上数据源已经插件化, 不应该强制感知数据库类型,如果需要类似Dialect的东西, 最好在插件测实现。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以看下 datasource-plugin模块

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个设计不太好, 实际上数据源已经插件化, 不应该强制感知数据库类型,如果需要类似Dialect的东西, 最好在插件测实现。

我也有思考过这个问题。

  1. 现在persistence 模块 是单独存在的,不依赖于 datasource-plugin模块。
  2. 但是PaginationHelper类这个分页是写在persistence模块下的。 如果不在persistence 模块下做数据分页查询条件的适配的话,更换数据源,会导致那么用户、角色等分页查询失效。
  3. 我认为现在最小的改动,就是在persistence 下将nacos所有支持的数据源类型,对应分页查询条件补齐Dialect类型。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者说 PaginationHelper 目前只支持实现类:

  1. ExternalStoragePaginationHelperImpl-mysql 、
  2. EmbeddedPaginationHelperImpl-derby。
  3. 后续继续增加实现类。xxxxHelperImpl-xxx。

已这种方式来弥补分页失效的问题。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 如果选择 DialectFactory 的方式。我可以补充好其他数据源的数据类型 ,继续PR。
  2. 或者说有更好的方式,我将关闭PR。

@KomachiSion
Copy link
Collaborator

数据库类型的感知应该有datasource插件来做, 如果你需要加这个Dialect来进行分页的辅助,需要在不同的插件实现中进行实现,而不是把所有数据库的实现都放在nacos中来做。

@KomachiSion KomachiSion added the pending On hold due to dependency or release label Nov 6, 2023
@huangkemingyyds
Copy link
Contributor Author

像 auth这个模块,不依赖于 datasource插件,要使用分页查询。 又该如何实现? 比如下面这个接口:
http://localhost:8848/nacos/v1/auth/users?pageNo=1&pageSize=2&search=accurate

@KomachiSion
Copy link
Collaborator

在auth模块自己实现,auth模块甚至可以使用jpa直接替换persistence service

@KomachiSion
Copy link
Collaborator

在auth模块自己实现,auth模块甚至可以使用jpa直接替换persistence service

插件之间不应该互相依赖和影响。

@huangkemingyyds
Copy link
Contributor Author

在auth模块自己实现,auth模块甚至可以使用jpa直接替换persistence service

插件之间不应该互相依赖和影响。

  1. 我个人认为PaginationHelper 在项目中定位为一种基础组件,Dialect支持感知数据源,辅助分页查询。并且随着数据源增多,只需迭代Dialect。好处是在拓展其他数据源的时候,不用在查询sql中手动的拼写查询条件,交给Dialect来处理。
  2. 像分页辅助Dialect这种具有共性的组件,却没有统一管理的地方。其他模块有使用到的地方,得重新编写,应该是重复开发了 。

@huangkemingyyds
Copy link
Contributor Author

在auth模块自己实现,auth模块甚至可以使用jpa直接替换persistence service

插件之间不应该互相依赖和影响。

  1. 我个人认为PaginationHelper 在项目中定位为一种基础组件,Dialect支持感知数据源,辅助分页查询。并且随着数据源增多,只需迭代Dialect。好处是在拓展其他数据源的时候,不用在查询sql中手动的拼写查询条件,交给Dialect来处理。
  2. 像分页辅助Dialect这种具有共性的组件,却没有统一管理的地方。其他模块有使用到的地方,得重新编写,应该是重复开发了 。
    补充 :3. 如果auth自己实现分页查询,也是要根据数据源拼接参数的。

@KomachiSion

@KomachiSion
Copy link
Collaborator

PaginationHelper 可以作为基础接口,但是不管实现。

Dialect既然是适配的实现,就应该在实现的插件里面去实现, 插件管理器不应该有。if是a插件,if是b插件的逻辑,就应该是getDialect,然后Dialect.xxx().

@huangkemingyyds
Copy link
Contributor Author

PaginationHelper 可以作为基础接口,但是不管实现。

Dialect既然是适配的实现,就应该在实现的插件里面去实现, 插件管理器不应该有。if是a插件,if是b插件的逻辑,就应该是getDialect,然后Dialect.xxx().

  1. 那既然是这样的话,那auth模块,角色、用户、权限的查询分页,就不能依赖persistence service中的PaginationHelper。
  2. bug不存在于 PaginationHelper分页。 而是auth模块没有分页查询的适配了。
  3. 是否要在auth写数据源分页适配查询的逻辑?

@KomachiSion
Copy link
Collaborator

PaginationHelper 可以作为基础接口,但是不管实现。
Dialect既然是适配的实现,就应该在实现的插件里面去实现, 插件管理器不应该有。if是a插件,if是b插件的逻辑,就应该是getDialect,然后Dialect.xxx().

  1. 那既然是这样的话,那auth模块,角色、用户、权限的查询分页,就不能依赖persistence service中的PaginationHelper。
  2. bug不存在于 PaginationHelper分页。 而是auth模块没有分页查询的适配了。
  3. 是否要在auth写数据源分页适配查询的逻辑?
  1. 正确,auth模块是独立模块,其实不应该依赖任何底层模块,当前的默认实现在逐渐排除对nacos server模块的依赖。
  2. 那就只需要在auth模块中修复即可。
  3. auth插件是auth插件, auth插件只支持MySQL数据库,不涉及多数据源适配,需要适配的话就自行开发对应数据源的auth插件; 或者将默认鉴权插件和persistence也解耦,直接使用spring jpa来处理数据库操作。

@huangkemingyyds huangkemingyyds changed the title Optimize paginated queries based on data sources fix auth plugin Page, add dataSource plugin Dialect Nov 18, 2023
Copy link
Collaborator

@KomachiSion KomachiSion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@huangkemingyyds
Copy link
Contributor Author

看完你的实现, 感觉和插件base中的这部分实现有一定重复了。

你看下是不是。

https://github.com/nacos-group/nacos-plugin/blob/develop/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/AbstractDatabaseDialect.java
是有重复了 我这边去掉吧

@huangkemingyyds huangkemingyyds changed the title fix auth plugin Page, add dataSource plugin Dialect fix auth plugin Page Nov 20, 2023
@KomachiSion KomachiSion added plugin kind/bug Category issues or prs related to bug. and removed pending On hold due to dependency or release labels Nov 24, 2023
@KomachiSion KomachiSion added this to the 2.3.0 milestone Nov 24, 2023
@KomachiSion KomachiSion merged commit 736948f into alibaba:develop Nov 24, 2023
6 checks passed
Bo-Qiu pushed a commit to Bo-Qiu/nacos that referenced this pull request Nov 24, 2023
* Optimize paginated queries based on data sources

* add startup conditions

* user movkEnv

* update Exception Class name

* Optimize paginated queries based on data sources

* update Exception Class name

* Revert "add startup conditions"

This reverts commit 4e2c85d

* Optimize paginated queries based on data sources

* add startup conditions

* user movkEnv

* update Exception Class name

* Revert "add startup conditions"

This reverts commit 4e2c85d

* Revert "Revert "add startup conditions""

This reverts commit 4225891.

* DialectFactory add database  supported

* fix auth plugin Page, add dataSource plugin Dialect

* description

* remove dataSource plugin Dialect

* detail adjustment

* DefaultPageHandlerAdapter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Category issues or prs related to bug. plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants