| 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/auth/user_context.h" | 5 #include "chrome/browser/chromeos/login/auth/user_context.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/login/helper.h" | 7 #include "chrome/browser/chromeos/login/helper.h" |
| 8 #include "chrome/browser/chromeos/login/users/user_manager.h" | 8 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 9 | 9 |
| 10 namespace chromeos { | 10 namespace chromeos { |
| 11 | 11 |
| 12 UserContext::UserContext() : does_need_password_hashing_(true), | 12 UserContext::UserContext() : is_using_oauth_(true), |
| 13 is_using_oauth_(true), | |
| 14 auth_flow_(AUTH_FLOW_OFFLINE) { | 13 auth_flow_(AUTH_FLOW_OFFLINE) { |
| 15 } | 14 } |
| 16 | 15 |
| 17 UserContext::UserContext(const UserContext& other) | 16 UserContext::UserContext(const UserContext& other) |
| 18 : user_id_(other.user_id_), | 17 : user_id_(other.user_id_), |
| 19 password_(other.password_), | 18 key_(other.key_), |
| 20 does_need_password_hashing_(other.does_need_password_hashing_), | |
| 21 key_label_(other.key_label_), | |
| 22 auth_code_(other.auth_code_), | 19 auth_code_(other.auth_code_), |
| 23 user_id_hash_(other.user_id_hash_), | 20 user_id_hash_(other.user_id_hash_), |
| 24 is_using_oauth_(other.is_using_oauth_), | 21 is_using_oauth_(other.is_using_oauth_), |
| 25 auth_flow_(other.auth_flow_) { | 22 auth_flow_(other.auth_flow_) { |
| 26 } | 23 } |
| 27 | 24 |
| 28 UserContext::UserContext(const std::string& user_id) | 25 UserContext::UserContext(const std::string& user_id) |
| 29 : user_id_(login::CanonicalizeUserID(user_id)), | 26 : user_id_(login::CanonicalizeUserID(user_id)), |
| 30 does_need_password_hashing_(true), | |
| 31 is_using_oauth_(true), | 27 is_using_oauth_(true), |
| 32 auth_flow_(AUTH_FLOW_OFFLINE) { | 28 auth_flow_(AUTH_FLOW_OFFLINE) { |
| 33 } | 29 } |
| 34 | 30 |
| 35 UserContext::~UserContext() { | 31 UserContext::~UserContext() { |
| 36 } | 32 } |
| 37 | 33 |
| 38 bool UserContext::operator==(const UserContext& context) const { | 34 bool UserContext::operator==(const UserContext& context) const { |
| 39 return context.user_id_ == user_id_ && | 35 return context.user_id_ == user_id_ && |
| 40 context.password_ == password_ && | 36 context.key_ == key_ && |
| 41 context.does_need_password_hashing_ == does_need_password_hashing_ && | |
| 42 context.key_label_ == key_label_ && | |
| 43 context.auth_code_ == auth_code_ && | 37 context.auth_code_ == auth_code_ && |
| 44 context.user_id_hash_ == user_id_hash_ && | 38 context.user_id_hash_ == user_id_hash_ && |
| 45 context.is_using_oauth_ == is_using_oauth_ && | 39 context.is_using_oauth_ == is_using_oauth_ && |
| 46 context.auth_flow_ == auth_flow_; | 40 context.auth_flow_ == auth_flow_; |
| 47 } | 41 } |
| 48 | 42 |
| 43 bool UserContext::operator!=(const UserContext& context) const { |
| 44 return !(*this == context); |
| 45 } |
| 46 |
| 49 const std::string& UserContext::GetUserID() const { | 47 const std::string& UserContext::GetUserID() const { |
| 50 return user_id_; | 48 return user_id_; |
| 51 } | 49 } |
| 52 | 50 |
| 53 const std::string& UserContext::GetPassword() const { | 51 const Key* UserContext::GetKey() const { |
| 54 return password_; | 52 return &key_; |
| 55 } | 53 } |
| 56 | 54 |
| 57 bool UserContext::DoesNeedPasswordHashing() const { | 55 Key* UserContext::GetKey() { |
| 58 return does_need_password_hashing_; | 56 return &key_; |
| 59 } | |
| 60 | |
| 61 const std::string& UserContext::GetKeyLabel() const { | |
| 62 return key_label_; | |
| 63 } | 57 } |
| 64 | 58 |
| 65 const std::string& UserContext::GetAuthCode() const { | 59 const std::string& UserContext::GetAuthCode() const { |
| 66 return auth_code_; | 60 return auth_code_; |
| 67 } | 61 } |
| 68 | 62 |
| 69 const std::string& UserContext::GetUserIDHash() const { | 63 const std::string& UserContext::GetUserIDHash() const { |
| 70 return user_id_hash_; | 64 return user_id_hash_; |
| 71 } | 65 } |
| 72 | 66 |
| 73 bool UserContext::IsUsingOAuth() const { | 67 bool UserContext::IsUsingOAuth() const { |
| 74 return is_using_oauth_; | 68 return is_using_oauth_; |
| 75 } | 69 } |
| 76 | 70 |
| 77 UserContext::AuthFlow UserContext::GetAuthFlow() const { | 71 UserContext::AuthFlow UserContext::GetAuthFlow() const { |
| 78 return auth_flow_; | 72 return auth_flow_; |
| 79 } | 73 } |
| 80 | 74 |
| 81 bool UserContext::HasCredentials() const { | 75 bool UserContext::HasCredentials() const { |
| 82 return (!user_id_.empty() && !password_.empty()) || !auth_code_.empty(); | 76 return (!user_id_.empty() && !key_.GetSecret().empty()) || |
| 77 !auth_code_.empty(); |
| 83 } | 78 } |
| 84 | 79 |
| 85 void UserContext::SetUserID(const std::string& user_id) { | 80 void UserContext::SetUserID(const std::string& user_id) { |
| 86 user_id_ = login::CanonicalizeUserID(user_id); | 81 user_id_ = login::CanonicalizeUserID(user_id); |
| 87 } | 82 } |
| 88 | 83 |
| 89 void UserContext::SetPassword(const std::string& password) { | 84 void UserContext::SetKey(const Key& key) { |
| 90 password_ = password; | 85 key_ = key; |
| 91 } | |
| 92 | |
| 93 void UserContext::SetDoesNeedPasswordHashing(bool does_need_password_hashing) { | |
| 94 does_need_password_hashing_ = does_need_password_hashing; | |
| 95 } | |
| 96 | |
| 97 void UserContext::SetKeyLabel(const std::string& key_label) { | |
| 98 key_label_ = key_label; | |
| 99 } | 86 } |
| 100 | 87 |
| 101 void UserContext::SetAuthCode(const std::string& auth_code) { | 88 void UserContext::SetAuthCode(const std::string& auth_code) { |
| 102 auth_code_ = auth_code; | 89 auth_code_ = auth_code; |
| 103 } | 90 } |
| 104 | 91 |
| 105 void UserContext::SetUserIDHash(const std::string& user_id_hash) { | 92 void UserContext::SetUserIDHash(const std::string& user_id_hash) { |
| 106 user_id_hash_ = user_id_hash; | 93 user_id_hash_ = user_id_hash; |
| 107 } | 94 } |
| 108 | 95 |
| 109 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { | 96 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { |
| 110 is_using_oauth_ = is_using_oauth; | 97 is_using_oauth_ = is_using_oauth; |
| 111 } | 98 } |
| 112 | 99 |
| 113 void UserContext::SetAuthFlow(AuthFlow auth_flow) { | 100 void UserContext::SetAuthFlow(AuthFlow auth_flow) { |
| 114 auth_flow_ = auth_flow; | 101 auth_flow_ = auth_flow; |
| 115 } | 102 } |
| 116 | 103 |
| 117 void UserContext::ClearSecrets() { | 104 void UserContext::ClearSecrets() { |
| 118 password_.clear(); | 105 key_.ClearSecret(); |
| 119 auth_code_.clear(); | 106 auth_code_.clear(); |
| 120 } | 107 } |
| 121 | 108 |
| 122 } // namespace chromeos | 109 } // namespace chromeos |
| OLD | NEW |