2012-04-20 16:06:06 +02:00
|
|
|
#include "i2-icinga.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
string AuthenticationComponent::GetName(void) const
|
|
|
|
{
|
|
|
|
return "authenticationcomponent";
|
|
|
|
}
|
|
|
|
|
|
|
|
void AuthenticationComponent::Start(void)
|
|
|
|
{
|
|
|
|
m_AuthenticationEndpoint = make_shared<VirtualEndpoint>();
|
2012-04-23 09:48:20 +02:00
|
|
|
m_AuthenticationEndpoint->RegisterMethodHandler("auth::SetIdentity", bind_weak(&AuthenticationComponent::IdentityMessageHandler, shared_from_this()));
|
2012-04-23 16:49:02 +02:00
|
|
|
m_AuthenticationEndpoint->RegisterMethodSource("auth::Welcome");
|
2012-04-20 16:06:06 +02:00
|
|
|
|
2012-04-24 07:16:34 +02:00
|
|
|
EndpointManager::Ptr mgr = GetEndpointManager();
|
2012-04-20 16:06:06 +02:00
|
|
|
mgr->OnNewEndpoint += bind_weak(&AuthenticationComponent::NewEndpointHandler, shared_from_this());
|
|
|
|
mgr->ForeachEndpoint(bind(&AuthenticationComponent::NewEndpointHandler, this, _1));
|
|
|
|
mgr->RegisterEndpoint(m_AuthenticationEndpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AuthenticationComponent::Stop(void)
|
|
|
|
{
|
2012-04-24 07:16:34 +02:00
|
|
|
EndpointManager::Ptr mgr = GetEndpointManager();
|
2012-04-20 16:06:06 +02:00
|
|
|
|
2012-04-24 07:16:34 +02:00
|
|
|
if (mgr)
|
2012-04-20 16:10:38 +02:00
|
|
|
mgr->UnregisterEndpoint(m_AuthenticationEndpoint);
|
2012-04-20 16:06:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int AuthenticationComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
|
|
|
|
{
|
2012-04-20 16:10:38 +02:00
|
|
|
if (neea.Endpoint->IsLocal() || neea.Endpoint->HasIdentity())
|
2012-04-20 16:06:06 +02:00
|
|
|
return 0;
|
|
|
|
|
2012-04-23 13:45:41 +02:00
|
|
|
neea.Endpoint->AddAllowedMethodSinkPrefix("auth::");
|
|
|
|
neea.Endpoint->AddAllowedMethodSourcePrefix("auth::");
|
|
|
|
|
2012-04-23 17:00:39 +02:00
|
|
|
neea.Endpoint->RegisterMethodSink("auth::SetIdentity");
|
|
|
|
|
2012-04-20 16:06:06 +02:00
|
|
|
JsonRpcRequest request;
|
2012-04-23 17:00:39 +02:00
|
|
|
request.SetMethod("auth::SetIdentity");
|
2012-04-20 16:06:06 +02:00
|
|
|
|
|
|
|
IdentityMessage params;
|
|
|
|
params.SetIdentity("keks");
|
|
|
|
request.SetParams(params);
|
|
|
|
|
2012-04-24 07:16:34 +02:00
|
|
|
GetEndpointManager()->SendUnicastRequest(m_AuthenticationEndpoint, neea.Endpoint, request);
|
2012-04-20 16:10:38 +02:00
|
|
|
|
|
|
|
return 0;
|
2012-04-20 16:06:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int AuthenticationComponent::IdentityMessageHandler(const NewRequestEventArgs& nrea)
|
|
|
|
{
|
|
|
|
Message params;
|
|
|
|
if (!nrea.Request.GetParams(¶ms))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
IdentityMessage identityMessage = params;
|
|
|
|
|
|
|
|
string identity;
|
|
|
|
if (!identityMessage.GetIdentity(&identity))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nrea.Sender->SetIdentity(identity);
|
|
|
|
|
|
|
|
/* there's no authentication for now, just tell them it's ok to send messages */
|
|
|
|
JsonRpcRequest request;
|
2012-04-23 09:48:20 +02:00
|
|
|
request.SetMethod("auth::Welcome");
|
2012-04-23 16:49:02 +02:00
|
|
|
|
2012-04-24 07:16:34 +02:00
|
|
|
GetEndpointManager()->SendUnicastRequest(m_AuthenticationEndpoint, nrea.Sender, request);
|
2012-04-20 16:06:06 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|