You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/06/17 06:48:43 UTC

[GitHub] [incubator-doris] AshinGau opened a new pull request, #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

AshinGau opened a new pull request, #10213:
URL: https://github.com/apache/incubator-doris/pull/10213

   # Proposed changes
   
   Issue Number: close #xxx
   
   ## Problem Summary:
   Doris uses regular matching strings. If the name contains underscores, it will be converted to '.' wildcard.
   ```
   // org.apache.doris.common.PatternMatcher#convertMysqlPattern
   switch (ch) {
       case '%':
           sb.append(".*");
           break;
       case '.':
           sb.append("\\.");
           break;
       case '_':
           sb.append(".");
           break; 
   ```
   In grant statement, database and table support matching a single '*' wildcard, the other cases are string case-sensitive equivalent matching.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (No)
   2. Has unit tests been added: (Yes)
   3. Has document been added or modified: (No)
   4. Does it need to update dependencies: (No)
   5. Are there any changes that cannot be rolled back: (No)
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   


-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morningman merged pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
morningman merged PR #10213:
URL: https://github.com/apache/doris/pull/10213


-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #10213:
URL: https://github.com/apache/incubator-doris/pull/10213#issuecomment-1158673757

   PR approved by anyone and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] AshinGau commented on a diff in pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
AshinGau commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r900044038


##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));

Review Comment:
   Modified



-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] AshinGau commented on a diff in pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
AshinGau commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r900045154


##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));
     private Pattern pattern;
+    private String casePattern;
+    private boolean caseSensitive;
 
     private static final Set<Character> FORBIDDEN_CHARS = Sets.newHashSet('<', '(', '[', '{', '^', '=',
                                                                           '$', '!', '|', ']', '}', ')',
                                                                           '?', '*', '+', '>', '@');
 
+    public PatternMatcher(Pattern pattern) {
+        this.pattern = pattern;
+    }
+
+    public PatternMatcher(String casePattern, boolean caseSensitive) {
+        this.casePattern = caseSensitive ? casePattern : casePattern.toLowerCase(Locale.ROOT);
+        this.caseSensitive = caseSensitive;
+    }
+
     public boolean match(String candidate) {
-        if (pattern == null || candidate == null) {
-            // No pattern, how can I explain this? Return false now.
-            // No candidate, return false.
+        if (candidate == null) {
             return false;
         }
-        if (pattern.matcher(candidate).matches()) {
-            return true;
+        if (pattern != null) {
+            return pattern.matcher(candidate).matches();
+        }
+        if (caseSensitive) {
+            return candidate.equals(casePattern);
+        } else {
+            return candidate.toLowerCase(Locale.ROOT).equals(casePattern);

Review Comment:
   when initialize PatternMatcher, casePattern is lowercase if caseSensitive = false



-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morningman commented on a diff in pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
morningman commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r901039146


##########
fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/DbPrivEntry.java:
##########
@@ -70,8 +70,7 @@ private static PatternMatcher createDbPatternMatcher(String db) throws AnalysisE
             dbCaseSensibility = false;
         }
 
-        PatternMatcher dbPattern = PatternMatcher.createMysqlPattern(db.equals(ANY_DB) ? "%" : db, dbCaseSensibility);
-        return dbPattern;
+        return  PatternMatcher.createFlatPattern(db, dbCaseSensibility, db.equals(ANY_DB));

Review Comment:
   ```suggestion
           return PatternMatcher.createFlatPattern(db, dbCaseSensibility, db.equals(ANY_DB));
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static final PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));
     private Pattern pattern;
+    private String flatPattern;

Review Comment:
   Add some comment in code to explain the different between `pattern` and `flatPattern`. Better to give some example.
   And looks like the `flatPattern` is not a real pattern, more like an `origin 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.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] AshinGau commented on a diff in pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
AshinGau commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r901041856


##########
fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/DbPrivEntry.java:
##########
@@ -70,8 +70,7 @@ private static PatternMatcher createDbPatternMatcher(String db) throws AnalysisE
             dbCaseSensibility = false;
         }
 
-        PatternMatcher dbPattern = PatternMatcher.createMysqlPattern(db.equals(ANY_DB) ? "%" : db, dbCaseSensibility);
-        return dbPattern;
+        return  PatternMatcher.createFlatPattern(db, dbCaseSensibility, db.equals(ANY_DB));

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static final PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));
     private Pattern pattern;
+    private String flatPattern;

Review Comment:
   done



-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] AshinGau commented on a diff in pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
AshinGau commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r900045726


##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));
     private Pattern pattern;
+    private String casePattern;
+    private boolean caseSensitive;
 
     private static final Set<Character> FORBIDDEN_CHARS = Sets.newHashSet('<', '(', '[', '{', '^', '=',
                                                                           '$', '!', '|', ']', '}', ')',
                                                                           '?', '*', '+', '>', '@');
 
