Imported Upstream version 1.41.0
[platform/upstream/grpc.git] / include / grpcpp / impl / codegen / security / auth_context.h
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #ifndef GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H
20 #define GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H
21
22 // IWYU pragma: private, include <grpcpp/security/auth_context.h>
23
24 #include <iterator>
25 #include <vector>
26
27 #include <grpcpp/impl/codegen/config.h>
28 #include <grpcpp/impl/codegen/string_ref.h>
29
30 struct grpc_auth_context;
31 struct grpc_auth_property;
32 struct grpc_auth_property_iterator;
33
34 namespace grpc {
35 class SecureAuthContext;
36
37 typedef std::pair<string_ref, string_ref> AuthProperty;
38
39 class AuthPropertyIterator
40     : public std::iterator<std::input_iterator_tag, const AuthProperty> {
41  public:
42   ~AuthPropertyIterator();
43   AuthPropertyIterator& operator++();
44   AuthPropertyIterator operator++(int);
45   bool operator==(const AuthPropertyIterator& rhs) const;
46   bool operator!=(const AuthPropertyIterator& rhs) const;
47   AuthProperty operator*();
48
49  protected:
50   AuthPropertyIterator();
51   AuthPropertyIterator(const grpc_auth_property* property,
52                        const grpc_auth_property_iterator* iter);
53
54  private:
55   friend class SecureAuthContext;
56   const grpc_auth_property* property_;
57   // The following items form a grpc_auth_property_iterator.
58   const grpc_auth_context* ctx_;
59   size_t index_;
60   const char* name_;
61 };
62
63 /// Class encapsulating the Authentication Information.
64 ///
65 /// It includes the secure identity of the peer, the type of secure transport
66 /// used as well as any other properties required by the authorization layer.
67 class AuthContext {
68  public:
69   virtual ~AuthContext() {}
70
71   /// Returns true if the peer is authenticated.
72   virtual bool IsPeerAuthenticated() const = 0;
73
74   /// A peer identity.
75   ///
76   /// It is, in general, comprised of one or more properties (in which case they
77   /// have the same name).
78   virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0;
79   virtual std::string GetPeerIdentityPropertyName() const = 0;
80
81   /// Returns all the property values with the given name.
82   virtual std::vector<grpc::string_ref> FindPropertyValues(
83       const std::string& name) const = 0;
84
85   /// Iteration over all the properties.
86   virtual AuthPropertyIterator begin() const = 0;
87   virtual AuthPropertyIterator end() const = 0;
88
89   /// Mutation functions: should only be used by an AuthMetadataProcessor.
90   virtual void AddProperty(const std::string& key, const string_ref& value) = 0;
91   virtual bool SetPeerIdentityPropertyName(const std::string& name) = 0;
92 };
93
94 }  // namespace grpc
95
96 #endif  // GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H