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

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: Fixing another non-Windows build error 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 #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 when the first message is received from
23 // the client. If the connection details are valid (e.g. conform to the current 23 // the client. If the connection details are valid (e.g. conform to the current
24 // policies), then the initial message, and all subsequent messages, are passed 24 // policies), then the initial message, and all subsequent messages, are passed
25 // to the underlying authenticator instance for processing. 25 // to the underlying authenticator instance for processing. Once the connection
26 // is accepted, a second callback (provided during construction) is used to
27 // ultimately accept or reject the connection. Splitting the validation into
28 // two parts allows pre-validation to occur before passing the info on to
29 // the lower-level validators and a final validation step once all other checks
30 // have passed.
26 class ValidatingAuthenticator : public Authenticator { 31 class ValidatingAuthenticator : public Authenticator {
27 public: 32 public:
28 enum class Result { 33 enum class Result {
29 SUCCESS, 34 SUCCESS,
30 ERROR_INVALID_CREDENTIALS, 35 ERROR_INVALID_CREDENTIALS,
31 ERROR_INVALID_ACCOUNT, 36 ERROR_INVALID_ACCOUNT,
32 ERROR_REJECTED_BY_USER 37 ERROR_REJECTED_BY_USER,
38 ERROR_TOO_MANY_CONNECTIONS
33 }; 39 };
34 40
35 typedef base::Callback<void(Result validation_result)> ResultCallback; 41 typedef base::Callback<void(Result validation_result)> ResultCallback;
36 42
37 typedef base::Callback<void(const std::string& remote_jid, 43 typedef base::Callback<void(const std::string& remote_jid,
38 const ResultCallback& callback)> 44 const ResultCallback& callback)>
39 ValidationCallback; 45 ValidationCallback;
40 46
41 ValidatingAuthenticator(const std::string& remote_jid, 47 ValidatingAuthenticator(const std::string& remote_jid,
42 const ValidationCallback& validation_callback, 48 const ValidationCallback& incoming_callback,
49 const ValidationCallback& accepted_callback,
43 std::unique_ptr<Authenticator> current_authenticator); 50 std::unique_ptr<Authenticator> current_authenticator);
44 ~ValidatingAuthenticator() override; 51 ~ValidatingAuthenticator() override;
45 52
46 // Authenticator interface. 53 // Authenticator interface.
47 State state() const override; 54 State state() const override;
48 bool started() const override; 55 bool started() const override;
49 RejectionReason rejection_reason() const override; 56 RejectionReason rejection_reason() const override;
50 const std::string& GetAuthKey() const override; 57 const std::string& GetAuthKey() const override;
51 std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator() 58 std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator()
52 const override; 59 const override;
53 void ProcessMessage(const buzz::XmlElement* message, 60 void ProcessMessage(const buzz::XmlElement* message,
54 const base::Closure& resume_callback) override; 61 const base::Closure& resume_callback) override;
55 std::unique_ptr<buzz::XmlElement> GetNextMessage() override; 62 std::unique_ptr<buzz::XmlElement> GetNextMessage() override;
56 63
57 private: 64 private:
58 // Checks |validation_result|. On success, |message| and |resume_callback| 65 // Checks |validation_result|. On success, |success_callback| is called.
59 // are passed on to |current_authenticator_|. If the connection was rejected, 66 // If the connection was rejected, |state_| and |rejection_reason_| are
60 // |state_| and |rejection_reason_| are updated and |resume_callback| is run. 67 // updated and |failure_callback| is run.
61 void OnValidateComplete(const buzz::XmlElement* message, 68 void OnValidateComplete(const base::Closure& success_callback,
62 const base::Closure& resume_callback, 69 const base::Closure& failure_callback,
63 Result validation_result); 70 Result validation_result);
64 71
65 // Updates |state_| to reflect the current underlying authenticator state. 72 // Updates |state_| to reflect the current underlying authenticator state.
66 // |resume_callback| is called after the state is updated. 73 // |resume_callback| is called after the state is updated.
67 void UpdateState(const base::Closure& resume_callback); 74 void UpdateState(const base::Closure& resume_callback);
68 75
69 bool first_message_received_ = false; 76 bool first_message_received_ = false;
70 77
71 // The JID of the remote user. 78 // The JID of the remote user.
72 std::string remote_jid_; 79 std::string remote_jid_;
73 80
74 ValidationCallback validation_callback_; 81 // Called for pre-validation of incoming connection requests.
82 ValidationCallback incoming_callback_;
83
84 // Called for final validation of accepted connection requests.
85 ValidationCallback accepted_callback_;
75 86
76 // Returns the current state of the authenticator. 87 // Returns the current state of the authenticator.
77 State state_ = Authenticator::WAITING_MESSAGE; 88 State state_ = Authenticator::WAITING_MESSAGE;
78 89
79 // Returns the rejection reason. Can be called only when in REJECTED state. 90 // Returns the rejection reason. Can be called only when in REJECTED state.
80 RejectionReason rejection_reason_ = Authenticator::INVALID_CREDENTIALS; 91 RejectionReason rejection_reason_ = Authenticator::INVALID_CREDENTIALS;
81 92
82 std::unique_ptr<Authenticator> current_authenticator_; 93 std::unique_ptr<Authenticator> current_authenticator_;
83 94
95 std::unique_ptr<buzz::XmlElement> pending_auth_message_;
96
84 base::WeakPtrFactory<ValidatingAuthenticator> weak_factory_; 97 base::WeakPtrFactory<ValidatingAuthenticator> weak_factory_;
85 98
86 DISALLOW_COPY_AND_ASSIGN(ValidatingAuthenticator); 99 DISALLOW_COPY_AND_ASSIGN(ValidatingAuthenticator);
87 }; 100 };
88 101
89 } // namespace protocol 102 } // namespace protocol
90 } // namespace remoting 103 } // namespace remoting
91 104
92 #endif // REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_ 105 #endif // REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698