• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <iterator>
23 #include <vector>
24 
25 #include <grpcpp/impl/codegen/config.h>
26 #include <grpcpp/impl/codegen/string_ref.h>
27 
28 struct grpc_auth_context;
29 struct grpc_auth_property;
30 struct grpc_auth_property_iterator;
31 
32 namespace grpc {
33 class SecureAuthContext;
34 
35 typedef std::pair<grpc::string_ref, grpc::string_ref> AuthProperty;
36 
37 class AuthPropertyIterator
38     : public std::iterator<std::input_iterator_tag, const AuthProperty> {
39  public:
40   ~AuthPropertyIterator();
41   AuthPropertyIterator& operator++();
42   AuthPropertyIterator operator++(int);
43   bool operator==(const AuthPropertyIterator& rhs) const;
44   bool operator!=(const AuthPropertyIterator& rhs) const;
45   const AuthProperty operator*();
46 
47  protected:
48   AuthPropertyIterator();
49   AuthPropertyIterator(const grpc_auth_property* property,
50                        const grpc_auth_property_iterator* iter);
51 
52  private:
53   friend class SecureAuthContext;
54   const grpc_auth_property* property_;
55   // The following items form a grpc_auth_property_iterator.
56   const grpc_auth_context* ctx_;
57   size_t index_;
58   const char* name_;
59 };
60 
61 /// Class encapsulating the Authentication Information.
62 ///
63 /// It includes the secure identity of the peer, the type of secure transport
64 /// used as well as any other properties required by the authorization layer.
65 class AuthContext {
66  public:
~AuthContext()67   virtual ~AuthContext() {}
68 
69   /// Returns true if the peer is authenticated.
70   virtual bool IsPeerAuthenticated() const = 0;
71 
72   /// A peer identity.
73   ///
74   /// It is, in general, comprised of one or more properties (in which case they
75   /// have the same name).
76   virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0;
77   virtual grpc::string GetPeerIdentityPropertyName() const = 0;
78 
79   /// Returns all the property values with the given name.
80   virtual std::vector<grpc::string_ref> FindPropertyValues(
81       const grpc::string& name) const = 0;
82 
83   /// Iteration over all the properties.
84   virtual AuthPropertyIterator begin() const = 0;
85   virtual AuthPropertyIterator end() const = 0;
86 
87   /// Mutation functions: should only be used by an AuthMetadataProcessor.
88   virtual void AddProperty(const grpc::string& key,
89                            const grpc::string_ref& value) = 0;
90   virtual bool SetPeerIdentityPropertyName(const grpc::string& name) = 0;
91 };
92 
93 }  // namespace grpc
94 
95 #endif  // GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H
96