Funnel messages through the generic SendUnicastRequest method to take advantage of the centralised security features.

This commit is contained in:
Gunnar Beutner 2012-04-23 16:48:40 +02:00
parent a60c7cd2a3
commit 5fa34a3e3d
3 changed files with 21 additions and 12 deletions

View File

@ -73,6 +73,23 @@ void EndpointManager::UnregisterEndpoint(Endpoint::Ptr endpoint)
m_Endpoints.remove(endpoint);
}
void EndpointManager::SendUnicastRequest(Endpoint::Ptr sender, Endpoint::Ptr recipient, const JsonRpcRequest& request, bool fromLocal)
{
if (sender == recipient)
return;
/* don't forward messages between non-local endpoints */
if (!fromLocal && !recipient->IsLocal())
return;
string method;
if (!request.GetMethod(&method))
throw InvalidArgumentException("Missing 'method' parameter.");
if (recipient->IsMethodSink(method) && recipient->IsAllowedMethodSink(method))
recipient->ProcessRequest(sender, request);
}
void EndpointManager::SendAnycastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal)
{
throw NotImplementedException();
@ -92,17 +109,7 @@ void EndpointManager::SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRe
for (list<Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
{
Endpoint::Ptr endpoint = *i;
if (endpoint == sender)
continue;
/* send non-local messages to just the local endpoints */
if (!fromLocal && !endpoint->IsLocal())
continue;
if (endpoint->IsMethodSink(method) && endpoint->IsAllowedMethodSink(method))
endpoint->ProcessRequest(sender, request);
SendUnicastRequest(sender, *i, request, fromLocal);
}
}

View File

@ -36,6 +36,7 @@ public:
void RegisterEndpoint(Endpoint::Ptr endpoint);
void UnregisterEndpoint(Endpoint::Ptr endpoint);
void SendUnicastRequest(Endpoint::Ptr sender, Endpoint::Ptr recipient, const JsonRpcRequest& request, bool fromLocal = true);
void SendAnycastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal = true);
void SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal = true);

View File

@ -46,7 +46,8 @@ int SubscriptionComponent::SyncSubscription(Endpoint::Ptr target, string type, c
subscriptionMessage.SetMethod(nmea.Method);
request.SetParams(subscriptionMessage);
target->ProcessRequest(m_SubscriptionEndpoint, request);
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
endpointManager->SendUnicastRequest(m_SubscriptionEndpoint, target, request);
return 0;
}