diff PalantirServer/PalantirInitialization.cpp @ 25:dd1489098265

basic http authentication
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 Aug 2012 11:20:49 +0200
parents 62bd05fe4b7c
children
line wrap: on
line diff
--- a/PalantirServer/PalantirInitialization.cpp	Tue Aug 28 10:42:43 2012 +0200
+++ b/PalantirServer/PalantirInitialization.cpp	Tue Aug 28 11:20:49 2012 +0200
@@ -205,4 +205,32 @@
       target.insert(members[i]);
     }
   }
+
+
+
+  void SetupRegisteredUsers(MongooseServer& httpServer)
+  {
+    boost::mutex::scoped_lock lock(globalMutex_);
+
+    httpServer.ClearUsers();
+
+    if (!configuration_->isMember("RegisteredUsers"))
+    {
+      return;
+    }
+
+    const Json::Value& users = (*configuration_) ["RegisteredUsers"];
+    if (users.type() != Json::objectValue)
+    {
+      throw PalantirException("Badly formatted list of users");
+    }
+
+    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());
+    }
+  }
 }