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 |
170 keep_alive_timer_.Start( | 188 keep_alive_timer_.Start( |
171 FROM_HERE, base::TimeDelta::FromSeconds(kKeepAliveIntervalSeconds), | 189 FROM_HERE, base::TimeDelta::FromSeconds(kKeepAliveIntervalSeconds), |
172 this, &XmppSignalStrategy::SendKeepAlive); | 190 this, &XmppSignalStrategy::SendKeepAlive); |
173 SetState(CONNECTED); | 191 SetState(CONNECTED); |
174 } else if (state == buzz::XmppEngine::STATE_CLOSED) { | 192 } else if (state == buzz::XmppEngine::STATE_CLOSED) { |
175 // Make sure we dump errors to the log. | 193 // Make sure we dump errors to the log. |
176 int subcode; | 194 int subcode; |
177 buzz::XmppEngine::Error error = xmpp_client_->GetError(&subcode); | 195 buzz::XmppEngine::Error error = xmpp_client_->GetError(&subcode); |
178 LOG(INFO) << "XMPP connection was closed: error=" << error | 196 LOG(INFO) << "XMPP connection was closed: error=" << error |
179 << ", subcode=" << subcode; | 197 << ", subcode=" << subcode; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism; | 236 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism; |
219 if (settings.token_service() == "oauth2") { | 237 if (settings.token_service() == "oauth2") { |
220 mechanism = "X-OAUTH2"; | 238 mechanism = "X-OAUTH2"; |
221 } | 239 } |
222 | 240 |
223 return new notifier::GaiaTokenPreXmppAuth( | 241 return new notifier::GaiaTokenPreXmppAuth( |
224 jid.Str(), settings.auth_cookie(), settings.token_service(), mechanism); | 242 jid.Str(), settings.auth_cookie(), settings.token_service(), mechanism); |
225 } | 243 } |
226 | 244 |
227 } // namespace remoting | 245 } // namespace remoting |
OLD | NEW |