From 659891cda0b355202a43c594f04933f8f9ddc463 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 19 Oct 2024 22:06:31 +0200 Subject: [PATCH] [New] Don't write roles and groups for remote users in xml file --- .../handler/DefaultPrivilegeHandler.java | 2 +- .../xml/PrivilegeUsersSaxWriter.java | 39 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/strolch-privilege/src/main/java/li/strolch/privilege/handler/DefaultPrivilegeHandler.java b/strolch-privilege/src/main/java/li/strolch/privilege/handler/DefaultPrivilegeHandler.java index f550bb5ba..08e257287 100644 --- a/strolch-privilege/src/main/java/li/strolch/privilege/handler/DefaultPrivilegeHandler.java +++ b/strolch-privilege/src/main/java/li/strolch/privilege/handler/DefaultPrivilegeHandler.java @@ -472,7 +472,7 @@ private Certificate internalAuthenticate(String username, char[] password, Strin // log logger.info("User {} authenticated with password : {}", username, certificate); } else { - logger.info("User {} authenticated with basic auth: {}", username, certificate); + logger.info("User {} authenticated with basic auth/sigle use: {}", username, certificate); } // return the certificate diff --git a/strolch-privilege/src/main/java/li/strolch/privilege/xml/PrivilegeUsersSaxWriter.java b/strolch-privilege/src/main/java/li/strolch/privilege/xml/PrivilegeUsersSaxWriter.java index 0780d1490..108e188cc 100644 --- a/strolch-privilege/src/main/java/li/strolch/privilege/xml/PrivilegeUsersSaxWriter.java +++ b/strolch-privilege/src/main/java/li/strolch/privilege/xml/PrivilegeUsersSaxWriter.java @@ -16,6 +16,7 @@ package li.strolch.privilege.xml; import javanet.staxutils.IndentingXMLStreamWriter; +import li.strolch.privilege.model.UserState; import li.strolch.privilege.model.internal.PasswordCrypt; import li.strolch.privilege.model.internal.User; import li.strolch.privilege.model.internal.UserHistory; @@ -85,25 +86,29 @@ public void write() throws IOException, XMLStreamException { if (user.isPasswordChangeRequested()) writeStringElement(xmlWriter, PASSWORD_CHANGE_REQUESTED, "true"); - // add all the group elements - if (!user.getGroups().isEmpty()) { - xmlWriter.writeStartElement(GROUPS); - writeStringList(xmlWriter, GROUP, user.getGroups()); - xmlWriter.writeEndElement(); + // only right groups and roles if not a remote user + if (user.getUserState() != UserState.REMOTE) { + + // add all the group elements + if (!user.getGroups().isEmpty()) { + xmlWriter.writeStartElement(GROUPS); + writeStringList(xmlWriter, GROUP, user.getGroups()); + xmlWriter.writeEndElement(); + } + + // add all the role elements + if (!user.getRoles().isEmpty()) { + xmlWriter.writeStartElement(ROLES); + writeStringList(xmlWriter, ROLE, user.getRoles()); + xmlWriter.writeEndElement(); + } + + // add the parameters + Map properties = user.getProperties(); + if (!properties.isEmpty()) + writeStringMapElement(xmlWriter, properties, PROPERTIES, PROPERTY); } - // add all the role elements - if (!user.getRoles().isEmpty()) { - xmlWriter.writeStartElement(ROLES); - writeStringList(xmlWriter, ROLE, user.getRoles()); - xmlWriter.writeEndElement(); - } - - // add the parameters - Map properties = user.getProperties(); - if (!properties.isEmpty()) - writeStringMapElement(xmlWriter, properties, PROPERTIES, PROPERTY); - if (!user.isHistoryEmpty()) { UserHistory history = user.getHistory(); xmlWriter.writeStartElement(HISTORY);