Mercurial > hg > orthanc
changeset 6226:3298fa589b27
do not create the default user if "RegisteredUsers" is empty
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Jul 2025 18:56:18 +0200 |
parents | 83e1282c5403 |
children | c3fb276f8eba |
files | NEWS OrthancServer/Resources/Configuration.json OrthancServer/Sources/OrthancConfiguration.cpp OrthancServer/Sources/OrthancConfiguration.h OrthancServer/Sources/main.cpp |
diffstat | 5 files changed, 62 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Mon Jul 07 17:18:38 2025 +0200 +++ b/NEWS Mon Jul 07 18:56:18 2025 +0200 @@ -35,6 +35,12 @@ the plugin did not detect any changes in the configuration that should trigger a reconstruct. +Maintenance +----------- + +* If the "RegisteredUsers" configuration option is present but empty, + Orthanc does not create the default user "orthanc" anymore. + Version 1.12.8 (2025-06-13)
--- a/OrthancServer/Resources/Configuration.json Mon Jul 07 17:18:38 2025 +0200 +++ b/OrthancServer/Resources/Configuration.json Mon Jul 07 18:56:18 2025 +0200 @@ -307,10 +307,11 @@ // The list of the registered users. Because Orthanc uses HTTP // Basic Authentication, the passwords are stored as plain text. - "RegisteredUsers" : { - // "alice" : "alicePassword" - }, - + /** + "RegisteredUsers" : { + // "alice" : "alicePassword" + }, + **/ /**
--- a/OrthancServer/Sources/OrthancConfiguration.cpp Mon Jul 07 17:18:38 2025 +0200 +++ b/OrthancServer/Sources/OrthancConfiguration.cpp Mon Jul 07 18:56:18 2025 +0200 @@ -707,32 +707,46 @@ } - bool OrthancConfiguration::SetupRegisteredUsers(HttpServer& httpServer) const + OrthancConfiguration::RegisteredUsersStatus OrthancConfiguration::SetupRegisteredUsers(HttpServer& httpServer) const { + static const char* const REGISTERED_USERS = "RegisteredUsers"; + httpServer.ClearUsers(); - if (!json_.isMember("RegisteredUsers")) + if (!json_.isMember(REGISTERED_USERS)) { - return false; + return RegisteredUsersStatus_NoConfiguration; } - - const Json::Value& users = json_["RegisteredUsers"]; - if (users.type() != Json::objectValue) + else { - throw OrthancException(ErrorCode_BadFileFormat, "Badly formatted list of users"); - } + const Json::Value& users = json_[REGISTERED_USERS]; + if (users.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadFileFormat, "Badly formatted list of users"); + } - bool hasUser = false; - Json::Value::Members usernames = users.getMemberNames(); - for (size_t i = 0; i < usernames.size(); i++) - { - const std::string& username = usernames[i]; - std::string password = users[username].asString(); - httpServer.RegisterUser(username.c_str(), password.c_str()); - hasUser = true; + bool hasUser = false; + Json::Value::Members usernames = users.getMemberNames(); + for (size_t i = 0; i < usernames.size(); i++) + { + const std::string& username = usernames[i]; + + if (users[username].type() != Json::stringValue) + { + throw OrthancException(ErrorCode_BadFileFormat, "Badly formatted list of users"); + } + else + { + std::string password = users[username].asString(); + httpServer.RegisterUser(username.c_str(), password.c_str()); + hasUser = true; + } + } + + return (hasUser ? + RegisteredUsersStatus_HasUser : + RegisteredUsersStatus_NoUser); } - - return hasUser; }
--- a/OrthancServer/Sources/OrthancConfiguration.h Mon Jul 07 17:18:38 2025 +0200 +++ b/OrthancServer/Sources/OrthancConfiguration.h Mon Jul 07 18:56:18 2025 +0200 @@ -49,6 +49,14 @@ class OrthancConfiguration : public boost::noncopyable { + public: + enum RegisteredUsersStatus + { + RegisteredUsersStatus_NoConfiguration, // There is no "RegisteredUsers" section in the configuration file + RegisteredUsersStatus_NoUser, // The "RegisteredUsers" section is present, but declares no user + RegisteredUsersStatus_HasUser // The "RegisteredUsers" section is present and contains at least 1 user + }; + private: typedef std::map<std::string, RemoteModalityParameters> Modalities; typedef std::map<std::string, WebServiceParameters> Peers; @@ -198,9 +206,8 @@ void GetListOfOrthancPeers(std::set<std::string>& target) const; unsigned int GetDicomLossyTranscodingQuality() const; - - // Returns "true" iff. at least one user is registered - bool SetupRegisteredUsers(HttpServer& httpServer) const; + + RegisteredUsersStatus SetupRegisteredUsers(HttpServer& httpServer) const; std::string InterpretStringParameterAsPath(const std::string& parameter) const;
--- a/OrthancServer/Sources/main.cpp Mon Jul 07 17:18:38 2025 +0200 +++ b/OrthancServer/Sources/main.cpp Mon Jul 07 18:56:18 2025 +0200 @@ -1102,12 +1102,16 @@ httpServer.SetAuthenticationEnabled(false); } - bool hasUsers = lock.GetConfiguration().SetupRegisteredUsers(httpServer); + OrthancConfiguration::RegisteredUsersStatus status = lock.GetConfiguration().SetupRegisteredUsers(httpServer); + assert(status == OrthancConfiguration::RegisteredUsersStatus_NoConfiguration || + status == OrthancConfiguration::RegisteredUsersStatus_NoUser || + status == OrthancConfiguration::RegisteredUsersStatus_HasUser); if (httpServer.IsAuthenticationEnabled() && - !hasUsers) + status != OrthancConfiguration::RegisteredUsersStatus_HasUser) { - if (httpServer.IsRemoteAccessAllowed()) + if (httpServer.IsRemoteAccessAllowed() && + status == OrthancConfiguration::RegisteredUsersStatus_NoConfiguration) { /** * Starting with Orthanc 1.5.8, if no user is explicitly @@ -1129,7 +1133,8 @@ else { LOG(WARNING) << "HTTP authentication is enabled, but no user is declared, " - << "check the value of configuration option \"RegisteredUsers\""; + << "check the value of configuration option \"RegisteredUsers\" " + << "if you cannot access Orthanc as expected"; } }