| 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/protocol/negotiating_authenticator_base.h" | 5 #include "remoting/protocol/negotiating_authenticator_base.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 const buzz::StaticQName NegotiatingAuthenticatorBase::kMethodAttributeQName = | 22 const buzz::StaticQName NegotiatingAuthenticatorBase::kMethodAttributeQName = |
| 23 { "", "method" }; | 23 { "", "method" }; |
| 24 const buzz::StaticQName | 24 const buzz::StaticQName |
| 25 NegotiatingAuthenticatorBase::kSupportedMethodsAttributeQName = | 25 NegotiatingAuthenticatorBase::kSupportedMethodsAttributeQName = |
| 26 { "", "supported-methods" }; | 26 { "", "supported-methods" }; |
| 27 const char NegotiatingAuthenticatorBase::kSupportedMethodsSeparator = ','; | 27 const char NegotiatingAuthenticatorBase::kSupportedMethodsSeparator = ','; |
| 28 | 28 |
| 29 NegotiatingAuthenticatorBase::NegotiatingAuthenticatorBase( | 29 NegotiatingAuthenticatorBase::NegotiatingAuthenticatorBase( |
| 30 Authenticator::State initial_state) | 30 Authenticator::State initial_state) |
| 31 : current_method_(AuthenticationMethod::Invalid()), | 31 : state_(initial_state) {} |
| 32 state_(initial_state), | |
| 33 rejection_reason_(INVALID_CREDENTIALS) { | |
| 34 } | |
| 35 | 32 |
| 36 NegotiatingAuthenticatorBase::~NegotiatingAuthenticatorBase() { | 33 NegotiatingAuthenticatorBase::~NegotiatingAuthenticatorBase() {} |
| 37 } | |
| 38 | 34 |
| 39 Authenticator::State NegotiatingAuthenticatorBase::state() const { | 35 Authenticator::State NegotiatingAuthenticatorBase::state() const { |
| 40 return state_; | 36 return state_; |
| 41 } | 37 } |
| 42 | 38 |
| 43 bool NegotiatingAuthenticatorBase::started() const { | 39 bool NegotiatingAuthenticatorBase::started() const { |
| 44 if (!current_authenticator_) { | 40 if (!current_authenticator_) { |
| 45 return false; | 41 return false; |
| 46 } | 42 } |
| 47 return current_authenticator_->started(); | 43 return current_authenticator_->started(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 76 // |resume_callback| to resume the session negotiation. | 72 // |resume_callback| to resume the session negotiation. |
| 77 state_ = current_authenticator_->state(); | 73 state_ = current_authenticator_->state(); |
| 78 if (state_ == REJECTED) | 74 if (state_ == REJECTED) |
| 79 rejection_reason_ = current_authenticator_->rejection_reason(); | 75 rejection_reason_ = current_authenticator_->rejection_reason(); |
| 80 resume_callback.Run(); | 76 resume_callback.Run(); |
| 81 } | 77 } |
| 82 | 78 |
| 83 scoped_ptr<buzz::XmlElement> | 79 scoped_ptr<buzz::XmlElement> |
| 84 NegotiatingAuthenticatorBase::GetNextMessageInternal() { | 80 NegotiatingAuthenticatorBase::GetNextMessageInternal() { |
| 85 DCHECK_EQ(state(), MESSAGE_READY); | 81 DCHECK_EQ(state(), MESSAGE_READY); |
| 86 DCHECK(current_method_.is_valid()); | 82 DCHECK(current_method_ != AuthenticationMethod::INVALID); |
| 87 | 83 |
| 88 scoped_ptr<buzz::XmlElement> result; | 84 scoped_ptr<buzz::XmlElement> result; |
| 89 if (current_authenticator_->state() == MESSAGE_READY) { | 85 if (current_authenticator_->state() == MESSAGE_READY) { |
| 90 result = current_authenticator_->GetNextMessage(); | 86 result = current_authenticator_->GetNextMessage(); |
| 91 } else { | 87 } else { |
| 92 result = CreateEmptyAuthenticatorMessage(); | 88 result = CreateEmptyAuthenticatorMessage(); |
| 93 } | 89 } |
| 94 state_ = current_authenticator_->state(); | 90 state_ = current_authenticator_->state(); |
| 95 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE); | 91 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE); |
| 96 result->AddAttr(kMethodAttributeQName, current_method_.ToString()); | 92 result->AddAttr(kMethodAttributeQName, |
| 93 AuthenticationMethodToString(current_method_)); |
| 97 return result; | 94 return result; |
| 98 } | 95 } |
| 99 | 96 |
| 100 void NegotiatingAuthenticatorBase::AddMethod( | 97 void NegotiatingAuthenticatorBase::AddMethod(AuthenticationMethod method) { |
| 101 const AuthenticationMethod& method) { | 98 DCHECK(method != AuthenticationMethod::INVALID); |
| 102 DCHECK(method.is_valid()); | |
| 103 methods_.push_back(method); | 99 methods_.push_back(method); |
| 104 } | 100 } |
| 105 | 101 |
| 106 const std::string& NegotiatingAuthenticatorBase::GetAuthKey() const { | 102 const std::string& NegotiatingAuthenticatorBase::GetAuthKey() const { |
| 107 DCHECK_EQ(state(), ACCEPTED); | 103 DCHECK_EQ(state(), ACCEPTED); |
| 108 return current_authenticator_->GetAuthKey(); | 104 return current_authenticator_->GetAuthKey(); |
| 109 } | 105 } |
| 110 | 106 |
| 111 scoped_ptr<ChannelAuthenticator> | 107 scoped_ptr<ChannelAuthenticator> |
| 112 NegotiatingAuthenticatorBase::CreateChannelAuthenticator() const { | 108 NegotiatingAuthenticatorBase::CreateChannelAuthenticator() const { |
| 113 DCHECK_EQ(state(), ACCEPTED); | 109 DCHECK_EQ(state(), ACCEPTED); |
| 114 return current_authenticator_->CreateChannelAuthenticator(); | 110 return current_authenticator_->CreateChannelAuthenticator(); |
| 115 } | 111 } |
| 116 | 112 |
| 117 } // namespace protocol | 113 } // namespace protocol |
| 118 } // namespace remoting | 114 } // namespace remoting |
| OLD | NEW |