From 3e65737268b9ae0bea215faa4e694162335e7e4d Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Thu, 14 May 2020 20:19:18 +0200 Subject: [PATCH] Re-use roles and groups defined on users on MemoryUserDatabase creation When the XML file for MemoryUserDatabse is digested, the order of the elements was important. It had to be roles, groups and than users. With this patch the order of the elements is not important anymore. If a user element defined a role or group before the corresponding role or group element, we now will re-use that element and add a possibly missing description. --- .../catalina/users/MemoryUserDatabase.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/java/org/apache/catalina/users/MemoryUserDatabase.java b/java/org/apache/catalina/users/MemoryUserDatabase.java index 7c81f111e8..6062c7512a 100644 --- a/java/org/apache/catalina/users/MemoryUserDatabase.java +++ b/java/org/apache/catalina/users/MemoryUserDatabase.java @@ -736,7 +736,14 @@ class MemoryGroupCreationFactory extends AbstractObjectCreationFactory { } String description = attributes.getValue("description"); String roles = attributes.getValue("roles"); - Group group = database.createGroup(groupname, description); + Group group = database.findGroup(groupname); + if (group == null) { + group = database.createGroup(groupname, description); + } else { + if (group.getDescription() == null) { + group.setDescription(description); + } + } if (roles != null) { while (roles.length() > 0) { String rolename = null; @@ -781,8 +788,14 @@ class MemoryRoleCreationFactory extends AbstractObjectCreationFactory { rolename = attributes.getValue("name"); } String description = attributes.getValue("description"); - Role role = database.createRole(rolename, description); - return role; + Role existingRole = database.findRole(rolename); + if (existingRole == null) { + return database.createRole(rolename, description); + } + if (existingRole.getDescription() == null) { + existingRole.setDescription(description); + } + return existingRole; } private final MemoryUserDatabase database; -- 2.25.1