diff --git a/pulsar-client-cpp/lib/Authentication.cc b/pulsar-client-cpp/lib/Authentication.cc index a65365ef7c30d538123b88c7964a0c7cb36f4063..805d100749fbb71b57dba6993bc866f80a972ae8 100644 --- a/pulsar-client-cpp/lib/Authentication.cc +++ b/pulsar-client-cpp/lib/Authentication.cc @@ -128,19 +128,41 @@ namespace pulsar { } AuthenticationPtr AuthFactory::create(const std::string& dynamicLibPath, const std::string& authParamsString) { - ParamMap paramMap; - if(!authParamsString.empty()) { - std::vector params; - boost::algorithm::split(params, authParamsString, boost::is_any_of(",")); - for(int i = 0; i kv; - boost::algorithm::split(kv, params[i], boost::is_any_of(":")); - if (kv.size() == 2) { - paramMap[kv[0]] = kv[1]; + { + boost::lock_guard lock(mutex); + if (!AuthFactory::isShutdownHookRegistered_) { + atexit(release_handles); + AuthFactory::isShutdownHookRegistered_ = true; + } + } + Authentication *auth = NULL; + void *handle = dlopen(dynamicLibPath.c_str(), RTLD_LAZY); + if (handle != NULL) { + { + boost::lock_guard lock(mutex); + loadedLibrariesHandles_.push_back(handle); + } + Authentication *(*createAuthentication)(const std::string&); + *(void **) (&createAuthentication) = dlsym(handle, "create"); + if (createAuthentication != NULL) { + auth = createAuthentication(authParamsString); + } else { + ParamMap paramMap; + if(!authParamsString.empty()) { + std::vector params; + boost::algorithm::split(params, authParamsString, boost::is_any_of(",")); + for(int i = 0; i kv; + boost::algorithm::split(kv, params[i], boost::is_any_of(":")); + if (kv.size() == 2) { + paramMap[kv[0]] = kv[1]; + } + } } + return AuthFactory::create(dynamicLibPath, paramMap); } } - return AuthFactory::create(dynamicLibPath, paramMap); + return AuthenticationPtr(auth); } AuthenticationPtr AuthFactory::create(const std::string& dynamicLibPath, ParamMap& params) { @@ -157,12 +179,12 @@ namespace pulsar { boost::lock_guard lock(mutex); loadedLibrariesHandles_.push_back(handle); Authentication *(*createAuthentication)(ParamMap&); - *(void **) (&createAuthentication) = dlsym(handle, "create"); + *(void **) (&createAuthentication) = dlsym(handle, "createFromMap"); if (createAuthentication != NULL) { auth = createAuthentication(params); } } - return boost::shared_ptr(auth); + return AuthenticationPtr(auth); } } diff --git a/pulsar-client-cpp/lib/auth/AuthAthenz.cc b/pulsar-client-cpp/lib/auth/AuthAthenz.cc index 5d525bdaceeb6edefbc1a782b30bab5007eb0d1d..4ef3726521770a9729ba354aab4edcf666bd0b70 100644 --- a/pulsar-client-cpp/lib/auth/AuthAthenz.cc +++ b/pulsar-client-cpp/lib/auth/AuthAthenz.cc @@ -85,7 +85,7 @@ namespace pulsar { return ResultOk; } - extern "C" Authentication* create(ParamMap& params) { + extern "C" Authentication* createFromMap(ParamMap& params) { AuthenticationDataPtr authDataAthenz = AuthenticationDataPtr(new AuthDataAthenz(params)); return new AuthAthenz(authDataAthenz); } diff --git a/pulsar-client-cpp/lib/auth/AuthTls.cc b/pulsar-client-cpp/lib/auth/AuthTls.cc index c330ec2144f5779eea0b2b92582ecdffc5739a2f..34ca7a3c6f12c615a4e65c2e2624fa3a546ed8d1 100644 --- a/pulsar-client-cpp/lib/auth/AuthTls.cc +++ b/pulsar-client-cpp/lib/auth/AuthTls.cc @@ -61,7 +61,7 @@ namespace pulsar { return ResultOk; } - extern "C" Authentication* create(ParamMap& params) { + extern "C" Authentication* createFromMap(ParamMap& params) { AuthenticationDataPtr authDataTls = AuthenticationDataPtr(new AuthDataTls(params)); return new AuthTls(authDataTls); }