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

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

Issue 2277553002: Adding a new authenticator which can be used to validate the remote user (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@policy_change
Patch Set: Addressing Feedback Created 4 years, 3 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
(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 (e.g. conform to the current
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,
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698