GRPC C++  0.11.0.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
auth_context.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPCXX_SUPPORT_AUTH_CONTEXT_H
35 #define GRPCXX_SUPPORT_AUTH_CONTEXT_H
36 
37 #include <iterator>
38 #include <vector>
39 
40 #include <grpc/grpc_security.h>
41 #include <grpc++/support/config.h>
43 
44 struct grpc_auth_context;
45 struct grpc_auth_property;
46 struct grpc_auth_property_iterator;
47 
48 namespace grpc {
50 
51 typedef std::pair<grpc::string_ref, grpc::string_ref> AuthProperty;
52 
54  : public std::iterator<std::input_iterator_tag, const AuthProperty> {
55  public:
59  bool operator==(const AuthPropertyIterator& rhs) const;
60  bool operator!=(const AuthPropertyIterator& rhs) const;
61  const AuthProperty operator*();
62 
63  protected:
65  AuthPropertyIterator(const grpc_auth_property* property,
66  const grpc_auth_property_iterator* iter);
67 
68  private:
69  friend class SecureAuthContext;
70  const grpc_auth_property* property_;
71  // The following items form a grpc_auth_property_iterator.
72  const grpc_auth_context* ctx_;
73  size_t index_;
74  const char* name_;
75 };
76 
81 class AuthContext {
82  public:
83  virtual ~AuthContext() {}
84 
86  virtual bool IsPeerAuthenticated() const = 0;
87 
92  virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0;
93  virtual grpc::string GetPeerIdentityPropertyName() const = 0;
94 
96  virtual std::vector<grpc::string_ref> FindPropertyValues(
97  const grpc::string& name) const = 0;
98 
100  virtual AuthPropertyIterator begin() const = 0;
101  virtual AuthPropertyIterator end() const = 0;
102 
104  return GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME;
105  }
106  static string ssl_transport_security_type() {
107  return GRPC_SSL_TRANSPORT_SECURITY_TYPE;
108  }
109  static string x509_cn_property_name() { return GRPC_X509_CN_PROPERTY_NAME; }
110  static string x509_san_property_name() { return GRPC_X509_SAN_PROPERTY_NAME; }
111 
112  // Mutation functions: should only be used by an AuthMetadataProcessor.
113  virtual void AddProperty(const grpc::string& key,
114  const grpc::string_ref& value) = 0;
115  virtual bool SetPeerIdentityPropertyName(const grpc::string& name) = 0;
116 };
117 
118 } // namespace grpc
119 
120 #endif // GRPCXX_SUPPORT_AUTH_CONTEXT_H
std::pair< grpc::string_ref, grpc::string_ref > AuthProperty
Definition: auth_context.h:49
std::string string
Definition: config.h:112
virtual bool IsPeerAuthenticated() const =0
Returns true if the peer is authenticated.
static string ssl_transport_security_type()
Definition: auth_context.h:106
Class encapsulating the Authentication Information.
Definition: auth_context.h:81
Definition: secure_auth_context.h:43
virtual AuthPropertyIterator end() const =0
virtual bool SetPeerIdentityPropertyName(const grpc::string &name)=0
AuthPropertyIterator()
Definition: auth_property_iterator.cc:40
AuthPropertyIterator & operator++()
Definition: auth_property_iterator.cc:52
virtual AuthPropertyIterator begin() const =0
Iteration over all the properties.
static string x509_cn_property_name()
Definition: auth_context.h:109
static string transport_security_type_property_name()
Definition: auth_context.h:103
bool operator!=(const AuthPropertyIterator &rhs) const
Definition: auth_property_iterator.cc:75
const AuthProperty operator*()
Definition: auth_property_iterator.cc:79
virtual ~AuthContext()
Definition: auth_context.h:83
bool operator==(const AuthPropertyIterator &rhs) const
Definition: auth_property_iterator.cc:67
This class is a non owning reference to a string.
Definition: string_ref.h:52
static string x509_san_property_name()
Definition: auth_context.h:110
virtual std::vector< grpc::string_ref > GetPeerIdentity() const =0
A peer identity.
Definition: auth_context.h:53
~AuthPropertyIterator()
Definition: auth_property_iterator.cc:50
virtual std::vector< grpc::string_ref > FindPropertyValues(const grpc::string &name) const =0
Returns all the property values with the given name.
virtual void AddProperty(const grpc::string &key, const grpc::string_ref &value)=0
virtual grpc::string GetPeerIdentityPropertyName() const =0