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

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

Issue 2724223003: Disconnect all users if too many connection requests are received for It2Me (Closed)
Patch Set: Addressing CR 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
« no previous file with comments | « remoting/protocol/jingle_session.cc ('k') | remoting/protocol/validating_authenticator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_ 5 #ifndef REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_
6 #define REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_ 6 #define REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "remoting/protocol/authenticator.h" 15 #include "remoting/protocol/authenticator.h"
16 16
17 namespace remoting { 17 namespace remoting {
18 namespace protocol { 18 namespace protocol {
19 19
20 // This authenticator class provides a way to check the validity of a connection 20 // This authenticator class provides a way to check the validity of a connection
21 // as it is being established through an asynchronous callback. The validation 21 // as it is being established through an asynchronous callback. The validation
22 // logic supplied by the caller is run when the first message is received from 22 // logic supplied by the caller is run once the underlying authenticator(s) have
23 // the client. If the connection details are valid (e.g. conform to the current 23 // accepted the connection.
24 // policies), then the initial message, and all subsequent messages, are passed
25 // to the underlying authenticator instance for processing.
26 class ValidatingAuthenticator : public Authenticator { 24 class ValidatingAuthenticator : public Authenticator {
27 public: 25 public:
28 enum class Result { 26 enum class Result {
29 SUCCESS, 27 SUCCESS,
30 ERROR_INVALID_CREDENTIALS, 28 ERROR_INVALID_CREDENTIALS,
31 ERROR_INVALID_ACCOUNT, 29 ERROR_INVALID_ACCOUNT,
32 ERROR_REJECTED_BY_USER 30 ERROR_REJECTED_BY_USER,
31 ERROR_TOO_MANY_CONNECTIONS
33 }; 32 };
34 33
35 typedef base::Callback<void(Result validation_result)> ResultCallback; 34 typedef base::Callback<void(Result validation_result)> ResultCallback;
36 35
37 typedef base::Callback<void(const std::string& remote_jid, 36 typedef base::Callback<void(const std::string& remote_jid,
38 const ResultCallback& callback)> 37 const ResultCallback& callback)>
39 ValidationCallback; 38 ValidationCallback;
40 39
41 ValidatingAuthenticator(const std::string& remote_jid, 40 ValidatingAuthenticator(const std::string& remote_jid,
42 const ValidationCallback& validation_callback, 41 const ValidationCallback& validation_callback,
43 std::unique_ptr<Authenticator> current_authenticator); 42 std::unique_ptr<Authenticator> current_authenticator);
44 ~ValidatingAuthenticator() override; 43 ~ValidatingAuthenticator() override;
45 44
46 // Authenticator interface. 45 // Authenticator interface.
47 State state() const override; 46 State state() const override;
48 bool started() const override; 47 bool started() const override;
49 RejectionReason rejection_reason() const override; 48 RejectionReason rejection_reason() const override;
50 const std::string& GetAuthKey() const override; 49 const std::string& GetAuthKey() const override;
51 std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator() 50 std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator()
52 const override; 51 const override;
53 void ProcessMessage(const buzz::XmlElement* message, 52 void ProcessMessage(const buzz::XmlElement* message,
54 const base::Closure& resume_callback) override; 53 const base::Closure& resume_callback) override;
55 std::unique_ptr<buzz::XmlElement> GetNextMessage() override; 54 std::unique_ptr<buzz::XmlElement> GetNextMessage() override;
56 55
57 private: 56 private:
58 // Checks |validation_result|. On success, |message| and |resume_callback| 57 // Checks |result|. If the connection was rejected, |state_| and
59 // are passed on to |current_authenticator_|. If the connection was rejected, 58 // |rejection_reason_| are updated. |callback| is always run.
60 // |state_| and |rejection_reason_| are updated and |resume_callback| is run. 59 void OnValidateComplete(const base::Closure& callback, Result result);
61 void OnValidateComplete(const buzz::XmlElement* message,
62 const base::Closure& resume_callback,
63 Result validation_result);
64 60
65 // Updates |state_| to reflect the current underlying authenticator state. 61 // Updates |state_| to reflect the current underlying authenticator state.
66 // |resume_callback| is called after the state is updated. 62 // |resume_callback| is called after the state is updated.
67 void UpdateState(const base::Closure& resume_callback); 63 void UpdateState(const base::Closure& resume_callback);
68 64
69 bool first_message_received_ = false;
70
71 // The JID of the remote user. 65 // The JID of the remote user.
72 std::string remote_jid_; 66 std::string remote_jid_;
73 67
68 // Called for validation of incoming connection requests.
74 ValidationCallback validation_callback_; 69 ValidationCallback validation_callback_;
75 70
76 // Returns the current state of the authenticator. 71 // Returns the current state of the authenticator.
77 State state_ = Authenticator::WAITING_MESSAGE; 72 State state_ = Authenticator::WAITING_MESSAGE;
78 73
79 // Returns the rejection reason. Can be called only when in REJECTED state. 74 // Returns the rejection reason. Can be called only when in REJECTED state.
80 RejectionReason rejection_reason_ = Authenticator::INVALID_CREDENTIALS; 75 RejectionReason rejection_reason_ = Authenticator::INVALID_CREDENTIALS;
81 76
82 std::unique_ptr<Authenticator> current_authenticator_; 77 std::unique_ptr<Authenticator> current_authenticator_;
83 78
79 std::unique_ptr<buzz::XmlElement> pending_auth_message_;
80
84 base::WeakPtrFactory<ValidatingAuthenticator> weak_factory_; 81 base::WeakPtrFactory<ValidatingAuthenticator> weak_factory_;
85 82
86 DISALLOW_COPY_AND_ASSIGN(ValidatingAuthenticator); 83 DISALLOW_COPY_AND_ASSIGN(ValidatingAuthenticator);
87 }; 84 };
88 85
89 } // namespace protocol 86 } // namespace protocol
90 } // namespace remoting 87 } // namespace remoting
91 88
92 #endif // REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_ 89 #endif // REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_
OLDNEW
« no previous file with comments | « remoting/protocol/jingle_session.cc ('k') | remoting/protocol/validating_authenticator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698