This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 5bf53205e5 Avoid adding roles of "" if the roles list contains empty
elements
5bf53205e5 is described below
commit 5bf53205e516f97a1f0ee992cadd3f8822cd6159
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 58c35c1bd1..b10fcb1c55 100644
--- a/java/org/apache/catalina/realm/MemoryRealm.java
+++ b/java/org/apache/catalina/realm/MemoryRealm.java
@@ -164,7 +164,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);
}
}
@@ -172,7 +174,6 @@ public class MemoryRealm extends RealmBase {
// Construct and cache the Principal for this user
GenericPrincipal principal = new GenericPrincipal(username, password,
list);
principals.put(username, principal);
-
}
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]