| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/login/users/affiliation.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 9 #include "google_apis/gaia/gaia_auth_util.h" |
| 10 |
| 11 namespace chromeos { |
| 12 |
| 13 bool HaveCommonElement(const std::set<std::string>& set1, |
| 14 const std::set<std::string>& set2) { |
| 15 std::set<std::string>::const_iterator it1 = set1.begin(); |
| 16 std::set<std::string>::const_iterator it2 = set2.begin(); |
| 17 |
| 18 while (it1 != set1.end() && it2 != set2.end()) { |
| 19 if (*it1 == *it2) |
| 20 return true; |
| 21 if (*it1 < *it2) { |
| 22 ++it1; |
| 23 } else { |
| 24 ++it2; |
| 25 } |
| 26 } |
| 27 return false; |
| 28 } |
| 29 |
| 30 bool IsUserAffiliated(const std::set<std::string>& user_affiliation_ids, |
| 31 const std::set<std::string>& device_affiliation_ids, |
| 32 const std::string& email, |
| 33 const std::string& enterprise_domain) { |
| 34 LOG(ERROR) << "GetUserAffiliation user_name: " << email; |
| 35 LOG(ERROR) << "user_affiliation_ids: " << user_affiliation_ids.size(); |
| 36 LOG(ERROR) << "device_affiliation_ids: " << device_affiliation_ids.size(); |
| 37 |
| 38 if (!device_affiliation_ids.empty() && !user_affiliation_ids.empty()) { |
| 39 LOG(ERROR) << "Device Affiliation IDs:"; |
| 40 for (const std::string& daid : device_affiliation_ids) { |
| 41 LOG(ERROR) << " - " << daid; |
| 42 } |
| 43 LOG(ERROR) << "User Affiliation IDs:"; |
| 44 for (const std::string& uaid : user_affiliation_ids) { |
| 45 LOG(ERROR) << " - " << uaid; |
| 46 } |
| 47 |
| 48 // This ugly construction will be fully removed before commit. |
| 49 if (HaveCommonElement(user_affiliation_ids, device_affiliation_ids)) { |
| 50 LOG(ERROR) << "GetUserAffiliation returns MANAGED, daid = uaid"; |
| 51 } else { |
| 52 LOG(ERROR) << "GetUserAffiliation returns NONE ..." |
| 53 << *(device_affiliation_ids.begin()) << " " |
| 54 << *(user_affiliation_ids.begin()); |
| 55 } |
| 56 |
| 57 return HaveCommonElement(user_affiliation_ids, device_affiliation_ids); |
| 58 } |
| 59 |
| 60 // TODO(peletskyi): Remove the following backwards compatibility part. |
| 61 // An empty username means incognito user in case of ChromiumOS and |
| 62 // no logged-in user in case of Chromium (SigninService). Many tests use |
| 63 // nonsense email addresses (e.g. 'test') so treat those as non-enterprise |
| 64 // users. |
| 65 if (email.empty() || email.find('@') == std::string::npos) { |
| 66 LOG(ERROR) |
| 67 << "GetUserAffiliation returns USER_AFFILIATION_NONE: wrong email"; |
| 68 return false; |
| 69 } |
| 70 |
| 71 if (gaia::ExtractDomainName(gaia::CanonicalizeEmail(email)) == |
| 72 enterprise_domain || |
| 73 policy::IsDeviceLocalAccountUser(email, NULL)) { |
| 74 LOG(ERROR) << "GetUserAffiliation returns MANAGED, email"; |
| 75 return true; |
| 76 } |
| 77 |
| 78 LOG(ERROR) << "GetUserAffiliation returns NONE"; |
| 79 return false; |
| 80 } |
| 81 |
| 82 } // namespace chromeos |
| OLD | NEW |