| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" | 5 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/time/clock.h" | 14 #include "base/time/clock.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "components/user_manager/user.h" | 20 #include "components/user_manager/user.h" |
| 21 #include "components/user_manager/user_manager.h" |
| 22 | 22 |
| 23 namespace chromeos { | 23 namespace chromeos { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const int kDefaultSAMLOfflineSigninTimeLimit = 14 * 24 * 60 * 60; // 14 days. | 27 const int kDefaultSAMLOfflineSigninTimeLimit = 14 * 24 * 60 * 60; // 14 days. |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 // static | 31 // static |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 NOTREACHED(); | 49 NOTREACHED(); |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 const std::string& user_id = user->email(); | 52 const std::string& user_id = user->email(); |
| 53 | 53 |
| 54 if (auth_flow == UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML) { | 54 if (auth_flow == UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML) { |
| 55 // The user went through online authentication and GAIA did not redirect to | 55 // The user went through online authentication and GAIA did not redirect to |
| 56 // a SAML IdP. No limit applies in this case. Clear the time of last login | 56 // a SAML IdP. No limit applies in this case. Clear the time of last login |
| 57 // with SAML and the flag enforcing online login, then return. | 57 // with SAML and the flag enforcing online login, then return. |
| 58 prefs->ClearPref(prefs::kSAMLLastGAIASignInTime); | 58 prefs->ClearPref(prefs::kSAMLLastGAIASignInTime); |
| 59 UserManager::Get()->SaveForceOnlineSignin(user_id, false); | 59 user_manager::UserManager::Get()->SaveForceOnlineSignin(user_id, false); |
| 60 return; | 60 return; |
| 61 } | 61 } |
| 62 | 62 |
| 63 if (auth_flow == UserContext::AUTH_FLOW_GAIA_WITH_SAML) { | 63 if (auth_flow == UserContext::AUTH_FLOW_GAIA_WITH_SAML) { |
| 64 // The user went through online authentication and GAIA did redirect to a | 64 // The user went through online authentication and GAIA did redirect to a |
| 65 // SAML IdP. Update the time of last login with SAML and clear the flag | 65 // SAML IdP. Update the time of last login with SAML and clear the flag |
| 66 // enforcing online login. The flag will be set again when the limit | 66 // enforcing online login. The flag will be set again when the limit |
| 67 // expires. If the limit already expired (e.g. because it was set to zero), | 67 // expires. If the limit already expired (e.g. because it was set to zero), |
| 68 // the flag will be set again immediately. | 68 // the flag will be set again immediately. |
| 69 UserManager::Get()->SaveForceOnlineSignin(user_id, false); | 69 user_manager::UserManager::Get()->SaveForceOnlineSignin(user_id, false); |
| 70 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, | 70 prefs->SetInt64(prefs::kSAMLLastGAIASignInTime, |
| 71 clock_->Now().ToInternalValue()); | 71 clock_->Now().ToInternalValue()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Start listening for pref changes. | 74 // Start listening for pref changes. |
| 75 pref_change_registrar_.Init(prefs); | 75 pref_change_registrar_.Init(prefs); |
| 76 pref_change_registrar_.Add(prefs::kSAMLOfflineSigninTimeLimit, | 76 pref_change_registrar_.Add(prefs::kSAMLOfflineSigninTimeLimit, |
| 77 base::Bind(&SAMLOfflineSigninLimiter::UpdateLimit, | 77 base::Bind(&SAMLOfflineSigninLimiter::UpdateLimit, |
| 78 base::Unretained(this))); | 78 base::Unretained(this))); |
| 79 | 79 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 &SAMLOfflineSigninLimiter::ForceOnlineLogin); | 140 &SAMLOfflineSigninLimiter::ForceOnlineLogin); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void SAMLOfflineSigninLimiter::ForceOnlineLogin() { | 143 void SAMLOfflineSigninLimiter::ForceOnlineLogin() { |
| 144 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile_); | 144 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile_); |
| 145 if (!user) { | 145 if (!user) { |
| 146 NOTREACHED(); | 146 NOTREACHED(); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 | 149 |
| 150 UserManager::Get()->SaveForceOnlineSignin(user->email(), true); | 150 user_manager::UserManager::Get()->SaveForceOnlineSignin(user->email(), true); |
| 151 offline_signin_limit_timer_.reset(); | 151 offline_signin_limit_timer_.reset(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace chromeos | 154 } // namespace chromeos |
| OLD | NEW |