azexcy commented on code in PR #23627:
URL: https://github.com/apache/shardingsphere/pull/23627#discussion_r1073305368


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/CDCChannelInboundHandler.java:
##########
@@ -109,33 +128,50 @@ public void channelRead(final ChannelHandlerContext ctx, 
final Object msg) {
         }
     }
     
-    private void processLogin(final ChannelHandlerContext ctx, final 
CDCRequest request) {
+    private void processLogin(final ChannelHandlerContext ctx, final 
CDCRequest request, final CDCConnectionContext connectionContext) {
         if (!request.hasLogin() || !request.getLogin().hasBasicBody()) {
             
ctx.writeAndFlush(CDCResponseGenerator.failed(request.getRequestId(), 
CDCResponseErrorCode.ILLEGAL_REQUEST_ERROR, "Miss login request 
body")).addListener(ChannelFutureListener.CLOSE);
             return;
         }
         BasicBody body = request.getLogin().getBasicBody();
-        Collection<ShardingSphereRule> globalRules = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRules();
-        Optional<AuthorityRule> authorityRule = 
globalRules.stream().filter(rule -> rule instanceof AuthorityRule).map(rule -> 
(AuthorityRule) rule).findFirst();
+        Optional<AuthorityRule> authorityRule = findAuthorityRule();
         if (!authorityRule.isPresent()) {
             
ctx.writeAndFlush(CDCResponseGenerator.failed(request.getRequestId(), 
CDCResponseErrorCode.SERVER_ERROR, "Not find authority 
rule")).addListener(ChannelFutureListener.CLOSE);
             return;
         }
         Optional<ShardingSphereUser> user = authorityRule.get().findUser(new 
Grantee(body.getUsername(), getHostAddress(ctx)));
         if (user.isPresent() && 
Objects.equals(Hashing.sha256().hashBytes(user.get().getPassword().getBytes()).toString().toUpperCase(),
 body.getPassword())) {
-            
ctx.channel().attr(CONNECTION_CONTEXT_KEY).get().setStatus(CDCConnectionStatus.LOGGED_IN);
+            connectionContext.setStatus(CDCConnectionStatus.LOGGED_IN);
+            connectionContext.setCurrentUser(user.get());
             
ctx.writeAndFlush(CDCResponseGenerator.succeedBuilder(request.getRequestId()).build());
+        } else {
+            
ctx.writeAndFlush(CDCResponseGenerator.failed(request.getRequestId(), 
CDCResponseErrorCode.SERVER_ERROR, "Incorrect username or 
password")).addListener(ChannelFutureListener.CLOSE);
+        }
+    }
+    
+    private Optional<AuthorityRule> findAuthorityRule() {
+        Collection<ShardingSphereRule> globalRules = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRules();
+        return globalRules.stream().filter(rule -> rule instanceof 
AuthorityRule).map(rule -> (AuthorityRule) rule).findFirst();
+    }
+    
+    private void checkPrivileges(final Grantee grantee, final String 
currentDatabase) {
+        if (null == grantee) {
             return;
         }
-        ctx.writeAndFlush(CDCResponseGenerator.failed(request.getRequestId(), 
CDCResponseErrorCode.SERVER_ERROR, "Incorrect username or 
password")).addListener(ChannelFutureListener.CLOSE);
+        Optional<AuthorityRule> authorityRule = findAuthorityRule();
+        ShardingSpherePreconditions.checkState(authorityRule.isPresent(), () 
-> new SQLCheckException("Not find authority rule"));

Review Comment:
   Use `MissingRequiredRuleException` instead



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to