This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d3f9ecdfd Avoid adding roles of "" if the roles list contains empty 
elements
6d3f9ecdfd is described below

commit 6d3f9ecdfd5cad84c3ee5d42b3dcfed11573d751
Author: Mark Thomas <[email protected]>
AuthorDate: Wed May 27 08:25:48 2026 +0100

    Avoid adding roles of "" if the roles list contains empty elements
---
 java/org/apache/catalina/realm/MemoryRealm.java     | 5 +++--
 test/org/apache/catalina/realm/TestMemoryRealm.java | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/realm/MemoryRealm.java 
b/java/org/apache/catalina/realm/MemoryRealm.java
index 797bf1c3b0..c9cc537fc9 100644
--- a/java/org/apache/catalina/realm/MemoryRealm.java
+++ b/java/org/apache/catalina/realm/MemoryRealm.java
@@ -174,7 +174,9 @@ public class MemoryRealm extends RealmBase {
                     break;
                 }
                 String role = roles.substring(0, comma).trim();
-                list.add(role);
+                if (!role.isEmpty()) {
+                    list.add(role);
+                }
                 roles = roles.substring(comma + 1);
             }
         }
@@ -183,7 +185,6 @@ public class MemoryRealm extends RealmBase {
         GenericPrincipal principal = new GenericPrincipal(username, list);
         principals.put(username, principal);
         credentials.put(username, password);
-
     }
 
 
diff --git a/test/org/apache/catalina/realm/TestMemoryRealm.java 
b/test/org/apache/catalina/realm/TestMemoryRealm.java
index 1035c80ce1..3eb8ce1049 100644
--- a/test/org/apache/catalina/realm/TestMemoryRealm.java
+++ b/test/org/apache/catalina/realm/TestMemoryRealm.java
@@ -38,6 +38,7 @@ public class TestMemoryRealm extends TomcatBaseTest {
             + "<group groupname=\"testgroup\" />"
             + "<user username=\"admin\" password=\"sekr3t\" roles=\"testrole, 
otherrole\" groups=\"testgroup, othergroup\" />"
             + "<user username=\"otheruser\" password=\"sekr3t2\" roles=\" \" 
/>"
+            + "<user username=\"user3\" password=\"sekr3t2\" roles=\",,\" />"
             + "</tomcat-users>";
 
     @Test
@@ -78,6 +79,10 @@ public class TestMemoryRealm extends TomcatBaseTest {
         Principal p2 = lockout.authenticate("otheruser", "sekr3t2");
         Assert.assertNotNull(p2);
         Assert.assertTrue(((GenericPrincipal) p2).getRoles().length == 0);
+
+        Principal p3 = lockout.authenticate("user3", "sekr3t2");
+        Assert.assertNotNull(p3);
+        Assert.assertTrue(((GenericPrincipal) p3).getRoles().length == 0);
     }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to