GRPC C++  1.39.1
security_context.h
Go to the documentation of this file.
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 GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H
20 #define GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H
21 
23 
29 
31 
32 /* --- grpc_auth_context ---
33 
34  High level authentication context object. Can optionally be chained. */
35 
36 /* Property names are always NULL terminated. */
37 
40  size_t count = 0;
41  size_t capacity = 0;
42 };
43 
45 
46 // This type is forward declared as a C struct and we cannot define it as a
47 // class. Otherwise, compiler will complain about type mismatch due to
48 // -Wmismatched-tags.
50  : public grpc_core::RefCounted<grpc_auth_context,
51  grpc_core::NonPolymorphicRefCount> {
52  public:
56  grpc_core::NonPolymorphicRefCount>(
58  ? "auth_context_refcount"
59  : nullptr),
60  chained_(std::move(chained)) {
61  if (chained_ != nullptr) {
62  peer_identity_property_name_ = chained_->peer_identity_property_name_;
63  }
64  }
65 
67  chained_.reset(DEBUG_LOCATION, "chained");
68  if (properties_.array != nullptr) {
69  for (size_t i = 0; i < properties_.count; i++) {
70  grpc_auth_property_reset(&properties_.array[i]);
71  }
72  gpr_free(properties_.array);
73  }
74  }
75 
76  const grpc_auth_context* chained() const { return chained_.get(); }
77  const grpc_auth_property_array& properties() const { return properties_; }
78 
79  bool is_authenticated() const {
80  return peer_identity_property_name_ != nullptr;
81  }
82  const char* peer_identity_property_name() const {
83  return peer_identity_property_name_;
84  }
85  void set_peer_identity_property_name(const char* name) {
86  peer_identity_property_name_ = name;
87  }
88 
89  void ensure_capacity();
90  void add_property(const char* name, const char* value, size_t value_length);
91  void add_cstring_property(const char* name, const char* value);
92 
93  private:
95  grpc_auth_property_array properties_;
96  const char* peer_identity_property_name_ = nullptr;
97 };
98 
99 /* --- grpc_security_context_extension ---
100 
101  Extension to the security context that may be set in a filter and accessed
102  later by a higher level method on a grpc_call object. */
103 
105  void* instance = nullptr;
106  void (*destroy)(void*) = nullptr;
107 };
108 
109 /* --- grpc_client_security_context ---
110 
111  Internal client-side security context. */
112 
116  : creds(std::move(creds)) {}
118 
122 };
123 
127 
128 /* --- grpc_server_security_context ---
129 
130  Internal server-side security context. */
131 
135 
138 };
139 
143 
144 /* --- Channel args for auth context --- */
145 #define GRPC_AUTH_CONTEXT_ARG "grpc.auth_context"
146 
150  const grpc_channel_args* args);
151 
152 #endif /* GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H */
Definition: arena.h:44
Definition: ref_counted.h:282
T * get() const
Definition: ref_counted_ptr.h:147
void reset(T *value=nullptr)
Definition: ref_counted_ptr.h:112
Definition: trace.h:61
#define DEBUG_LOCATION
Definition: debug_location.h:41
GPRAPI void gpr_free(void *ptr)
free
Definition: alloc.cc:50
Round Robin Policy.
Definition: backend_metric.cc:26
Definition: async_unary_call.h:398
grpc_auth_context * grpc_find_auth_context_in_args(const grpc_channel_args *args)
Definition: security_context.cc:313
grpc_server_security_context * grpc_server_security_context_create(grpc_core::Arena *arena)
Definition: security_context.cc:125
grpc_auth_context * grpc_auth_context_from_arg(const grpc_arg *arg)
Definition: security_context.cc:303
grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount
grpc_client_security_context * grpc_client_security_context_create(grpc_core::Arena *arena, grpc_call_credentials *creds)
Definition: security_context.cc:104
void grpc_client_security_context_destroy(void *ctx)
Definition: security_context.cc:110
void grpc_server_security_context_destroy(void *ctx)
Definition: security_context.cc:130
grpc_arg grpc_auth_context_to_arg(grpc_auth_context *c)
Definition: security_context.cc:297
void grpc_auth_property_reset(grpc_auth_property *property)
Definition: security_context.cc:271
A single argument...
Definition: grpc_types.h:103
Definition: security_context.h:51
const char * peer_identity_property_name() const
Definition: security_context.h:82
void add_property(const char *name, const char *value, size_t value_length)
Definition: security_context.cc:231
bool is_authenticated() const
Definition: security_context.h:79
const grpc_auth_property_array & properties() const
Definition: security_context.h:77
grpc_auth_context(grpc_core::RefCountedPtr< grpc_auth_context > chained)
Definition: security_context.h:53
~grpc_auth_context()
Definition: security_context.h:66
void add_cstring_property(const char *name, const char *value)
Definition: security_context.cc:253
void ensure_capacity()
Definition: security_context.cc:222
void set_peer_identity_property_name(const char *name)
Definition: security_context.h:85
const grpc_auth_context * chained() const
Definition: security_context.h:76
Definition: security_context.h:38
size_t count
Definition: security_context.h:40
grpc_auth_property * array
Definition: security_context.h:39
size_t capacity
Definition: security_context.h:41
value, if not NULL, is guaranteed to be NULL terminated.
Definition: grpc_security.h:43
Definition: credentials.h:173
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Definition: security_context.h:113
grpc_security_context_extension extension
Definition: security_context.h:121
grpc_core::RefCountedPtr< grpc_auth_context > auth_context
Definition: security_context.h:120
~grpc_client_security_context()
Definition: security_context.cc:97
grpc_core::RefCountedPtr< grpc_call_credentials > creds
Definition: security_context.h:119
grpc_client_security_context(grpc_core::RefCountedPtr< grpc_call_credentials > creds)
Definition: security_context.h:114
Definition: security_context.h:104
void(* destroy)(void *)
Definition: security_context.h:106
void * instance
Definition: security_context.h:105
Definition: security_context.h:132
grpc_core::RefCountedPtr< grpc_auth_context > auth_context
Definition: security_context.h:136
grpc_security_context_extension extension
Definition: security_context.h:137
~grpc_server_security_context()
Definition: security_context.cc:118
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: trace.h:112
upb_arena * arena
Definition: xds_api.cc:909