mgmt: NfdManagerBase::makeAuthorization uses CommandAuthenticator
This commit also eliminates Forwarder in Mgmt/TestFaceManager/CreateFace test suite
and uses FaceTable directly.
refs #2063
Change-Id: I596e8c2a12dad64ee75082f384955f30d574f53e
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index e3e0cb8..8b7057c 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -52,8 +52,8 @@
NFD_LOG_INIT("FaceManager");
-FaceManager::FaceManager(FaceTable& faceTable, Dispatcher& dispatcher, CommandValidator& validator)
- : NfdManagerBase(dispatcher, validator, "faces")
+FaceManager::FaceManager(FaceTable& faceTable, Dispatcher& dispatcher, CommandAuthenticator& authenticator)
+ : NfdManagerBase(dispatcher, authenticator, "faces")
, m_faceTable(faceTable)
{
registerCommandHandler<ndn::nfd::FaceCreateCommand>("create",
diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp
index ec0af92..f31f04b 100644
--- a/daemon/mgmt/face-manager.hpp
+++ b/daemon/mgmt/face-manager.hpp
@@ -46,7 +46,7 @@
public:
FaceManager(FaceTable& faceTable,
Dispatcher& dispatcher,
- CommandValidator& validator);
+ CommandAuthenticator& authenticator);
/**
* @brief Subscribe to face_system section for the config file
diff --git a/daemon/mgmt/fib-manager.cpp b/daemon/mgmt/fib-manager.cpp
index 1c15ebf..9992789 100644
--- a/daemon/mgmt/fib-manager.cpp
+++ b/daemon/mgmt/fib-manager.cpp
@@ -34,8 +34,8 @@
FibManager::FibManager(Fib& fib,
const FaceTable& faceTable,
Dispatcher& dispatcher,
- CommandValidator& validator)
- : NfdManagerBase(dispatcher, validator, "fib")
+ CommandAuthenticator& authenticator)
+ : NfdManagerBase(dispatcher, authenticator, "fib")
, m_fib(fib)
, m_faceTable(faceTable)
{
diff --git a/daemon/mgmt/fib-manager.hpp b/daemon/mgmt/fib-manager.hpp
index 9599a01..b5c6984 100644
--- a/daemon/mgmt/fib-manager.hpp
+++ b/daemon/mgmt/fib-manager.hpp
@@ -42,18 +42,10 @@
class FibManager : public NfdManagerBase
{
public:
- /**
- * @brief construct a FibManger
- *
- * @param fib the managed FIB
- * @param faceTable FaceTable for querying available faces
- * @param dispatcher the management dispatcher
- * @param validator the command validator
- */
FibManager(Fib& fib,
const FaceTable& faceTable,
Dispatcher& dispatcher,
- CommandValidator& validator);
+ CommandAuthenticator& authenticator);
private:
void
diff --git a/daemon/mgmt/nfd-manager-base.cpp b/daemon/mgmt/nfd-manager-base.cpp
index b30eca7..b417934 100644
--- a/daemon/mgmt/nfd-manager-base.cpp
+++ b/daemon/mgmt/nfd-manager-base.cpp
@@ -28,28 +28,17 @@
namespace nfd {
NfdManagerBase::NfdManagerBase(Dispatcher& dispatcher,
- CommandValidator& validator,
+ CommandAuthenticator& authenticator,
const std::string& module)
: ManagerBase(dispatcher, module)
- , m_validator(validator)
+ , m_authenticator(authenticator)
{
- m_validator.addSupportedPrivilege(module);
}
ndn::mgmt::Authorization
NfdManagerBase::makeAuthorization(const std::string& verb)
{
- return [this] (const Name& prefix, const Interest& interest,
- const ndn::mgmt::ControlParameters* params,
- const ndn::mgmt::AcceptContinuation& accept,
- const ndn::mgmt::RejectContinuation& reject) {
- BOOST_ASSERT(params != nullptr);
- BOOST_ASSERT(typeid(*params) == typeid(ndn::nfd::ControlParameters));
-
- m_validator.validate(interest,
- bind([&interest, this, accept] { extractRequester(interest, accept); }),
- bind([reject] { reject(ndn::mgmt::RejectReply::STATUS403); }));
- };
+ return m_authenticator.makeAuthorization(this->getModule(), verb);
}
} // namespace nfd
diff --git a/daemon/mgmt/nfd-manager-base.hpp b/daemon/mgmt/nfd-manager-base.hpp
index 49a3ea2..27c3392 100644
--- a/daemon/mgmt/nfd-manager-base.hpp
+++ b/daemon/mgmt/nfd-manager-base.hpp
@@ -26,14 +26,8 @@
#ifndef NFD_DAEMON_MGMT_NFD_MANAGER_BASE_HPP
#define NFD_DAEMON_MGMT_NFD_MANAGER_BASE_HPP
-#include "core/common.hpp"
-#include "command-validator.hpp"
#include "core/manager-base.hpp"
-
-#include <ndn-cxx/mgmt/dispatcher.hpp>
-#include <ndn-cxx/management/nfd-control-command.hpp>
-#include <ndn-cxx/management/nfd-control-response.hpp>
-#include <ndn-cxx/management/nfd-control-parameters.hpp>
+#include "command-authenticator.hpp"
namespace nfd {
@@ -48,7 +42,7 @@
{
public:
NfdManagerBase(Dispatcher& dispatcher,
- CommandValidator& validator,
+ CommandAuthenticator& authenticator,
const std::string& module);
PUBLIC_WITH_TESTS_ELSE_PRIVATE: // command validation
@@ -56,7 +50,7 @@
makeAuthorization(const std::string& verb) override;
private:
- CommandValidator& m_validator;
+ CommandAuthenticator& m_authenticator;
};
} // namespace nfd
diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp
index 1f0c208..312a35c 100644
--- a/daemon/mgmt/strategy-choice-manager.cpp
+++ b/daemon/mgmt/strategy-choice-manager.cpp
@@ -33,8 +33,8 @@
StrategyChoiceManager::StrategyChoiceManager(StrategyChoice& strategyChoice,
Dispatcher& dispatcher,
- CommandValidator& validator)
- : NfdManagerBase(dispatcher, validator, "strategy-choice")
+ CommandAuthenticator& authenticator)
+ : NfdManagerBase(dispatcher, authenticator, "strategy-choice")
, m_table(strategyChoice)
{
registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>("set",
diff --git a/daemon/mgmt/strategy-choice-manager.hpp b/daemon/mgmt/strategy-choice-manager.hpp
index 9fd4ad3..5520790 100644
--- a/daemon/mgmt/strategy-choice-manager.hpp
+++ b/daemon/mgmt/strategy-choice-manager.hpp
@@ -43,7 +43,7 @@
public:
StrategyChoiceManager(strategy_choice::StrategyChoice& table,
Dispatcher& dispatcher,
- CommandValidator& validator);
+ CommandAuthenticator& authenticator);
private:
void
diff --git a/daemon/nfd.cpp b/daemon/nfd.cpp
index 35fc941..5d6bec7 100644
--- a/daemon/nfd.cpp
+++ b/daemon/nfd.cpp
@@ -38,9 +38,6 @@
#include "mgmt/forwarder-status-manager.hpp"
#include "mgmt/general-config-section.hpp"
#include "mgmt/tables-config-section.hpp"
-#include "mgmt/command-validator.hpp"
-
-#include <ndn-cxx/mgmt/dispatcher.hpp>
namespace nfd {
@@ -74,12 +71,10 @@
{
}
-Nfd::~Nfd()
-{
- // It is necessary to explicitly define the destructor, because some member variables (e.g.,
- // unique_ptr<Forwarder>) are forward-declared, but implicitly declared destructor requires
- // complete types for all members when instantiated.
-}
+// It is necessary to explicitly define the destructor, because some member variables (e.g.,
+// unique_ptr<Forwarder>) are forward-declared, but implicitly declared destructor requires
+// complete types for all members when instantiated.
+Nfd::~Nfd() = default;
void
Nfd::initialize()
@@ -125,7 +120,6 @@
}
}
-
static inline void
ignoreRibAndLogSections(const std::string& filename, const std::string& sectionName,
const ConfigSection& section, bool isDryRun)
@@ -146,24 +140,17 @@
{
std::tie(m_internalFace, m_internalClientFace) = face::makeInternalFace(m_keyChain);
m_forwarder->getFaceTable().addReserved(m_internalFace, face::FACEID_INTERNAL_FACE);
+
m_dispatcher.reset(new ndn::mgmt::Dispatcher(*m_internalClientFace, m_keyChain));
-
- m_validator.reset(new CommandValidator());
-
- m_fibManager.reset(new FibManager(m_forwarder->getFib(),
- m_forwarder->getFaceTable(),
- *m_dispatcher,
- *m_validator));
-
- m_faceManager.reset(new FaceManager(m_forwarder->getFaceTable(),
- *m_dispatcher,
- *m_validator));
-
- m_strategyChoiceManager.reset(new StrategyChoiceManager(m_forwarder->getStrategyChoice(),
- *m_dispatcher,
- *m_validator));
+ m_authenticator = CommandAuthenticator::create();
m_forwarderStatusManager.reset(new ForwarderStatusManager(*m_forwarder, *m_dispatcher));
+ m_faceManager.reset(new FaceManager(m_forwarder->getFaceTable(),
+ *m_dispatcher, *m_authenticator));
+ m_fibManager.reset(new FibManager(m_forwarder->getFib(), m_forwarder->getFaceTable(),
+ *m_dispatcher, *m_authenticator));
+ m_strategyChoiceManager.reset(new StrategyChoiceManager(m_forwarder->getStrategyChoice(),
+ *m_dispatcher, *m_authenticator));
ConfigFile config(&ignoreRibAndLogSections);
general::setConfigFile(config);
@@ -176,8 +163,7 @@
m_forwarder->getNetworkRegionTable());
tablesConfig.setConfigFile(config);
- m_validator->setConfigFile(config);
-
+ m_authenticator->setConfigFile(config);
m_faceManager->setConfigFile(config);
// parse config file
@@ -216,10 +202,9 @@
m_forwarder->getStrategyChoice(),
m_forwarder->getMeasurements(),
m_forwarder->getNetworkRegionTable());
-
tablesConfig.setConfigFile(config);
- m_validator->setConfigFile(config);
+ m_authenticator->setConfigFile(config);
m_faceManager->setConfigFile(config);
if (!m_configFile.empty()) {
diff --git a/daemon/nfd.hpp b/daemon/nfd.hpp
index d8fd12e..f98d3b6 100644
--- a/daemon/nfd.hpp
+++ b/daemon/nfd.hpp
@@ -42,11 +42,11 @@
namespace nfd {
class Forwarder;
+class CommandAuthenticator;
class FibManager;
class FaceManager;
class StrategyChoiceManager;
class ForwarderStatusManager;
-class CommandValidator;
namespace face {
class Face;
@@ -107,19 +107,18 @@
unique_ptr<Forwarder> m_forwarder;
- ndn::KeyChain& m_keyChain;
- shared_ptr<face::Face> m_internalFace;
- shared_ptr<ndn::Face> m_internalClientFace;
- unique_ptr<CommandValidator> m_validator;
-
- unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
- unique_ptr<FibManager> m_fibManager;
- unique_ptr<FaceManager> m_faceManager;
- unique_ptr<StrategyChoiceManager> m_strategyChoiceManager;
+ ndn::KeyChain& m_keyChain;
+ shared_ptr<face::Face> m_internalFace;
+ shared_ptr<ndn::Face> m_internalClientFace;
+ unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
+ shared_ptr<CommandAuthenticator> m_authenticator;
unique_ptr<ForwarderStatusManager> m_forwarderStatusManager;
+ unique_ptr<FaceManager> m_faceManager;
+ unique_ptr<FibManager> m_fibManager;
+ unique_ptr<StrategyChoiceManager> m_strategyChoiceManager;
unique_ptr<ndn::util::NetworkMonitor> m_networkMonitor;
- scheduler::ScopedEventId m_reloadConfigEvent;
+ scheduler::ScopedEventId m_reloadConfigEvent;
};
} // namespace nfd