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

Side by Side Diff: remoting/protocol/validating_authenticator.cc

Issue 2724223003: Disconnect all users if too many connection requests are received for It2Me (Closed)
Patch Set: Addressing feedback Created 3 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "remoting/protocol/validating_authenticator.h" 5 #include "remoting/protocol/validating_authenticator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 12 matching lines...) Expand all
23 23
24 ValidatingAuthenticator::ValidatingAuthenticator( 24 ValidatingAuthenticator::ValidatingAuthenticator(
25 const std::string& remote_jid, 25 const std::string& remote_jid,
26 const ValidationCallback& validation_callback, 26 const ValidationCallback& validation_callback,
27 std::unique_ptr<Authenticator> current_authenticator) 27 std::unique_ptr<Authenticator> current_authenticator)
28 : remote_jid_(remote_jid), 28 : remote_jid_(remote_jid),
29 validation_callback_(validation_callback), 29 validation_callback_(validation_callback),
30 current_authenticator_(std::move(current_authenticator)), 30 current_authenticator_(std::move(current_authenticator)),
31 weak_factory_(this) { 31 weak_factory_(this) {
32 DCHECK(!remote_jid_.empty()); 32 DCHECK(!remote_jid_.empty());
33 DCHECK(!validation_callback_.is_null()); 33 DCHECK(validation_callback_);
34 DCHECK(current_authenticator_); 34 DCHECK(current_authenticator_);
35 } 35 }
36 36
37 ValidatingAuthenticator::~ValidatingAuthenticator() {} 37 ValidatingAuthenticator::~ValidatingAuthenticator() {}
38 38
39 Authenticator::State ValidatingAuthenticator::state() const { 39 Authenticator::State ValidatingAuthenticator::state() const {
40 return state_; 40 return pending_auth_message_ ? MESSAGE_READY : state_;
41 } 41 }
42 42
43 bool ValidatingAuthenticator::started() const { 43 bool ValidatingAuthenticator::started() const {
44 return current_authenticator_->started(); 44 return current_authenticator_->started();
45 } 45 }
46 46
47 Authenticator::RejectionReason ValidatingAuthenticator::rejection_reason() 47 Authenticator::RejectionReason ValidatingAuthenticator::rejection_reason()
48 const { 48 const {
49 return rejection_reason_; 49 return rejection_reason_;
50 } 50 }
51 51
52 const std::string& ValidatingAuthenticator::GetAuthKey() const { 52 const std::string& ValidatingAuthenticator::GetAuthKey() const {
53 return current_authenticator_->GetAuthKey(); 53 return current_authenticator_->GetAuthKey();
54 } 54 }
55 55
56 std::unique_ptr<ChannelAuthenticator> 56 std::unique_ptr<ChannelAuthenticator>
57 ValidatingAuthenticator::CreateChannelAuthenticator() const { 57 ValidatingAuthenticator::CreateChannelAuthenticator() const {
58 return current_authenticator_->CreateChannelAuthenticator(); 58 return current_authenticator_->CreateChannelAuthenticator();
59 } 59 }
60 60
61 void ValidatingAuthenticator::ProcessMessage( 61 void ValidatingAuthenticator::ProcessMessage(
62 const buzz::XmlElement* message, 62 const buzz::XmlElement* message,
63 const base::Closure& resume_callback) { 63 const base::Closure& resume_callback) {
64 DCHECK_EQ(state_, WAITING_MESSAGE); 64 DCHECK_EQ(state_, WAITING_MESSAGE);
65 state_ = PROCESSING_MESSAGE; 65 state_ = PROCESSING_MESSAGE;
66 66
67 if (first_message_received_) { 67 current_authenticator_->ProcessMessage(
68 current_authenticator_->ProcessMessage( 68 message, base::Bind(&ValidatingAuthenticator::UpdateState,
69 message, base::Bind(&ValidatingAuthenticator::UpdateState, 69 weak_factory_.GetWeakPtr(), resume_callback));
70 weak_factory_.GetWeakPtr(), resume_callback));
71 } else {
72 first_message_received_ = true;
73 validation_callback_.Run(
74 remote_jid_, base::Bind(&ValidatingAuthenticator::OnValidateComplete,
75 weak_factory_.GetWeakPtr(),
76 base::Owned(new buzz::XmlElement(*message)),
77 resume_callback));
78 }
79 } 70 }
80 71
81 std::unique_ptr<buzz::XmlElement> ValidatingAuthenticator::GetNextMessage() { 72 std::unique_ptr<buzz::XmlElement> ValidatingAuthenticator::GetNextMessage() {
73 if (pending_auth_message_) {
74 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE);
75 return std::move(pending_auth_message_);
76 }
77
82 std::unique_ptr<buzz::XmlElement> result( 78 std::unique_ptr<buzz::XmlElement> result(
83 current_authenticator_->GetNextMessage()); 79 current_authenticator_->GetNextMessage());
84 state_ = current_authenticator_->state(); 80 state_ = current_authenticator_->state();
85 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE); 81 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE);
86 82
87 return result; 83 return result;
88 } 84 }
89 85
90 void ValidatingAuthenticator::OnValidateComplete( 86 void ValidatingAuthenticator::OnValidateComplete(const base::Closure& callback,
91 const buzz::XmlElement* message, 87 Result validation_result) {
92 const base::Closure& resume_callback, 88 // Map |rejection_reason_| to a known reason, set |state_| to REJECTED and
93 Result validation_result) { 89 // notify the listener of the connection error via the callback.
94 // Process the original message in the success case, otherwise map
95 // |rejection_reason_| to a known reason, set |state_| to REJECTED and notify
96 // the listener of the connection error via the callback.
97 switch (validation_result) { 90 switch (validation_result) {
98 case Result::SUCCESS: 91 case Result::SUCCESS:
99 current_authenticator_->ProcessMessage( 92 callback.Run();
100 message, base::Bind(&ValidatingAuthenticator::UpdateState,
101 weak_factory_.GetWeakPtr(), resume_callback));
102 return; 93 return;
103 94
104 case Result::ERROR_INVALID_CREDENTIALS: 95 case Result::ERROR_INVALID_CREDENTIALS:
105 rejection_reason_ = Authenticator::INVALID_CREDENTIALS; 96 rejection_reason_ = Authenticator::INVALID_CREDENTIALS;
106 break; 97 break;
107 98
108 case Result::ERROR_INVALID_ACCOUNT: 99 case Result::ERROR_INVALID_ACCOUNT:
109 rejection_reason_ = Authenticator::INVALID_ACCOUNT; 100 rejection_reason_ = Authenticator::INVALID_ACCOUNT;
110 break; 101 break;
111 102
103 case Result::ERROR_TOO_MANY_CONNECTIONS:
104 rejection_reason_ = Authenticator::TOO_MANY_CONNECTIONS;
105 break;
106
112 case Result::ERROR_REJECTED_BY_USER: 107 case Result::ERROR_REJECTED_BY_USER:
113 rejection_reason_ = Authenticator::REJECTED_BY_USER; 108 rejection_reason_ = Authenticator::REJECTED_BY_USER;
114 break; 109 break;
115 } 110 }
116 111
117 state_ = Authenticator::REJECTED; 112 state_ = Authenticator::REJECTED;
118 resume_callback.Run(); 113 callback.Run();
119 } 114 }
120 115
121 void ValidatingAuthenticator::UpdateState( 116 void ValidatingAuthenticator::UpdateState(
122 const base::Closure& resume_callback) { 117 const base::Closure& resume_callback) {
123 DCHECK_EQ(state_, PROCESSING_MESSAGE); 118 DCHECK_EQ(state_, PROCESSING_MESSAGE);
124 119
125 // Update our current state before running |resume_callback|. 120 // Update our current state before running |resume_callback|.
126 state_ = current_authenticator_->state(); 121 state_ = current_authenticator_->state();
127 if (state_ == REJECTED) { 122 if (state_ == REJECTED) {
128 rejection_reason_ = current_authenticator_->rejection_reason(); 123 rejection_reason_ = current_authenticator_->rejection_reason();
124 } else if (state_ == MESSAGE_READY) {
125 DCHECK(!pending_auth_message_);
126 pending_auth_message_ = current_authenticator_->GetNextMessage();
127 state_ = current_authenticator_->state();
129 } 128 }
130 129
131 resume_callback.Run(); 130 if (state_ == ACCEPTED) {
131 validation_callback_.Run(
Sergey Ulanov 2017/03/17 21:11:28 I think we want to stay in PROCESSING_MESSAGE stat
joedow 2017/03/20 15:09:06 That makes sense, good suggestion!
132 remote_jid_, base::Bind(&ValidatingAuthenticator::OnValidateComplete,
133 weak_factory_.GetWeakPtr(), resume_callback));
134 } else {
135 resume_callback.Run();
136 }
132 } 137 }
133 138
134 } // namespace protocol 139 } // namespace protocol
135 } // namespace remoting 140 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/validating_authenticator.h ('k') | remoting/protocol/validating_authenticator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698