This is an automated email from the ASF dual-hosted git repository.
rmaucher 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 4180c85be4 Avoid adding a "null" or empty string role where non is
specified
4180c85be4 is described below
commit 4180c85be400cba4f2b24f63b3d4348400de79d3
Author: remm <[email protected]>
AuthorDate: Fri May 22 19:20:50 2026 +0200
Avoid adding a "null" or empty string role where non is specified
---
java/org/apache/catalina/realm/MemoryRealm.java | 18 ++++++++++--------
test/org/apache/catalina/realm/TestMemoryRealm.java | 4 ++++
webapps/docs/changelog.xml | 4 ++++
3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/catalina/realm/MemoryRealm.java
b/java/org/apache/catalina/realm/MemoryRealm.java
index 474f019e0d..0766d6b491 100644
--- a/java/org/apache/catalina/realm/MemoryRealm.java
+++ b/java/org/apache/catalina/realm/MemoryRealm.java
@@ -156,15 +156,17 @@ public class MemoryRealm extends RealmBase {
// Accumulate the list of roles for this user
List<String> list = new ArrayList<>();
- roles += ",";
- while (true) {
- int comma = roles.indexOf(',');
- if (comma < 0) {
- break;
+ if (roles != null && !roles.isBlank()) {
+ roles += ",";
+ while (true) {
+ int comma = roles.indexOf(',');
+ if (comma < 0) {
+ break;
+ }
+ String role = roles.substring(0, comma).trim();
+ list.add(role);
+ roles = roles.substring(comma + 1);
}
- String role = roles.substring(0, comma).trim();
- list.add(role);
- roles = roles.substring(comma + 1);
}
// Construct and cache the Principal for this user
diff --git a/test/org/apache/catalina/realm/TestMemoryRealm.java
b/test/org/apache/catalina/realm/TestMemoryRealm.java
index 9ba71d268f..1035c80ce1 100644
--- a/test/org/apache/catalina/realm/TestMemoryRealm.java
+++ b/test/org/apache/catalina/realm/TestMemoryRealm.java
@@ -37,6 +37,7 @@ public class TestMemoryRealm extends TomcatBaseTest {
+ "<role rolename=\"testrole\" />"
+ "<group groupname=\"testgroup\" />"
+ "<user username=\"admin\" password=\"sekr3t\" roles=\"testrole,
otherrole\" groups=\"testgroup, othergroup\" />"
+ + "<user username=\"otheruser\" password=\"sekr3t2\" roles=\" \"
/>"
+ "</tomcat-users>";
@Test
@@ -74,6 +75,9 @@ public class TestMemoryRealm extends TomcatBaseTest {
p = lockout.authenticate("admin", "sekr3t");
Assert.assertNull(p);
+ Principal p2 = lockout.authenticate("otheruser", "sekr3t2");
+ Assert.assertNotNull(p2);
+ Assert.assertTrue(((GenericPrincipal) p2).getRoles().length == 0);
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 612dfcffc8..f3f950e10b 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -164,6 +164,10 @@
On JAAS logout, clear out role principals on the subject that were
added on commit, as recommended by the JAAS specification. (remm)
</fix>
+ <fix>
+ <code>MemoryRealm</code> should not add a dummy role when none is
+ specified in the configuration. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]