You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/15 12:30:56 UTC

[GitHub] [shardingsphere] sandynz opened a new pull request #6860: Implement PostgreSQL authentication for proxy (#5978)

sandynz opened a new pull request #6860:
URL: https://github.com/apache/shardingsphere/pull/6860


   Fixes #5978.
   
   Changes proposed in this pull request:
   - Implement PostgreSQL authentication for proxy
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter commented on pull request #6860: Implement PostgreSQL authentication for proxy (#5978)

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #6860:
URL: https://github.com/apache/shardingsphere/pull/6860#issuecomment-674755921


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/6860?src=pr&el=h1) Report
   > Merging [#6860](https://codecov.io/gh/apache/shardingsphere/pull/6860?src=pr&el=desc) into [master](https://codecov.io/gh/apache/shardingsphere/commit/dc55826e389d8ba5c2e8d57fc4438267c472aa1a&el=desc) will **increase** coverage by `0.63%`.
   > The diff coverage is `4.16%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/6860/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so)](https://codecov.io/gh/apache/shardingsphere/pull/6860?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #6860      +/-   ##
   ============================================
   + Coverage     55.88%   56.52%   +0.63%     
   - Complexity      437      444       +7     
   ============================================
     Files          1242     1249       +7     
     Lines         22001    22122     +121     
     Branches       3952     3962      +10     
   ============================================
   + Hits          12296    12505     +209     
   + Misses         8927     8827     -100     
   - Partials        778      790      +12     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/6860?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
   |---|---|---|---|
   | [...tocol/postgresql/constant/PostgreSQLErrorCode.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGIvcHJvdG9jb2wvcG9zdGdyZXNxbC9jb25zdGFudC9Qb3N0Z3JlU1FMRXJyb3JDb2RlLmphdmE=) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (?)` | |
   | [...ake/PostgreSQLAuthenticationMD5PasswordPacket.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGIvcHJvdG9jb2wvcG9zdGdyZXNxbC9wYWNrZXQvaGFuZHNoYWtlL1Bvc3RncmVTUUxBdXRoZW50aWNhdGlvbk1ENVBhc3N3b3JkUGFja2V0LmphdmE=) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (?)` | |
   | [...ket/handshake/PostgreSQLPasswordMessagePacket.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGIvcHJvdG9jb2wvcG9zdGdyZXNxbC9wYWNrZXQvaGFuZHNoYWtlL1Bvc3RncmVTUUxQYXNzd29yZE1lc3NhZ2VQYWNrZXQuamF2YQ==) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (?)` | |
   | [...ostgresql/auth/PostgreSQLAuthenticationEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvcG9zdGdyZXNxbC9hdXRoL1Bvc3RncmVTUUxBdXRoZW50aWNhdGlvbkVuZ2luZS5qYXZh) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (ø)` | |
   | [...stgresql/auth/PostgreSQLAuthenticationHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvcG9zdGdyZXNxbC9hdXRoL1Bvc3RncmVTUUxBdXRoZW50aWNhdGlvbkhhbmRsZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (?)` | |
   | [...rontend/postgresql/auth/PostgreSQLLoginResult.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvcG9zdGdyZXNxbC9hdXRoL1Bvc3RncmVTUUxMb2dpblJlc3VsdC5qYXZh) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (?)` | |
   | [...ql/packet/handshake/PostgreSQLRandomGenerator.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGIvcHJvdG9jb2wvcG9zdGdyZXNxbC9wYWNrZXQvaGFuZHNoYWtlL1Bvc3RncmVTUUxSYW5kb21HZW5lcmF0b3IuamF2YQ==) | `100.00% <100.00%> (ø)` | `0.00 <0.00> (?)` | |
   | [...ategy/keygen/KeyGenerateStrategyConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zaGFyZGluZy9hcGkvY29uZmlnL3N0cmF0ZWd5L2tleWdlbi9LZXlHZW5lcmF0ZVN0cmF0ZWd5Q29uZmlndXJhdGlvbi5qYXZh) | `0.00% <0.00%> (-100.00%)` | `0.00% <0.00%> (ø%)` | |
   | [...gy/sharding/HintShardingStrategyConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zaGFyZGluZy9hcGkvY29uZmlnL3N0cmF0ZWd5L3NoYXJkaW5nL0hpbnRTaGFyZGluZ1N0cmF0ZWd5Q29uZmlndXJhdGlvbi5qYXZh) | `0.00% <0.00%> (-100.00%)` | `0.00% <0.00%> (ø%)` | |
   | [...sharding/ComplexShardingStrategyConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zaGFyZGluZy9hcGkvY29uZmlnL3N0cmF0ZWd5L3NoYXJkaW5nL0NvbXBsZXhTaGFyZGluZ1N0cmF0ZWd5Q29uZmlndXJhdGlvbi5qYXZh) | `0.00% <0.00%> (-100.00%)` | `0.00% <0.00%> (ø%)` | |
   | ... and [40 more](https://codecov.io/gh/apache/shardingsphere/pull/6860/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/6860?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/6860?src=pr&el=footer). Last update [dc55826...e4109c2](https://codecov.io/gh/apache/shardingsphere/pull/6860?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tuohai666 commented on a change in pull request #6860: Implement PostgreSQL authentication for proxy (#5978)

Posted by GitBox <gi...@apache.org>.
tuohai666 commented on a change in pull request #6860:
URL: https://github.com/apache/shardingsphere/pull/6860#discussion_r471227689



##########
File path: shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLMd5Digest.java
##########
@@ -0,0 +1,94 @@
+/*

Review comment:
       We can't replace BSD-2-Clause License header with Apache 2.0 License. 
   BSD-2-Clause License requests: **Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.**
   
   The actual PasswordMessage can be computed in SQL as concat('md5', md5(concat(md5(concat(password, username)), random-salt))). (Keep in mind the md5() function returns its result as a hex string.)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] coveralls edited a comment on pull request #6860: Implement PostgreSQL authentication for proxy (#5978)

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #6860:
URL: https://github.com/apache/shardingsphere/pull/6860#issuecomment-675185265


   ## Pull Request Test Coverage Report for [Build 13843](https://coveralls.io/builds/32797191)
   
   * **5** of **120**   **(4.17%)**  changed or added relevant lines in **7** files are covered.
   * **115** unchanged lines in **7** files lost coverage.
   * Overall coverage increased (+**0.4%**) to **58.571%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLLoginResult.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLLoginResult.java#L33) | 0 | 4 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fpacket%2Fhandshake%2FPostgreSQLPasswordMessagePacket.java#L28) | 0 | 7 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fpacket%2Fhandshake%2FPostgreSQLAuthenticationMD5PasswordPacket.java#L28) | 0 | 9 | 0.0%
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationHandler.java#L32) | 0 | 21 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLErrorCode.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fconstant%2FPostgreSQLErrorCode.java#L25) | 0 | 27 | 0.0%
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationEngine.java#L54) | 0 | 47 | 0.0%
   <!-- | **Total:** | **5** | **120** | **4.17%** | -->
   
   |  Files with Coverage Reduction | New Missed Lines | % |
   | :-----|--------------|--: |
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationEngine.java#L95) | 1 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/strategy/sharding/HintShardingStrategyConfiguration.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Fstrategy%2Fsharding%2FHintShardingStrategyConfiguration.java#L31) | 4 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/strategy/keygen/KeyGenerateStrategyConfiguration.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Fstrategy%2Fkeygen%2FKeyGenerateStrategyConfiguration.java#L34) | 5 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingTableRuleConfiguration.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Frule%2FShardingTableRuleConfiguration.java#L45) | 6 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/strategy/sharding/ComplexShardingStrategyConfiguration.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Fstrategy%2Fsharding%2FComplexShardingStrategyConfiguration.java#L34) | 6 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/strategy/sharding/StandardShardingStrategyConfiguration.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Fstrategy%2Fsharding%2FStandardShardingStrategyConfiguration.java#L34) | 6 | 0% |
   | [shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDDLVisitor.java](https://coveralls.io/builds/32797191/source?filename=shardingsphere-sql-parser%2Fshardingsphere-sql-parser-dialect%2Fshardingsphere-sql-parser-mysql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsql%2Fparser%2Fmysql%2Fvisitor%2Fimpl%2FMySQLDDLVisitor.java#L116) | 87 | 0% |
   <!-- | **Total:** | **115** |  | -->
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/32797191/badge)](https://coveralls.io/builds/32797191) |
   | :-- | --: |
   | Change from base [Build 13788](https://coveralls.io/builds/32774477): |  0.4% |
   | Covered Lines: | 13308 |
   | Relevant Lines: | 22721 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tuohai666 merged pull request #6860: Implement PostgreSQL authentication for proxy (#5978)

Posted by GitBox <gi...@apache.org>.
tuohai666 merged pull request #6860:
URL: https://github.com/apache/shardingsphere/pull/6860


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] coveralls commented on pull request #6860: Implement PostgreSQL authentication for proxy (#5978)

Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #6860:
URL: https://github.com/apache/shardingsphere/pull/6860#issuecomment-675185265


   ## Pull Request Test Coverage Report for [Build 13837](https://coveralls.io/builds/32793204)
   
   * **5** of **120**   **(4.17%)**  changed or added relevant lines in **7** files are covered.
   * **28** unchanged lines in **6** files lost coverage.
   * Overall coverage increased (+**0.4%**) to **58.574%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLLoginResult.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLLoginResult.java#L33) | 0 | 4 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fpacket%2Fhandshake%2FPostgreSQLPasswordMessagePacket.java#L28) | 0 | 7 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fpacket%2Fhandshake%2FPostgreSQLAuthenticationMD5PasswordPacket.java#L28) | 0 | 9 | 0.0%
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationHandler.java#L32) | 0 | 21 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLErrorCode.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fconstant%2FPostgreSQLErrorCode.java#L25) | 0 | 27 | 0.0%
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationEngine.java#L54) | 0 | 47 | 0.0%
   <!-- | **Total:** | **5** | **120** | **4.17%** | -->
   
   |  Files with Coverage Reduction | New Missed Lines | % |
   | :-----|--------------|--: |
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationEngine.java#L95) | 1 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/strategy/sharding/HintShardingStrategyConfiguration.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Fstrategy%2Fsharding%2FHintShardingStrategyConfiguration.java#L31) | 4 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/strategy/keygen/KeyGenerateStrategyConfiguration.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Fstrategy%2Fkeygen%2FKeyGenerateStrategyConfiguration.java#L34) | 5 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingTableRuleConfiguration.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Frule%2FShardingTableRuleConfiguration.java#L45) | 6 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/strategy/sharding/ComplexShardingStrategyConfiguration.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Fstrategy%2Fsharding%2FComplexShardingStrategyConfiguration.java#L34) | 6 | 0% |
   | [shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/strategy/sharding/StandardShardingStrategyConfiguration.java](https://coveralls.io/builds/32793204/source?filename=shardingsphere-features%2Fshardingsphere-sharding%2Fshardingsphere-sharding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fapi%2Fconfig%2Fstrategy%2Fsharding%2FStandardShardingStrategyConfiguration.java#L34) | 6 | 0% |
   <!-- | **Total:** | **28** |  | -->
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/32793204/badge)](https://coveralls.io/builds/32793204) |
   | :-- | --: |
   | Change from base [Build 13788](https://coveralls.io/builds/32774477): |  0.4% |
   | Covered Lines: | 13305 |
   | Relevant Lines: | 22715 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tuohai666 commented on a change in pull request #6860: Implement PostgreSQL authentication for proxy (#5978)

Posted by GitBox <gi...@apache.org>.
tuohai666 commented on a change in pull request #6860:
URL: https://github.com/apache/shardingsphere/pull/6860#discussion_r471253724



##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
+
+import lombok.Getter;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
+import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+
+/**
+ * AuthenticationMD5Password (B) packet for PostgreSQL.

Review comment:
       What does (B) mean? If it means back end, please don't use abbreviation.

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLErrorCode.java
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.db.protocol.postgresql.constant;
+
+/**
+ * PostgreSQL error code.
+ *
+ * @see <a href="https://www.postgresql.org/docs/12/errcodes-appendix.html">Appendix A. PostgreSQL Error Codes</a>
+ */
+public enum PostgreSQLErrorCode {
+    
+    SUCCESSFUL_COMPLETION("00000", "successful_completion"),
+    WARNING("01000", "warning"),
+    DYNAMIC_RESULT_SETS_RETURNED("0100C", "dynamic_result_sets_returned"),
+    IMPLICIT_ZERO_BIT_PADDING("01008", "implicit_zero_bit_padding"),
+    NULL_VALUE_ELIMINATED_IN_SET_FUNCTION("01003", "null_value_eliminated_in_set_function"),
+    PRIVILEGE_NOT_GRANTED("01007", "privilege_not_granted"),
+    PRIVILEGE_NOT_REVOKED("01006", "privilege_not_revoked"),
+    STRING_DATA_RIGHT_TRUNCATION("01004", "string_data_right_truncation"),
+    DEPRECATED_FEATURE("01P01", "deprecated_feature"),
+    CONNECTION_EXCEPTION("08000", "connection_exception"),
+    CONNECTION_DOES_NOT_EXIST("08003", "connection_does_not_exist"),
+    CONNECTION_FAILURE("08006", "connection_failure"),
+    SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION("08001", "sqlclient_unable_to_establish_sqlconnection"),
+    SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION("08004", "sqlserver_rejected_establishment_of_sqlconnection"),
+    TRANSACTION_RESOLUTION_UNKNOWN("08007", "transaction_resolution_unknown"),
+    PROTOCOL_VIOLATION("08P01", "protocol_violation"),
+    INVALID_AUTHORIZATION_SPECIFICATION("28000", "invalid_authorization_specification"),
+    INVALID_PASSWORD("28P01", "invalid_password"),
+    INVALID_CATALOG_NAME("3D000", "invalid_catalog_name"),
+    INVALID_SCHEMA_NAME("3F000", "invalid_schema_name"),;
+    
+    private final String errorCode;
+    
+    private final String conditionName;
+    
+    PostgreSQLErrorCode(final String errorCode, final String conditionName) {
+        this.errorCode = errorCode;
+        this.conditionName = conditionName;
+    }
+    
+    /**
+     * Get error code.
+     *
+     * @return error code
+     */
+    public String getErrorCode() {
+        return errorCode;
+    }
+    
+    /**
+     * Get condition name.
+     *
+     * @return condition name
+     */
+    public String getConditionName() {

Review comment:
       When will this function be called?

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
+
+import lombok.Getter;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
+import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+
+/**
+ * PasswordMessage (F) packet for PostgreSQL.
+ */
+public class PostgreSQLPasswordMessagePacket implements PostgreSQLPacket {

Review comment:
       To a final class

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
+
+import lombok.Getter;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
+import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+
+/**
+ * PasswordMessage (F) packet for PostgreSQL.

Review comment:
       What does (F) mean?

##########
File path: shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.frontend.postgresql.auth;
+
+import java.security.MessageDigest;
+import java.util.Map;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLErrorCode;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLPasswordMessagePacket;
+import org.apache.shardingsphere.infra.auth.ProxyUser;
+import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
+
+/**
+ * Authentication handler for PostgreSQL.
+ */
+public class PostgreSQLAuthenticationHandler {
+    
+    /**
+     * Login.
+     *
+     * @param userName              user name
+     * @param databaseName          database name
+     * @param md5Salt               md5 salt
+     * @param passwordMessagePacket password message packet
+     * @return PostgreSQLLoginResult
+     */
+    public static PostgreSQLLoginResult loginWithMd5Password(final String userName, final String databaseName, final byte[] md5Salt, final PostgreSQLPasswordMessagePacket passwordMessagePacket) {
+        ProxyUser proxyUser = null;
+        for (Map.Entry<String, ProxyUser> entry : ProxySchemaContexts.getInstance().getSchemaContexts().getAuthentication().getUsers().entrySet()) {
+            if (entry.getKey().equals(userName)) {
+                proxyUser = entry.getValue();
+                break;
+            }
+        }
+        if (null == proxyUser) {
+            return new PostgreSQLLoginResult(PostgreSQLErrorCode.INVALID_AUTHORIZATION_SPECIFICATION, "unknown userName: " + userName);
+        }
+        
+        String md5Digest = passwordMessagePacket.getMd5Digest();
+        String expectedMd5Digest = md5Encode(userName, proxyUser.getPassword(), md5Salt);
+        if (!expectedMd5Digest.equals(md5Digest)) {
+            return new PostgreSQLLoginResult(PostgreSQLErrorCode.INVALID_PASSWORD, "bad md5 password");
+        }
+        
+        if (!proxyUser.getAuthorizedSchemas().contains(databaseName)) {
+            return new PostgreSQLLoginResult(PostgreSQLErrorCode.PRIVILEGE_NOT_GRANTED, String.format("%s has no configured %s in authorizedSchemas", userName, databaseName));
+        }
+        
+        return new PostgreSQLLoginResult(PostgreSQLErrorCode.SUCCESSFUL_COMPLETION, null);
+    }
+    
+    private static String md5Encode(final String userName, final String password, final byte[] md5Salt) {
+        String pwdHash = new String(Hex.encodeHex(DigestUtils.md5(password + userName), true));

Review comment:
       Please don't use abbreviation.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java
##########
@@ -58,23 +69,64 @@ public boolean auth(final ChannelHandlerContext context, final PacketPayload pay
             return false;
         }
         payload.getByteBuf().resetReaderIndex();
-        PostgreSQLComStartupPacket comStartupPacket = new PostgreSQLComStartupPacket((PostgreSQLPacketPayload) payload);
-        String databaseName = comStartupPacket.getParametersMap().get(DATABASE_NAME_KEYWORD);
-        if (!Strings.isNullOrEmpty(databaseName) && !ProxySchemaContexts.getInstance().schemaExists(databaseName)) {
-            PostgreSQLErrorResponsePacket responsePacket = new PostgreSQLErrorResponsePacket();
-            responsePacket.addField(PostgreSQLErrorResponsePacket.FIELD_TYPE_SEVERITY, "FATAL");
-            responsePacket.addField(PostgreSQLErrorResponsePacket.FIELD_TYPE_CODE, "3D000");
-            responsePacket.addField(PostgreSQLErrorResponsePacket.FIELD_TYPE_MESSAGE, String.format("database \"%s\" does not exist", databaseName));
-            context.writeAndFlush(responsePacket);
+        if (!startupMessageReceived.get()) {
+            PostgreSQLComStartupPacket comStartupPacket = new PostgreSQLComStartupPacket((PostgreSQLPacketPayload) payload);
+            startupMessageReceived.set(true);
+            String databaseName = comStartupPacket.getParametersMap().get(DATABASE_NAME_KEYWORD);
+            if (!Strings.isNullOrEmpty(databaseName) && !ProxySchemaContexts.getInstance().schemaExists(databaseName)) {
+                PostgreSQLErrorResponsePacket responsePacket = createPostgreSQLErrorResponsePacket(PostgreSQLErrorCode.INVALID_CATALOG_NAME,
+                    String.format("database \"%s\" does not exist", databaseName));
+                context.writeAndFlush(responsePacket);
+                context.close();
+                return false;
+            }
+            backendConnection.setCurrentSchema(databaseName);
+            String userName = comStartupPacket.getParametersMap().get(USER_NAME_KEYWORD);
+            if (null == userName || userName.isEmpty()) {
+                PostgreSQLErrorResponsePacket responsePacket = createPostgreSQLErrorResponsePacket(PostgreSQLErrorCode.SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION,
+                    "user not set in StartupMessage");
+                context.writeAndFlush(responsePacket);
+                context.close();
+                return false;
+            }
+            backendConnection.setUserName(userName);
+            md5Salt = PostgreSQLRandomGenerator.getInstance().generateRandomBytes(4);
+            context.writeAndFlush(new PostgreSQLAuthenticationMD5PasswordPacket(md5Salt));
             return false;
+        } else {
+            final char messageType = (char) ((PostgreSQLPacketPayload) payload).readInt1();

Review comment:
       Don't have to use final for local variable.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java
##########
@@ -58,23 +69,64 @@ public boolean auth(final ChannelHandlerContext context, final PacketPayload pay
             return false;
         }
         payload.getByteBuf().resetReaderIndex();
-        PostgreSQLComStartupPacket comStartupPacket = new PostgreSQLComStartupPacket((PostgreSQLPacketPayload) payload);
-        String databaseName = comStartupPacket.getParametersMap().get(DATABASE_NAME_KEYWORD);
-        if (!Strings.isNullOrEmpty(databaseName) && !ProxySchemaContexts.getInstance().schemaExists(databaseName)) {
-            PostgreSQLErrorResponsePacket responsePacket = new PostgreSQLErrorResponsePacket();
-            responsePacket.addField(PostgreSQLErrorResponsePacket.FIELD_TYPE_SEVERITY, "FATAL");
-            responsePacket.addField(PostgreSQLErrorResponsePacket.FIELD_TYPE_CODE, "3D000");
-            responsePacket.addField(PostgreSQLErrorResponsePacket.FIELD_TYPE_MESSAGE, String.format("database \"%s\" does not exist", databaseName));
-            context.writeAndFlush(responsePacket);
+        if (!startupMessageReceived.get()) {
+            PostgreSQLComStartupPacket comStartupPacket = new PostgreSQLComStartupPacket((PostgreSQLPacketPayload) payload);
+            startupMessageReceived.set(true);
+            String databaseName = comStartupPacket.getParametersMap().get(DATABASE_NAME_KEYWORD);
+            if (!Strings.isNullOrEmpty(databaseName) && !ProxySchemaContexts.getInstance().schemaExists(databaseName)) {
+                PostgreSQLErrorResponsePacket responsePacket = createPostgreSQLErrorResponsePacket(PostgreSQLErrorCode.INVALID_CATALOG_NAME,
+                    String.format("database \"%s\" does not exist", databaseName));
+                context.writeAndFlush(responsePacket);
+                context.close();
+                return false;
+            }
+            backendConnection.setCurrentSchema(databaseName);
+            String userName = comStartupPacket.getParametersMap().get(USER_NAME_KEYWORD);
+            if (null == userName || userName.isEmpty()) {
+                PostgreSQLErrorResponsePacket responsePacket = createPostgreSQLErrorResponsePacket(PostgreSQLErrorCode.SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION,
+                    "user not set in StartupMessage");
+                context.writeAndFlush(responsePacket);
+                context.close();
+                return false;
+            }
+            backendConnection.setUserName(userName);
+            md5Salt = PostgreSQLRandomGenerator.getInstance().generateRandomBytes(4);
+            context.writeAndFlush(new PostgreSQLAuthenticationMD5PasswordPacket(md5Salt));
             return false;
+        } else {
+            final char messageType = (char) ((PostgreSQLPacketPayload) payload).readInt1();
+            if ('p' != messageType) {
+                PostgreSQLErrorResponsePacket responsePacket = createPostgreSQLErrorResponsePacket(PostgreSQLErrorCode.SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION,
+                    "PasswordMessage is expected, message type 'p', but not '" + messageType + "'");
+                context.writeAndFlush(responsePacket);
+                context.close();
+                return false;
+            }
+            PostgreSQLPasswordMessagePacket passwordMessagePacket = new PostgreSQLPasswordMessagePacket((PostgreSQLPacketPayload) payload);
+            PostgreSQLLoginResult loginResult = PostgreSQLAuthenticationHandler.loginWithMd5Password(
+                backendConnection.getUserName(), backendConnection.getSchema().getName(), md5Salt, passwordMessagePacket);
+            if (PostgreSQLErrorCode.SUCCESSFUL_COMPLETION != loginResult.getErrorCode()) {
+                PostgreSQLErrorResponsePacket responsePacket = createPostgreSQLErrorResponsePacket(loginResult.getErrorCode(),
+                    loginResult.getErrorMessage());
+                context.writeAndFlush(responsePacket);
+                context.close();
+                return false;
+            } else {
+                context.write(new PostgreSQLAuthenticationOKPacket(true));
+                context.write(new PostgreSQLParameterStatusPacket("server_version", "12.3"));

Review comment:
       Add a TODO comment here to implement PostgreSQLServerInfo like MySQLServerInfo。

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
+
+import lombok.Getter;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
+import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+
+/**
+ * AuthenticationMD5Password (B) packet for PostgreSQL.
+ */
+public class PostgreSQLAuthenticationMD5PasswordPacket implements PostgreSQLPacket {

Review comment:
       To a final class

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLRandomGenerator.java
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
+
+import java.util.concurrent.ThreadLocalRandom;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Random generator for PostgreSQL.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class PostgreSQLRandomGenerator {

Review comment:
       To a final class




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] coveralls edited a comment on pull request #6860: Implement PostgreSQL authentication for proxy (#5978)

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #6860:
URL: https://github.com/apache/shardingsphere/pull/6860#issuecomment-675185265


   ## Pull Request Test Coverage Report for [Build 13796](https://coveralls.io/builds/32776783)
   
   * **5** of **115**   **(4.35%)**  changed or added relevant lines in **7** files are covered.
   * **1** unchanged line in **1** file lost coverage.
   * Overall coverage decreased (**-0.2%**) to **58.029%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLLoginResult.java](https://coveralls.io/builds/32776783/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLLoginResult.java#L33) | 0 | 4 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java](https://coveralls.io/builds/32776783/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fpacket%2Fhandshake%2FPostgreSQLPasswordMessagePacket.java#L28) | 0 | 7 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java](https://coveralls.io/builds/32776783/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fpacket%2Fhandshake%2FPostgreSQLAuthenticationMD5PasswordPacket.java#L28) | 0 | 9 | 0.0%
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java](https://coveralls.io/builds/32776783/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationHandler.java#L30) | 0 | 16 | 0.0%
   | [shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLErrorCode.java](https://coveralls.io/builds/32776783/source?filename=shardingsphere-db-protocol%2Fshardingsphere-db-protocol-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fdb%2Fprotocol%2Fpostgresql%2Fconstant%2FPostgreSQLErrorCode.java#L25) | 0 | 27 | 0.0%
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java](https://coveralls.io/builds/32776783/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationEngine.java#L54) | 0 | 47 | 0.0%
   <!-- | **Total:** | **5** | **115** | **4.35%** | -->
   
   |  Files with Coverage Reduction | New Missed Lines | % |
   | :-----|--------------|--: |
   | [shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java](https://coveralls.io/builds/32776783/source?filename=shardingsphere-proxy%2Fshardingsphere-proxy-frontend%2Fshardingsphere-proxy-frontend-postgresql%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fproxy%2Ffrontend%2Fpostgresql%2Fauth%2FPostgreSQLAuthenticationEngine.java#L95) | 1 | 0% |
   <!-- | **Total:** | **1** |  | -->
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/32776783/badge)](https://coveralls.io/builds/32776783) |
   | :-- | --: |
   | Change from base [Build 13788](https://coveralls.io/builds/32774477): |  -0.2% |
   | Covered Lines: | 13190 |
   | Relevant Lines: | 22730 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org