Commit 67dbff15 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Check the domain before return phone alias

parent 5ede4b95
......@@ -66,6 +66,10 @@ void SociAuthDB::declareConfig(GenericStruct *mc) {
"Example : select login, domain, phone from accounts where phone in (:phones)",
""},
{Boolean, "check-domain-in-presence-results",
"When getting the list of users with phones, if this setting is enabled, it will limit the results to the ones that have the same domain",
"false"},
{Integer, "soci-poolsize",
"Size of the pool of connections that Soci will use. We open a thread for each DB query, and this pool will "
"allow each thread to get a connection.\n"
......@@ -112,6 +116,7 @@ SociAuthDB::SociAuthDB() : conn_pool(NULL) {
get_users_with_phones_request = ma->get<ConfigString>("soci-users-with-phones-request")->read();
unsigned int max_queue_size = (unsigned int)ma->get<ConfigInt>("soci-max-queue-size")->read();
hashed_passwd = ma->get<ConfigBoolean>("hashed-passwords")->read();
check_domain_in_presence_results = ma->get<ConfigBoolean>("check-domain-in-presence-results")->read();
conn_pool = new connection_pool(poolSize);
thread_pool = new ThreadPool(poolSize, max_queue_size);
......@@ -333,10 +338,12 @@ void SociAuthDB::getUsersWithPhonesWithPool(list<tuple<std::string,std::string,A
std::ostringstream in;
session *sql = NULL;
list<std::string> phones;
list<std::string> domains;
bool first = true;
for(tuple<std::string,std::string,AuthDbListener*> cred : creds) {
phones.push_back(std::get<0>(cred));
if(first) {
domains.push_back(std::get<1>(cred));
if (first) {
first = false;
in << "'" << std::get<0>(cred) << "'";
} else {
......@@ -368,13 +375,21 @@ void SociAuthDB::getUsersWithPhonesWithPool(list<tuple<std::string,std::string,A
for (rowset<row>::const_iterator it = ret.begin(); it != ret.end(); ++it) {
row const& row = *it;
string user = row.get<string>(0);
string domain = row.get<string>(1);
string phone = (row.size() > 2) ? row.get<string>(2) : "";
if(phone != "") {
string domain = row.get<string>(1);
cacheUserWithPhone(phone, domain, user);
presences.insert(make_pair(user, phone));
} else {
presences.insert(make_pair(user, user));
bool domain_match = false;
if (check_domain_in_presence_results) {
domain_match = find(domains.begin(), domains.end(), domain) != domains.end();
}
if (!check_domain_in_presence_results || domain_match) {
if (phone != "") {
cacheUserWithPhone(phone, domain, user);
presences.insert(make_pair(user, phone));
} else {
presences.insert(make_pair(user, user));
}
}
}
......
......@@ -217,6 +217,7 @@ private:
std::string get_user_with_phone_request;
std::string get_users_with_phones_request;
std::string get_password_algo_request;
bool check_domain_in_presence_results = false;
bool hashed_passwd;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment