[New] Allow case insensitive usernames in privilege

This commit is contained in:
Robert von Burg 2020-09-25 17:45:10 +02:00
parent 9ec060fe50
commit 468cd0643a
1 changed files with 8 additions and 7 deletions

View File

@ -106,19 +106,20 @@ public class XmlPersistenceHandler implements PersistenceHandler {
@Override
public void addUser(User user) {
if (this.userMap
.containsKey(this.caseInsensitiveUsername ? user.getUsername().toLowerCase() : user.getUsername()))
String username = this.caseInsensitiveUsername ? user.getUsername().toLowerCase() : user.getUsername();
if (this.userMap.containsKey(username))
throw new IllegalStateException(MessageFormat.format("The user {0} already exists!", user.getUsername()));
this.userMap.put(user.getUsername(), user);
this.userMap.put(username, user);
this.userMapDirty = true;
}
@Override
public void replaceUser(User user) {
if (!this.userMap.containsKey(user.getUsername()))
throw new IllegalStateException(MessageFormat
.format("The user {0} can not be replaced as it does not exiset!", user.getUsername()));
this.userMap.put(user.getUsername(), user);
String username = this.caseInsensitiveUsername ? user.getUsername().toLowerCase() : user.getUsername();
if (!this.userMap.containsKey(username))
throw new IllegalStateException(
MessageFormat.format("The user {0} can not be replaced as it does not exist!", user.getUsername()));
this.userMap.put(username, user);
this.userMapDirty = true;
}