--- /dev/null
+{
+ "component": {
+ "configrpc": { "replicate": "0", "configSource": "1" }
+ },
+
+ "rpclistener": {
+ "kekslistener": { "replicate": "0", "port": "7777" }
+ },
+ "rpcconnection": {
+ "keksclient": { "replicate": "0", "hostname": "localhost", "port": "7777" }
+ },
+ "host": {
+ "localhost": { "ipaddr": "127.0.0.1" }
+ }
+}
\ No newline at end of file
libicinga.la
libicinga_la_SOURCES = \
+ authenticationcomponent.cpp \
+ authenticationcomponent.h \
endpoint.cpp \
endpoint.h \
endpointmanager.cpp \
--- /dev/null
+#include "i2-icinga.h"
+
+using namespace icinga;
+
+IcingaApplication::Ptr AuthenticationComponent::GetIcingaApplication(void) const
+{
+ return static_pointer_cast<IcingaApplication>(GetApplication());
+}
+
+string AuthenticationComponent::GetName(void) const
+{
+ return "authenticationcomponent";
+}
+
+void AuthenticationComponent::Start(void)
+{
+ m_AuthenticationEndpoint = make_shared<VirtualEndpoint>();
+ m_AuthenticationEndpoint->RegisterMethodHandler("message::SetIdentity", bind_weak(&AuthenticationComponent::IdentityMessageHandler, shared_from_this()));
+
+ EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
+ mgr->OnNewEndpoint += bind_weak(&AuthenticationComponent::NewEndpointHandler, shared_from_this());
+ mgr->ForeachEndpoint(bind(&AuthenticationComponent::NewEndpointHandler, this, _1));
+ mgr->RegisterEndpoint(m_AuthenticationEndpoint);
+}
+
+void AuthenticationComponent::Stop(void)
+{
+
+}
+
+int AuthenticationComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
+{
+ if (neea.Endpoint->IsLocal())
+ return 0;
+
+ JsonRpcRequest request;
+ request.SetVersion("2.0");
+ request.SetMethod("message::SetIdentity");
+
+ IdentityMessage params;
+ params.SetIdentity("keks");
+ request.SetParams(params);
+
+ neea.Endpoint->ProcessRequest(m_AuthenticationEndpoint, request);
+}
+
+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;
+ request.SetVersion("2.0");
+ request.SetMethod("message::Welcome");
+ nrea.Sender->ProcessRequest(m_AuthenticationEndpoint, request);
+
+ return 0;
+}
--- /dev/null
+#ifndef AUTHENTICATIONCOMPONENT_H
+#define AUTHENTICATIONCOMPONENT_H
+
+namespace icinga
+{
+
+class AuthenticationComponent : public Component
+{
+private:
+ VirtualEndpoint::Ptr m_AuthenticationEndpoint;
+
+ IcingaApplication::Ptr GetIcingaApplication(void) const;
+
+ int NewEndpointHandler(const NewEndpointEventArgs& neea);
+ int IdentityMessageHandler(const NewRequestEventArgs& nrea);
+
+public:
+ virtual string GetName(void) const;
+ virtual void Start(void);
+ virtual void Stop(void);
+};
+
+}
+
+#endif /* AUTHENTICATIONCOMPONENT_H */
#include "icingaapplication.h"
#include "subscriptioncomponent.h"
#include "subscriptionmessage.h"
+#include "authenticationcomponent.h"
#include "identitymessage.h"
#endif /* I2ICINGA_H */
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="authenticationcomponent.cpp" />
<ClCompile Include="endpoint.cpp" />
<ClCompile Include="endpointmanager.cpp" />
<ClCompile Include="icingaapplication.cpp" />
<ClCompile Include="virtualendpoint.cpp" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="authenticationcomponent.h" />
<ClInclude Include="endpoint.h" />
<ClInclude Include="endpointmanager.h" />
<ClInclude Include="i2-icinga.h" />
connectionCollection->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedRpcConnectionHandler, shared_from_this());
- SubscriptionComponent::Ptr subscriptionsComponent = make_shared<SubscriptionComponent>();
- RegisterComponent(subscriptionsComponent);
+ AuthenticationComponent::Ptr authenticationComponent = make_shared<AuthenticationComponent>();
+ RegisterComponent(authenticationComponent);
+
+ SubscriptionComponent::Ptr subscriptionComponent = make_shared<SubscriptionComponent>();
+ RegisterComponent(subscriptionComponent);
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
fileComponentConfig->SetPropertyString("configFilename", args[1]);
client->OnNewMessage += bind_weak(&JsonRpcEndpoint::NewMessageHandler, shared_from_this());
client->OnClosed += bind_weak(&JsonRpcEndpoint::ClientClosedHandler, shared_from_this());
client->OnError += bind_weak(&JsonRpcEndpoint::ClientErrorHandler, shared_from_this());
-
- JsonRpcRequest request;
- request.SetVersion("2.0");
- request.SetMethod("message::SetIdentity");
-
- IdentityMessage params;
- params.SetIdentity("keks");
- request.SetParams(params);
-
- client->SendMessage(request);
}
bool JsonRpcEndpoint::IsLocal(void) const
m_SubscriptionEndpoint = make_shared<VirtualEndpoint>();
m_SubscriptionEndpoint->RegisterMethodHandler("message::Subscribe", bind_weak(&SubscriptionComponent::SubscribeMessageHandler, shared_from_this()));
m_SubscriptionEndpoint->RegisterMethodHandler("message::Provide", bind_weak(&SubscriptionComponent::ProvideMessageHandler, shared_from_this()));
- m_SubscriptionEndpoint->RegisterMethodHandler("message::SetIdentity", bind_weak(&SubscriptionComponent::IdentityMessageHandler, shared_from_this()));
m_SubscriptionEndpoint->RegisterMethodSource("message::Subscribe");
m_SubscriptionEndpoint->RegisterMethodSource("message::Provide");
m_SubscriptionEndpoint->RegisterMethodSource("message::Welcome");
nrea.Sender->RegisterMethodSource(method);
return 0;
}
-
-int SubscriptionComponent::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;
- request.SetVersion("2.0");
- request.SetMethod("message::Welcome");
- nrea.Sender->ProcessRequest(m_SubscriptionEndpoint, request);
-
- return 0;
-}