+    public PatternMatcher(Pattern pattern) {
+        this.pattern = pattern;
+    }
+
+    public PatternMatcher(String casePattern, boolean caseSensitive) {
+        this.casePattern = caseSensitive ? casePattern : casePattern.toLowerCase(Locale.ROOT);
+        this.caseSensitive = caseSensitive;
+    }
+
     public boolean match(String candidate) {
-        if (pattern == null || candidate == null) {
-            // No pattern, how can I explain this? Return false now.
-            // No candidate, return false.
+        if (candidate == null) {
             return false;
         }
-        if (pattern.matcher(candidate).matches()) {
-            return true;
+        if (pattern != null) {
+            return pattern.matcher(candidate).matches();
+        }
+        if (caseSensitive) {
+            return candidate.equals(casePattern);
+        } else {
+            return candidate.toLowerCase(Locale.ROOT).equals(casePattern);
+        }
+    }
+
+    public static PatternMatcher createCasePattern(String casePattern, boolean caseSensitive) {
+        return createCasePattern(casePattern, caseSensitive, false);
+    }
+
+    /**
+     * In grant operation, database and table support matching a single wildcard,
+     * the other cases are string case-sensitive equivalent matching.
+     */
+    public static PatternMatcher createCasePattern(

Review Comment:
   change to createFlatPattern



-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] AshinGau commented on a diff in pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
AshinGau commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r900049077


##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));
     private Pattern pattern;
+    private String casePattern;

Review Comment:
   String.equals() is faster than Pattern.matcher().matches(), and we can avoid errors caused by special characters, such as '.', '\', '*', etc. Of course, these special characters will not appear in the name, but it is better to use the string equivalent comparison.



-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] AshinGau commented on a diff in pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
AshinGau commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r900045374


##########
fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/PrivEntryTest.java:
##########
@@ -0,0 +1,51 @@
+// 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.doris.mysql.privilege;
+
+import org.apache.doris.analysis.UserIdentity;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PrivEntryTest {
+    @Test
+    public void testPatternMatch() throws Exception {
+        TablePrivEntry tablePrivEntry = TablePrivEntry.create(
+                "127.%", "db_db1", "user1", "tbl_tbl1", false,
+                PrivBitSet.of(PaloPrivilege.SELECT_PRIV, PaloPrivilege.DROP_PRIV));
+        // pattern match
+        boolean dp = tablePrivEntry.getDbPattern().match("db-db1");
+        boolean tp = tablePrivEntry.getTblPattern().match("tbl-tbl1");
+        // create TablePrivTable
+        TablePrivTable tablePrivTable = new TablePrivTable();
+        tablePrivTable.addEntry(tablePrivEntry, false, false);
+        UserIdentity userIdentity = new UserIdentity("user1", "127.%", false);
+        userIdentity.setIsAnalyzed();
+
+        PrivBitSet privs1 = PrivBitSet.of();
+        tablePrivTable.getPrivs(userIdentity, "db#db1", "tbl#tbl1", privs1);
+        boolean canDrop1 = PaloPrivilege.satisfy(privs1, PrivPredicate.DROP);
+
+        PrivBitSet privs2 = PrivBitSet.of();
+        tablePrivTable.getPrivs(userIdentity, "db_db1", "tbl_tbl1", privs2);
+        boolean canDrop2 = PaloPrivilege.satisfy(privs2, PrivPredicate.DROP);
+
+        Assert.assertTrue(!dp && !tp && !canDrop1);

Review Comment:
   Modified



##########
fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/PrivEntryTest.java:
##########
@@ -0,0 +1,51 @@
+// 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.doris.mysql.privilege;
+
+import org.apache.doris.analysis.UserIdentity;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PrivEntryTest {
+    @Test
+    public void testPatternMatch() throws Exception {

Review Comment:
   Modified



-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morrySnow commented on a diff in pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
morrySnow commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r899900703


##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));

Review Comment:
   could be final



##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));
     private Pattern pattern;
+    private String casePattern;
+    private boolean caseSensitive;
 
     private static final Set<Character> FORBIDDEN_CHARS = Sets.newHashSet('<', '(', '[', '{', '^', '=',
                                                                           '$', '!', '|', ']', '}', ')',
                                                                           '?', '*', '+', '>', '@');
 
+    public PatternMatcher(Pattern pattern) {
+        this.pattern = pattern;
+    }
+
+    public PatternMatcher(String casePattern, boolean caseSensitive) {
+        this.casePattern = caseSensitive ? casePattern : casePattern.toLowerCase(Locale.ROOT);
+        this.caseSensitive = caseSensitive;
+    }
+
     public boolean match(String candidate) {
-        if (pattern == null || candidate == null) {
-            // No pattern, how can I explain this? Return false now.
-            // No candidate, return false.
+        if (candidate == null) {
             return false;
         }
-        if (pattern.matcher(candidate).matches()) {
-            return true;
+        if (pattern != null) {
+            return pattern.matcher(candidate).matches();
+        }
+        if (caseSensitive) {
+            return candidate.equals(casePattern);
+        } else {
+            return candidate.toLowerCase(Locale.ROOT).equals(casePattern);

Review Comment:
   casePattern always lowerCase?



##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));
     private Pattern pattern;
+    private String casePattern;

Review Comment:
   why use a `String` instead of a `Pattern`?



##########
fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/PrivEntryTest.java:
##########
@@ -0,0 +1,51 @@
+// 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.doris.mysql.privilege;
+
+import org.apache.doris.analysis.UserIdentity;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PrivEntryTest {
+    @Test
+    public void testPatternMatch() throws Exception {
+        TablePrivEntry tablePrivEntry = TablePrivEntry.create(
+                "127.%", "db_db1", "user1", "tbl_tbl1", false,
+                PrivBitSet.of(PaloPrivilege.SELECT_PRIV, PaloPrivilege.DROP_PRIV));
+        // pattern match
+        boolean dp = tablePrivEntry.getDbPattern().match("db-db1");
+        boolean tp = tablePrivEntry.getTblPattern().match("tbl-tbl1");
+        // create TablePrivTable
+        TablePrivTable tablePrivTable = new TablePrivTable();
+        tablePrivTable.addEntry(tablePrivEntry, false, false);
+        UserIdentity userIdentity = new UserIdentity("user1", "127.%", false);
+        userIdentity.setIsAnalyzed();
+
+        PrivBitSet privs1 = PrivBitSet.of();
+        tablePrivTable.getPrivs(userIdentity, "db#db1", "tbl#tbl1", privs1);
+        boolean canDrop1 = PaloPrivilege.satisfy(privs1, PrivPredicate.DROP);
+
+        PrivBitSet privs2 = PrivBitSet.of();
+        tablePrivTable.getPrivs(userIdentity, "db_db1", "tbl_tbl1", privs2);
+        boolean canDrop2 = PaloPrivilege.satisfy(privs2, PrivPredicate.DROP);
+
+        Assert.assertTrue(!dp && !tp && !canDrop1);

Review Comment:
   it is better to assert one by one



##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
 
 // Wrap for Java pattern and matcher
 public class PatternMatcher {
+    public static PatternMatcher MATCH_ANY = new PatternMatcher(Pattern.compile(".*"));
     private Pattern pattern;
+    private String casePattern;
+    private boolean caseSensitive;
 
     private static final Set<Character> FORBIDDEN_CHARS = Sets.newHashSet('<', '(', '[', '{', '^', '=',
                                                                           '$', '!', '|', ']', '}', ')',
                                                                           '?', '*', '+', '>', '@');
 
+    public PatternMatcher(Pattern pattern) {
+        this.pattern = pattern;
+    }
+
+    public PatternMatcher(String casePattern, boolean caseSensitive) {
+        this.casePattern = caseSensitive ? casePattern : casePattern.toLowerCase(Locale.ROOT);
+        this.caseSensitive = caseSensitive;
+    }
+
     public boolean match(String candidate) {
-        if (pattern == null || candidate == null) {
-            // No pattern, how can I explain this? Return false now.
-            // No candidate, return false.
+        if (candidate == null) {
             return false;
         }
-        if (pattern.matcher(candidate).matches()) {
-            return true;
+        if (pattern != null) {
+            return pattern.matcher(candidate).matches();
+        }
+        if (caseSensitive) {
+            return candidate.equals(casePattern);
+        } else {
+            return candidate.toLowerCase(Locale.ROOT).equals(casePattern);
+        }
+    }
+
+    public static PatternMatcher createCasePattern(String casePattern, boolean caseSensitive) {
+        return createCasePattern(casePattern, caseSensitive, false);
+    }
+
+    /**
+     * In grant operation, database and table support matching a single wildcard,
+     * the other cases are string case-sensitive equivalent matching.
+     */
+    public static PatternMatcher createCasePattern(

Review Comment:
   what's mean about 'case' in function name?



##########
fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/PrivEntryTest.java:
##########
@@ -0,0 +1,51 @@
+// 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.doris.mysql.privilege;
+
+import org.apache.doris.analysis.UserIdentity;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PrivEntryTest {
+    @Test
+    public void testPatternMatch() throws Exception {

Review Comment:
   add a java doc comment or change the function name to to explicitly state that the test is for names that contain underscores



-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #10213: [fix](auth) Authentication exception when the name of database or table contains an underscore in grant statement.

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #10213:
URL: https://github.com/apache/doris/pull/10213#issuecomment-1159616627

   PR approved by at least one committer and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org