Skip to content

Commit

Permalink
Modify AuthFactory for C++ Client to enable each plugin to parse auth…
Browse files Browse the repository at this point in the history
…PramsString (apache#792)
  • Loading branch information
yush1ga authored and merlimat committed Oct 20, 2017
1 parent 4288839 commit 79ecb72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
46 changes: 34 additions & 12 deletions pulsar-client-cpp/lib/Authentication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,41 @@ namespace pulsar {
}

AuthenticationPtr AuthFactory::create(const std::string& dynamicLibPath, const std::string& authParamsString) {
ParamMap paramMap;
if(!authParamsString.empty()) {
std::vector<std::string> params;
boost::algorithm::split(params, authParamsString, boost::is_any_of(","));
for(int i = 0; i<params.size(); i++) {
std::vector<std::string> kv;
boost::algorithm::split(kv, params[i], boost::is_any_of(":"));
if (kv.size() == 2) {
paramMap[kv[0]] = kv[1];
{
boost::lock_guard<boost::mutex> 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<boost::mutex> 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<std::string> params;
boost::algorithm::split(params, authParamsString, boost::is_any_of(","));
for(int i = 0; i<params.size(); i++) {
std::vector<std::string> 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) {
Expand All @@ -157,12 +179,12 @@ namespace pulsar {
boost::lock_guard<boost::mutex> 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<Authentication>(auth);
return AuthenticationPtr(auth);
}

}
2 changes: 1 addition & 1 deletion pulsar-client-cpp/lib/auth/AuthAthenz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion pulsar-client-cpp/lib/auth/AuthTls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 79ecb72

Please sign in to comment.