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

Side by Side Diff: chromeos/network/managed_network_configuration_handler.cc

Issue 22327005: Automatically resolve ClientCertificatePatterns. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed yet another issue with CertLoader. Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/network/managed_network_configuration_handler.h" 5 #include "chromeos/network/managed_network_configuration_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chromeos/dbus/dbus_method_call_status.h" 20 #include "chromeos/dbus/dbus_method_call_status.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/dbus/shill_manager_client.h" 22 #include "chromeos/dbus/shill_manager_client.h"
23 #include "chromeos/dbus/shill_profile_client.h" 23 #include "chromeos/dbus/shill_profile_client.h"
24 #include "chromeos/dbus/shill_service_client.h" 24 #include "chromeos/dbus/shill_service_client.h"
25 #include "chromeos/network/network_configuration_handler.h" 25 #include "chromeos/network/network_configuration_handler.h"
26 #include "chromeos/network/network_event_log.h" 26 #include "chromeos/network/network_event_log.h"
27 #include "chromeos/network/network_handler_callbacks.h" 27 #include "chromeos/network/network_handler_callbacks.h"
28 #include "chromeos/network/network_policy_observer.h"
28 #include "chromeos/network/network_profile.h" 29 #include "chromeos/network/network_profile.h"
29 #include "chromeos/network/network_profile_handler.h" 30 #include "chromeos/network/network_profile_handler.h"
30 #include "chromeos/network/network_state.h" 31 #include "chromeos/network/network_state.h"
31 #include "chromeos/network/network_state_handler.h" 32 #include "chromeos/network/network_state_handler.h"
32 #include "chromeos/network/network_ui_data.h" 33 #include "chromeos/network/network_ui_data.h"
33 #include "chromeos/network/onc/onc_constants.h" 34 #include "chromeos/network/onc/onc_constants.h"
34 #include "chromeos/network/onc/onc_merger.h" 35 #include "chromeos/network/onc/onc_merger.h"
35 #include "chromeos/network/onc/onc_normalizer.h" 36 #include "chromeos/network/onc/onc_normalizer.h"
36 #include "chromeos/network/onc/onc_signature.h" 37 #include "chromeos/network/onc/onc_signature.h"
37 #include "chromeos/network/onc/onc_translator.h" 38 #include "chromeos/network/onc/onc_translator.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void SetUIData(const NetworkUIData& ui_data, 92 void SetUIData(const NetworkUIData& ui_data,
92 base::DictionaryValue* shill_dictionary) { 93 base::DictionaryValue* shill_dictionary) {
93 base::DictionaryValue ui_data_dict; 94 base::DictionaryValue ui_data_dict;
94 ui_data.FillDictionary(&ui_data_dict); 95 ui_data.FillDictionary(&ui_data_dict);
95 std::string ui_data_blob; 96 std::string ui_data_blob;
96 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); 97 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob);
97 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, 98 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty,
98 ui_data_blob); 99 ui_data_blob);
99 } 100 }
100 101
101 // A dummy callback to ignore the result of Shill calls.
102 void IgnoreString(const std::string& str) {
103 }
104
105 void LogErrorWithDict(const tracked_objects::Location& from_where, 102 void LogErrorWithDict(const tracked_objects::Location& from_where,
106 const std::string& error_name, 103 const std::string& error_name,
107 scoped_ptr<base::DictionaryValue> error_data) { 104 scoped_ptr<base::DictionaryValue> error_data) {
108 LOG(ERROR) << from_where.ToString() << ": " << error_name; 105 LOG(ERROR) << from_where.ToString() << ": " << error_name;
109 } 106 }
110 107
111 void LogErrorMessage(const tracked_objects::Location& from_where, 108 void LogErrorMessage(const tracked_objects::Location& from_where,
112 const std::string& error_name, 109 const std::string& error_name,
113 const std::string& error_message) { 110 const std::string& error_message) {
114 LOG(ERROR) << from_where.ToString() << ": " << error_message; 111 LOG(ERROR) << from_where.ToString() << ": " << error_message;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 onc::ReadDictionaryFromJson(ui_data_blob); 364 onc::ReadDictionaryFromJson(ui_data_blob);
368 if (ui_data_dict) 365 if (ui_data_dict)
369 return make_scoped_ptr(new NetworkUIData(*ui_data_dict)); 366 return make_scoped_ptr(new NetworkUIData(*ui_data_dict));
370 else 367 else
371 LOG(ERROR) << "UIData is not a valid JSON dictionary."; 368 LOG(ERROR) << "UIData is not a valid JSON dictionary.";
372 } 369 }
373 VLOG(2) << "JSON dictionary has no UIData blob: " << shill_dictionary; 370 VLOG(2) << "JSON dictionary has no UIData blob: " << shill_dictionary;
374 return scoped_ptr<NetworkUIData>(); 371 return scoped_ptr<NetworkUIData>();
375 } 372 }
376 373
374 void ManagedNetworkConfigurationHandler::AddObserver(
375 NetworkPolicyObserver* observer) {
376 observers_.AddObserver(observer);
377 }
378
379 void ManagedNetworkConfigurationHandler::RemoveObserver(
380 NetworkPolicyObserver* observer) {
381 observers_.RemoveObserver(observer);
382 }
383
377 void ManagedNetworkConfigurationHandler::GetManagedProperties( 384 void ManagedNetworkConfigurationHandler::GetManagedProperties(
378 const std::string& userhash, 385 const std::string& userhash,
379 const std::string& service_path, 386 const std::string& service_path,
380 const network_handler::DictionaryResultCallback& callback, 387 const network_handler::DictionaryResultCallback& callback,
381 const network_handler::ErrorCallback& error_callback) { 388 const network_handler::ErrorCallback& error_callback) {
382 if (!GetPoliciesForUser(userhash) || !GetPoliciesForUser(std::string())) { 389 if (!GetPoliciesForUser(userhash) || !GetPoliciesForUser(std::string())) {
383 RunErrorCallback(service_path, 390 RunErrorCallback(service_path,
384 kPoliciesNotInitialized, 391 kPoliciesNotInitialized,
385 kPoliciesNotInitializedMessage, 392 kPoliciesNotInitializedMessage,
386 error_callback); 393 error_callback);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 GuidToPolicyMap::const_iterator found = device_policies->find(guid); 734 GuidToPolicyMap::const_iterator found = device_policies->find(guid);
728 if (found != device_policies->end()) { 735 if (found != device_policies->end()) {
729 *onc_source = onc::ONC_SOURCE_DEVICE_POLICY; 736 *onc_source = onc::ONC_SOURCE_DEVICE_POLICY;
730 return found->second; 737 return found->second;
731 } 738 }
732 } 739 }
733 740
734 return NULL; 741 return NULL;
735 } 742 }
736 743
744 const base::DictionaryValue*
745 ManagedNetworkConfigurationHandler::FindPolicyByGuidAndProfile(
746 const std::string& guid,
747 const std::string& profile_path) const {
748 const NetworkProfile* profile =
749 network_profile_handler_->GetProfileForPath(profile_path);
750 if (!profile) {
751 LOG(ERROR) << "Profile path unknown: " << profile_path;
752 return NULL;
753 }
754
755 const GuidToPolicyMap* policies = GetPoliciesForProfile(*profile);
756 if (!policies)
757 return NULL;
758
759 GuidToPolicyMap::const_iterator it = policies->find(guid);
760 if (it == policies->end())
761 return NULL;
762 return it->second;
763 }
764
737 void ManagedNetworkConfigurationHandler::OnProfileRemoved( 765 void ManagedNetworkConfigurationHandler::OnProfileRemoved(
738 const NetworkProfile& profile) { 766 const NetworkProfile& profile) {
739 // Nothing to do in this case. 767 // Nothing to do in this case.
740 } 768 }
741 769
742 const ManagedNetworkConfigurationHandler::GuidToPolicyMap* 770 const ManagedNetworkConfigurationHandler::GuidToPolicyMap*
743 ManagedNetworkConfigurationHandler::GetPoliciesForUser( 771 ManagedNetworkConfigurationHandler::GetPoliciesForUser(
744 const std::string& userhash) const { 772 const std::string& userhash) const {
745 UserToPoliciesMap::const_iterator it = policies_by_user_.find(userhash); 773 UserToPoliciesMap::const_iterator it = policies_by_user_.find(userhash);
746 if (it == policies_by_user_.end()) 774 if (it == policies_by_user_.end())
(...skipping 27 matching lines...) Expand all
774 void ManagedNetworkConfigurationHandler::Init( 802 void ManagedNetworkConfigurationHandler::Init(
775 NetworkStateHandler* network_state_handler, 803 NetworkStateHandler* network_state_handler,
776 NetworkProfileHandler* network_profile_handler, 804 NetworkProfileHandler* network_profile_handler,
777 NetworkConfigurationHandler* network_configuration_handler) { 805 NetworkConfigurationHandler* network_configuration_handler) {
778 network_state_handler_ = network_state_handler; 806 network_state_handler_ = network_state_handler;
779 network_profile_handler_ = network_profile_handler; 807 network_profile_handler_ = network_profile_handler;
780 network_configuration_handler_ = network_configuration_handler; 808 network_configuration_handler_ = network_configuration_handler;
781 network_profile_handler_->AddObserver(this); 809 network_profile_handler_->AddObserver(this);
782 } 810 }
783 811
812 void ManagedNetworkConfigurationHandler::OnPolicyApplied(
813 const std::string& service_path) {
814 if (service_path.empty())
815 return;
816 FOR_EACH_OBSERVER(
817 NetworkPolicyObserver, observers_, PolicyApplied(service_path));
818 }
819
784 ManagedNetworkConfigurationHandler::PolicyApplicator::PolicyApplicator( 820 ManagedNetworkConfigurationHandler::PolicyApplicator::PolicyApplicator(
785 base::WeakPtr<ManagedNetworkConfigurationHandler> handler, 821 base::WeakPtr<ManagedNetworkConfigurationHandler> handler,
786 const NetworkProfile& profile, 822 const NetworkProfile& profile,
787 std::set<std::string>* modified_policies) 823 std::set<std::string>* modified_policies)
788 : handler_(handler), profile_(profile) { 824 : handler_(handler), profile_(profile) {
789 remaining_policies_.swap(*modified_policies); 825 remaining_policies_.swap(*modified_policies);
790 } 826 }
791 827
792 void ManagedNetworkConfigurationHandler::PolicyApplicator::Run() { 828 void ManagedNetworkConfigurationHandler::PolicyApplicator::Run() {
793 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( 829 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 DeleteEntry(entry); 950 DeleteEntry(entry);
915 } 951 }
916 952
917 const base::DictionaryValue* user_settings = 953 const base::DictionaryValue* user_settings =
918 ui_data ? ui_data->user_settings() : NULL; 954 ui_data ? ui_data->user_settings() : NULL;
919 955
920 // Write the new configuration. 956 // Write the new configuration.
921 scoped_ptr<base::DictionaryValue> shill_dictionary = 957 scoped_ptr<base::DictionaryValue> shill_dictionary =
922 CreateShillConfiguration( 958 CreateShillConfiguration(
923 profile_, new_guid, new_policy, user_settings); 959 profile_, new_guid, new_policy, user_settings);
924 handler_->network_configuration_handler() 960 handler_->network_configuration_handler()->CreateConfiguration(
925 ->CreateConfiguration(*shill_dictionary, 961 *shill_dictionary,
926 base::Bind(&IgnoreString), 962 base::Bind(&ManagedNetworkConfigurationHandler::OnPolicyApplied,
927 base::Bind(&LogErrorWithDict, FROM_HERE)); 963 handler_),
964 base::Bind(&LogErrorWithDict, FROM_HERE));
928 remaining_policies_.erase(new_guid); 965 remaining_policies_.erase(new_guid);
929 } 966 }
930 } else if (was_managed) { 967 } else if (was_managed) {
931 VLOG(1) << "Removing configuration previously managed by policy " 968 VLOG(1) << "Removing configuration previously managed by policy "
932 << old_guid << ", because the policy was removed."; 969 << old_guid << ", because the policy was removed.";
933 970
934 // Remove the entry, because the network was managed but isn't anymore. 971 // Remove the entry, because the network was managed but isn't anymore.
935 // Note: An alternative might be to preserve the user settings, but it's 972 // Note: An alternative might be to preserve the user settings, but it's
936 // unclear which values originating the policy should be removed. 973 // unclear which values originating the policy should be removed.
937 DeleteEntry(entry); 974 DeleteEntry(entry);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 LOG(ERROR) << "Policy " << *it << " doesn't exist anymore."; 1017 LOG(ERROR) << "Policy " << *it << " doesn't exist anymore.";
981 continue; 1018 continue;
982 } 1019 }
983 1020
984 VLOG(1) << "Creating new configuration managed by policy " << *it 1021 VLOG(1) << "Creating new configuration managed by policy " << *it
985 << " in profile " << profile_.ToDebugString() << "."; 1022 << " in profile " << profile_.ToDebugString() << ".";
986 1023
987 scoped_ptr<base::DictionaryValue> shill_dictionary = 1024 scoped_ptr<base::DictionaryValue> shill_dictionary =
988 CreateShillConfiguration( 1025 CreateShillConfiguration(
989 profile_, *it, policy, NULL /* no user settings */); 1026 profile_, *it, policy, NULL /* no user settings */);
990 handler_->network_configuration_handler() 1027 handler_->network_configuration_handler()->CreateConfiguration(
991 ->CreateConfiguration(*shill_dictionary, 1028 *shill_dictionary,
992 base::Bind(&IgnoreString), 1029 base::Bind(&ManagedNetworkConfigurationHandler::OnPolicyApplied,
993 base::Bind(&LogErrorWithDict, FROM_HERE)); 1030 handler_),
1031 base::Bind(&LogErrorWithDict, FROM_HERE));
994 } 1032 }
995 } 1033 }
996 1034
997 } // namespace chromeos 1035 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698