core: change ManagerBase::authorize to makeAuthorization
refs #2063
Change-Id: I0e6faced6e4e1733362e3ec018e2ee60fcefafa1
diff --git a/core/manager-base.cpp b/core/manager-base.cpp
index bad25b9..02190a2 100644
--- a/core/manager-base.cpp
+++ b/core/manager-base.cpp
@@ -99,5 +99,4 @@
handler(*command, prefix, interest, parameters, done);
}
-
} // namespace nfd
diff --git a/core/manager-base.hpp b/core/manager-base.hpp
index 31de566..8ace6bb 100644
--- a/core/manager-base.hpp
+++ b/core/manager-base.hpp
@@ -82,27 +82,7 @@
ndn::mgmt::PostNotification
registerNotificationStream(const std::string& verb);
-PUBLIC_WITH_TESTS_ELSE_PROTECTED: // command validation
- /**
- * @brief validate a request for ControlCommand.
- *
- * This is called by the dispatcher.
- *
- * @pre params != null
- * @pre typeid(*params) == typeid(ndn::nfd::ControlParameters)
- *
- * @param prefix the top prefix
- * @param interest a request for ControlCommand
- * @param params the parameters for ControlCommand
- * @param accept callback of successful validation, take the requester string as a argument
- * @param reject callback of failure in validation, take the action code as a argument
- */
- virtual void
- authorize(const Name& prefix, const Interest& interest,
- const ndn::mgmt::ControlParameters* params,
- ndn::mgmt::AcceptContinuation accept,
- ndn::mgmt::RejectContinuation reject) = 0;
-
+PUBLIC_WITH_TESTS_ELSE_PROTECTED:
/**
* @brief extract a requester from a ControlCommand request
*
@@ -115,7 +95,13 @@
extractRequester(const Interest& interest,
ndn::mgmt::AcceptContinuation accept);
-PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+ /**
+ * @return an authorization function for specified management module and verb
+ */
+ virtual ndn::mgmt::Authorization
+ makeAuthorization(const std::string& verb) = 0;
+
/**
* @brief validate the @p parameters for a given @p command
*
@@ -167,7 +153,7 @@
m_dispatcher.addControlCommand<ControlParameters>(
makeRelPrefix(verb),
- bind(&ManagerBase::authorize, this, _1, _2, _3, _4, _5),
+ makeAuthorization(verb),
bind(&ManagerBase::validateParameters, cref(*command), _1),
bind(&ManagerBase::handleCommand, command, handler, _1, _2, _3, _4));
}
diff --git a/daemon/mgmt/nfd-manager-base.cpp b/daemon/mgmt/nfd-manager-base.cpp
index c0ecaae..b30eca7 100644
--- a/daemon/mgmt/nfd-manager-base.cpp
+++ b/daemon/mgmt/nfd-manager-base.cpp
@@ -36,18 +36,20 @@
m_validator.addSupportedPrivilege(module);
}
-void
-NfdManagerBase::authorize(const Name& prefix, const Interest& interest,
- const ndn::mgmt::ControlParameters* params,
- ndn::mgmt::AcceptContinuation accept,
- ndn::mgmt::RejectContinuation reject)
+ndn::mgmt::Authorization
+NfdManagerBase::makeAuthorization(const std::string& verb)
{
- BOOST_ASSERT(params != nullptr);
- BOOST_ASSERT(typeid(*params) == typeid(ndn::nfd::ControlParameters));
+ 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); }));
+ m_validator.validate(interest,
+ bind([&interest, this, accept] { extractRequester(interest, accept); }),
+ bind([reject] { reject(ndn::mgmt::RejectReply::STATUS403); }));
+ };
}
} // namespace nfd
diff --git a/daemon/mgmt/nfd-manager-base.hpp b/daemon/mgmt/nfd-manager-base.hpp
index c7f30ff..49a3ea2 100644
--- a/daemon/mgmt/nfd-manager-base.hpp
+++ b/daemon/mgmt/nfd-manager-base.hpp
@@ -52,25 +52,8 @@
const std::string& module);
PUBLIC_WITH_TESTS_ELSE_PRIVATE: // command validation
- /**
- * @brief validate a request for ControlCommand.
- *
- * This is called by the dispatcher.
- *
- * @pre params != null
- * @pre typeid(*params) == typeid(ndn::nfd::ControlParameters)
- *
- * @param prefix the top prefix
- * @param interest a request for ControlCommand
- * @param params the parameters for ControlCommand
- * @param accept callback of successful validation, take the requester string as a argument
- * @param reject callback of failure in validation, take the action code as a argument
- */
- virtual void
- authorize(const Name& prefix, const Interest& interest,
- const ndn::mgmt::ControlParameters* params,
- ndn::mgmt::AcceptContinuation accept,
- ndn::mgmt::RejectContinuation reject) override;
+ virtual ndn::mgmt::Authorization
+ makeAuthorization(const std::string& verb) override;
private:
CommandValidator& m_validator;
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index dd0abca..d49f625 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -293,23 +293,23 @@
}
}
-void
-RibManager::authorize(const Name& prefix, const Interest& interest,
- const ndn::mgmt::ControlParameters* params,
- ndn::mgmt::AcceptContinuation accept,
- ndn::mgmt::RejectContinuation reject)
+ndn::mgmt::Authorization
+RibManager::makeAuthorization(const std::string& verb)
{
- BOOST_ASSERT(params != nullptr);
- BOOST_ASSERT(typeid(*params) == typeid(ndn::nfd::ControlParameters));
- BOOST_ASSERT(prefix == LOCAL_HOST_TOP_PREFIX || prefix == LOCAL_HOP_TOP_PREFIX);
+ 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));
+ BOOST_ASSERT(prefix == LOCAL_HOST_TOP_PREFIX || prefix == LOCAL_HOP_TOP_PREFIX);
- auto& validator = [this, &prefix] () -> ndn::ValidatorConfig & {
- return prefix == LOCAL_HOST_TOP_PREFIX ? m_localhostValidator : m_localhopValidator;
- }();
-
- validator.validate(interest,
- bind([&interest, this, accept] { extractRequester(interest, accept); }),
- bind([reject] { reject(ndn::mgmt::RejectReply::STATUS403); }));
+ ndn::ValidatorConfig& validator = prefix == LOCAL_HOST_TOP_PREFIX ?
+ m_localhostValidator : m_localhopValidator;
+ validator.validate(interest,
+ bind([&interest, this, accept] { extractRequester(interest, accept); }),
+ bind([reject] { reject(ndn::mgmt::RejectReply::STATUS403); }));
+ };
}
void
diff --git a/rib/rib-manager.hpp b/rib/rib-manager.hpp
index 998a284..a27d353 100644
--- a/rib/rib-manager.hpp
+++ b/rib/rib-manager.hpp
@@ -107,28 +107,8 @@
void
setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
-private: // command validation
- /**
- * @brief validate a request for ControlCommand.
- *
- * This is called by the dispatcher.
- *
- * @pre params != null
- * @pre typeid(*params) == typeid(ndn::nfd::ControlParameters)
- *
- * @param prefix the top prefix
- * @param interest a request for ControlCommand
- * @param params the parameters for ControlCommand
- * @param accept callback of successful validation, take the requester string as a argument
- * @param reject callback of failure in validation, take the action code as a argument
- *
- * use m_localhostValidator / m_localhopValidator to validate commands according to @p prefix.
- */
- virtual void
- authorize(const Name& prefix, const Interest& interest,
- const ndn::mgmt::ControlParameters* params,
- ndn::mgmt::AcceptContinuation accept,
- ndn::mgmt::RejectContinuation reject) override;
+ virtual ndn::mgmt::Authorization
+ makeAuthorization(const std::string& verb) override;
private: // Face monitor
void
diff --git a/tests/core/manager-base.t.cpp b/tests/core/manager-base.t.cpp
index 7ebe95e..6e696ff 100644
--- a/tests/core/manager-base.t.cpp
+++ b/tests/core/manager-base.t.cpp
@@ -56,15 +56,19 @@
public:
ManagerTester(Dispatcher& dispatcher,
const std::string& module)
- : ManagerBase(dispatcher, module) {
+ : ManagerBase(dispatcher, module)
+ {
}
- virtual void
- authorize(const Name& prefix, const Interest& interest,
- const ndn::mgmt::ControlParameters* params,
- ndn::mgmt::AcceptContinuation accept,
- ndn::mgmt::RejectContinuation reject) {
- extractRequester(interest, accept);
+ virtual ndn::mgmt::Authorization
+ makeAuthorization(const std::string& verb) override
+ {
+ return [this] (const Name& prefix, const Interest& interest,
+ const ndn::mgmt::ControlParameters* params,
+ ndn::mgmt::AcceptContinuation accept,
+ ndn::mgmt::RejectContinuation reject) {
+ accept("requester");
+ };
}
};
diff --git a/tests/daemon/mgmt/nfd-manager-base.t.cpp b/tests/daemon/mgmt/nfd-manager-base.t.cpp
index 410f41c..340c9ec 100644
--- a/tests/daemon/mgmt/nfd-manager-base.t.cpp
+++ b/tests/daemon/mgmt/nfd-manager-base.t.cpp
@@ -57,6 +57,8 @@
BOOST_AUTO_TEST_CASE(CommandAuthorization)
{
+ ndn::mgmt::Authorization authorize = m_manager.makeAuthorization("test-verb");
+
bool didAcceptCallbackFire = false;
bool didRejectCallbackFire = false;
auto testAuthorization = [&] {
@@ -66,9 +68,9 @@
auto command = makeControlCommandRequest("/localhost/nfd/test-module/test-verb",
ControlParameters());
ndn::nfd::ControlParameters params;
- m_manager.authorize("/top/prefix", *command, ¶ms,
- bind([&] { didAcceptCallbackFire = true; }),
- bind([&] { didRejectCallbackFire = true; }));
+ authorize("/top/prefix", *command, ¶ms,
+ bind([&] { didAcceptCallbackFire = true; }),
+ bind([&] { didRejectCallbackFire = true; }));
};
testAuthorization();