OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/jingle_glue/xmpp_signal_strategy.h" | 5 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" | 10 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 void XmppSignalStrategy::SetResourceName(const std::string &resource_name) { | 160 void XmppSignalStrategy::SetResourceName(const std::string &resource_name) { |
161 DCHECK(CalledOnValidThread()); | 161 DCHECK(CalledOnValidThread()); |
162 resource_name_ = resource_name; | 162 resource_name_ = resource_name; |
163 } | 163 } |
164 | 164 |
165 void XmppSignalStrategy::OnConnectionStateChanged( | 165 void XmppSignalStrategy::OnConnectionStateChanged( |
166 buzz::XmppEngine::State state) { | 166 buzz::XmppEngine::State state) { |
167 DCHECK(CalledOnValidThread()); | 167 DCHECK(CalledOnValidThread()); |
168 | 168 |
169 if (state == buzz::XmppEngine::STATE_OPEN) { | 169 if (state == buzz::XmppEngine::STATE_OPEN) { |
170 // Verify that the JID that we've received matches the username | |
171 // that we have. If it doesn't, then the OAuth token was probably | |
172 // issued for a different account, so we treat is a an auth error. | |
173 // | |
174 // TODO(sergeyu): Some user accounts may not have associated | |
175 // e-mail address. The check below will fail for such | |
176 // accounts. Make sure we can handle this case proprely. | |
177 if (!StartsWithASCII(GetLocalJid(), username_, false)) { | |
178 LOG(ERROR) << "Received JID that is different from the expected value."; | |
179 error_ = AUTHENTICATION_FAILED; | |
180 xmpp_client_->SignalStateChange.disconnect(this); | |
181 MessageLoop::current()->PostTask( | |
182 FROM_HERE, base::Bind(&DisconnectXmppClient, xmpp_client_)); | |
183 xmpp_client_ = NULL; | |
184 SetState(DISCONNECTED); | |
185 return; | |
186 } | |
187 | |
188 keep_alive_timer_.Start( | 170 keep_alive_timer_.Start( |
189 FROM_HERE, base::TimeDelta::FromSeconds(kKeepAliveIntervalSeconds), | 171 FROM_HERE, base::TimeDelta::FromSeconds(kKeepAliveIntervalSeconds), |
190 this, &XmppSignalStrategy::SendKeepAlive); | 172 this, &XmppSignalStrategy::SendKeepAlive); |
191 SetState(CONNECTED); | 173 SetState(CONNECTED); |
192 } else if (state == buzz::XmppEngine::STATE_CLOSED) { | 174 } else if (state == buzz::XmppEngine::STATE_CLOSED) { |
193 // Make sure we dump errors to the log. | 175 // Make sure we dump errors to the log. |
194 int subcode; | 176 int subcode; |
195 buzz::XmppEngine::Error error = xmpp_client_->GetError(&subcode); | 177 buzz::XmppEngine::Error error = xmpp_client_->GetError(&subcode); |
196 LOG(INFO) << "XMPP connection was closed: error=" << error | 178 LOG(INFO) << "XMPP connection was closed: error=" << error |
197 << ", subcode=" << subcode; | 179 << ", subcode=" << subcode; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism; | 218 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism; |
237 if (settings.token_service() == "oauth2") { | 219 if (settings.token_service() == "oauth2") { |
238 mechanism = "X-OAUTH2"; | 220 mechanism = "X-OAUTH2"; |
239 } | 221 } |
240 | 222 |
241 return new notifier::GaiaTokenPreXmppAuth( | 223 return new notifier::GaiaTokenPreXmppAuth( |
242 jid.Str(), settings.auth_cookie(), settings.token_service(), mechanism); | 224 jid.Str(), settings.auth_cookie(), settings.token_service(), mechanism); |
243 } | 225 } |
244 | 226 |
245 } // namespace remoting | 227 } // namespace remoting |
OLD | NEW |