Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6722)

Unified Diff: chrome/browser/chromeos/login/users/affiliation.cc

Issue 1266563002: Added affiliation IDs for the new affiliation determination. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/users/affiliation.cc
diff --git a/chrome/browser/chromeos/login/users/affiliation.cc b/chrome/browser/chromeos/login/users/affiliation.cc
new file mode 100644
index 0000000000000000000000000000000000000000..063f8e78b88de4f61b67f3ccc18e2a0b0350ce17
--- /dev/null
+++ b/chrome/browser/chromeos/login/users/affiliation.cc
@@ -0,0 +1,82 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/login/users/affiliation.h"
+
+#include "base/logging.h"
+#include "chrome/browser/chromeos/policy/device_local_account.h"
+#include "google_apis/gaia/gaia_auth_util.h"
+
+namespace chromeos {
+
+bool HaveCommonElement(const std::set<std::string>& set1,
+ const std::set<std::string>& set2) {
+ std::set<std::string>::const_iterator it1 = set1.begin();
+ std::set<std::string>::const_iterator it2 = set2.begin();
+
+ while (it1 != set1.end() && it2 != set2.end()) {
+ if (*it1 == *it2)
+ return true;
+ if (*it1 < *it2) {
+ ++it1;
+ } else {
+ ++it2;
+ }
+ }
+ return false;
+}
+
+bool IsUserAffiliated(const std::set<std::string>& user_affiliation_ids,
+ const std::set<std::string>& device_affiliation_ids,
+ const std::string& email,
+ const std::string& enterprise_domain) {
+ LOG(ERROR) << "GetUserAffiliation user_name: " << email;
Mattias Nissler (ping if slow) 2015/07/30 12:10:57 All these LOG lines should be removed.
peletskyi 2015/07/30 14:10:57 Done.
+ LOG(ERROR) << "user_affiliation_ids: " << user_affiliation_ids.size();
+ LOG(ERROR) << "device_affiliation_ids: " << device_affiliation_ids.size();
+
+ if (!device_affiliation_ids.empty() && !user_affiliation_ids.empty()) {
+ LOG(ERROR) << "Device Affiliation IDs:";
+ for (const std::string& daid : device_affiliation_ids) {
+ LOG(ERROR) << " - " << daid;
+ }
+ LOG(ERROR) << "User Affiliation IDs:";
+ for (const std::string& uaid : user_affiliation_ids) {
+ LOG(ERROR) << " - " << uaid;
+ }
+
+ // This ugly construction will be fully removed before commit.
+ if (HaveCommonElement(user_affiliation_ids, device_affiliation_ids)) {
+ LOG(ERROR) << "GetUserAffiliation returns MANAGED, daid = uaid";
+ } else {
+ LOG(ERROR) << "GetUserAffiliation returns NONE ..."
+ << *(device_affiliation_ids.begin()) << " "
+ << *(user_affiliation_ids.begin());
+ }
+
+ return HaveCommonElement(user_affiliation_ids, device_affiliation_ids);
+ }
+
+ // TODO(peletskyi): Remove the following backwards compatibility part.
+ // An empty username means incognito user in case of ChromiumOS and
+ // no logged-in user in case of Chromium (SigninService). Many tests use
+ // nonsense email addresses (e.g. 'test') so treat those as non-enterprise
+ // users.
+ if (email.empty() || email.find('@') == std::string::npos) {
+ LOG(ERROR)
+ << "GetUserAffiliation returns USER_AFFILIATION_NONE: wrong email";
+ return false;
+ }
+
+ if (gaia::ExtractDomainName(gaia::CanonicalizeEmail(email)) ==
+ enterprise_domain ||
+ policy::IsDeviceLocalAccountUser(email, NULL)) {
+ LOG(ERROR) << "GetUserAffiliation returns MANAGED, email";
+ return true;
+ }
+
+ LOG(ERROR) << "GetUserAffiliation returns NONE";
+ return false;
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698