OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_ | |
6 #define REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "remoting/protocol/authenticator.h" | |
16 | |
17 namespace remoting { | |
18 namespace protocol { | |
19 | |
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 | |
22 // logic supplied by the caller is run when the first message is received from | |
23 // the client. If the connection details are valid (i.e. conform to the current | |
Jamie
2016/08/26 23:12:08
Since the validation is arbitrary, I think you mea
joedow
2016/08/29 23:43:22
True, I'll turn i.e. into e.g. and then I think th
| |
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 { | |
27 public: | |
28 enum class Result { | |
29 SUCCESS, | |
30 ERROR_INVALID_CREDENTIALS, | |
31 ERROR_INVALID_ACCOUNT, | |
32 ERROR_REJECTED_BY_USER | |
33 }; | |
34 | |
35 typedef base::Callback<void(Result validation_result)> ResultCallback; | |
36 | |
37 typedef base::Callback<void(const std::string& remote_jid, | |
38 const ResultCallback& callback)> | |
39 ValidationCallback; | |
40 | |
41 ValidatingAuthenticator(const std::string& remote_jid, | |
Jamie
2016/08/26 23:12:08
This class doesn't need to know the JID--it just p
joedow
2016/08/29 23:43:22
The component providing the ValidationCallback doe
Jamie
2016/08/31 00:28:34
You could rebind the callback with the JID at the
joedow
2016/08/31 17:42:29
Discussed offline. I could do this but it wouldn'
| |
42 const ValidationCallback& validation_callback, | |
43 std::unique_ptr<Authenticator> current_authenticator); | |
44 ~ValidatingAuthenticator() override; | |
45 | |
46 // Authenticator interface. | |
47 State state() const override; | |
48 bool started() const override; | |
49 RejectionReason rejection_reason() const override; | |
50 const std::string& GetAuthKey() const override; | |
51 std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator() | |
52 const override; | |
53 void ProcessMessage(const buzz::XmlElement* message, | |
54 const base::Closure& resume_callback) override; | |
55 std::unique_ptr<buzz::XmlElement> GetNextMessage() override; | |
56 | |
57 private: | |
58 // Checks |validation_result|. On success, |message| and |resume_callback| | |
59 // are passed on to |current_authenticator_|. If the connection was rejected, | |
60 // |state_| and |rejection_reason_| are updated and |resume_callback| is run. | |
61 void OnValidateComplete(const buzz::XmlElement* message, | |
62 const base::Closure& resume_callback, | |
63 Result validation_result); | |
64 | |
65 // Updates |state_| to reflect the current underlying authenticator state. | |
66 // |resume_callback| is called after the state is updated. | |
67 void UpdateState(const base::Closure& resume_callback); | |
68 | |
69 bool first_message_received_ = false; | |
70 | |
71 // The JID of the remote user. | |
72 std::string remote_jid_; | |
73 | |
74 ValidationCallback validation_callback_; | |
75 | |
76 // Returns the current state of the authenticator. | |
77 State state_ = Authenticator::WAITING_MESSAGE; | |
78 | |
79 // Returns the rejection reason. Can be called only when in REJECTED state. | |
80 RejectionReason rejection_reason_ = Authenticator::INVALID_CREDENTIALS; | |
81 | |
82 std::unique_ptr<Authenticator> current_authenticator_; | |
83 | |
84 base::WeakPtrFactory<ValidatingAuthenticator> weak_factory_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(ValidatingAuthenticator); | |
87 }; | |
88 | |
89 } // namespace protocol | |
90 } // namespace remoting | |
91 | |
92 #endif // REMOTING_PROTOCOL_VALIDATING_AUTHENTICATOR_H_ | |
OLD | NEW |