secure_auth_context.cc
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 
20 
21 #include <algorithm>
22 
23 #include <grpc/grpc_security.h>
24 
25 namespace grpc {
26 
27 std::vector<grpc::string_ref> SecureAuthContext::GetPeerIdentity() const {
28  if (ctx_ == nullptr) {
29  return std::vector<grpc::string_ref>();
30  }
33  std::vector<grpc::string_ref> identity;
34  const grpc_auth_property* property = nullptr;
35  while ((property = grpc_auth_property_iterator_next(&iter))) {
36  identity.push_back(
37  grpc::string_ref(property->value, property->value_length));
38  }
39  return identity;
40 }
41 
43  if (ctx_ == nullptr) {
44  return "";
45  }
47  return name == nullptr ? "" : name;
48 }
49 
50 std::vector<grpc::string_ref> SecureAuthContext::FindPropertyValues(
51  const std::string& name) const {
52  if (ctx_ == nullptr) {
53  return std::vector<grpc::string_ref>();
54  }
57  const grpc_auth_property* property = nullptr;
58  std::vector<grpc::string_ref> values;
59  while ((property = grpc_auth_property_iterator_next(&iter))) {
60  values.push_back(grpc::string_ref(property->value, property->value_length));
61  }
62  return values;
63 }
64 
66  if (ctx_ != nullptr) {
69  const grpc_auth_property* property =
71  return AuthPropertyIterator(property, &iter);
72  } else {
73  return end();
74  }
75 }
76 
78  return AuthPropertyIterator();
79 }
80 
82  const grpc::string_ref& value) {
83  if (ctx_ == nullptr) return;
84  grpc_auth_context_add_property(ctx_.get(), key.c_str(), value.data(),
85  value.size());
86 }
87 
89  if (ctx_ == nullptr) return false;
91  name.c_str()) != 0;
92 }
93 
95  if (ctx_ == nullptr) return false;
97 }
98 
99 } // namespace grpc
grpc::string_ref
Definition: grpcpp/impl/codegen/string_ref.h:43
grpc::SecureAuthContext::GetPeerIdentity
std::vector< grpc::string_ref > GetPeerIdentity() const override
Definition: secure_auth_context.cc:27
grpc
Definition: grpcpp/alarm.h:33
grpc_core::RefCountedPtr::get
T * get() const
Definition: ref_counted_ptr.h:146
grpc::SecureAuthContext::AddProperty
void AddProperty(const std::string &key, const grpc::string_ref &value) override
Mutation functions: should only be used by an AuthMetadataProcessor.
Definition: secure_auth_context.cc:81
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_auth_context_peer_is_authenticated
GRPCAPI int grpc_auth_context_peer_is_authenticated(const grpc_auth_context *ctx)
Definition: security_context.cc:168
secure_auth_context.h
setup.name
name
Definition: setup.py:542
grpc_security.h
grpc::SecureAuthContext::IsPeerAuthenticated
bool IsPeerAuthenticated() const override
Returns true if the peer is authenticated.
Definition: secure_auth_context.cc:94
grpc::SecureAuthContext::FindPropertyValues
std::vector< grpc::string_ref > FindPropertyValues(const std::string &name) const override
Returns all the property values with the given name.
Definition: secure_auth_context.cc:50
grpc_auth_property_iterator_next
const GRPCAPI grpc_auth_property * grpc_auth_property_iterator_next(grpc_auth_property_iterator *it)
Definition: security_context.cc:182
grpc::SecureAuthContext::end
AuthPropertyIterator end() const override
Definition: secure_auth_context.cc:77
grpc_auth_context_set_peer_identity_property_name
GRPCAPI int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context *ctx, const char *name)
Definition: security_context.cc:151
grpc::SecureAuthContext::begin
AuthPropertyIterator begin() const override
Iteration over all the properties.
Definition: secure_auth_context.cc:65
grpc_auth_property_iterator
Definition: grpc_security.h:36
grpc::SecureAuthContext::GetPeerIdentityPropertyName
std::string GetPeerIdentityPropertyName() const override
Definition: secure_auth_context.cc:42
grpc_auth_property
Definition: grpc_security.h:43
grpc_auth_context_property_iterator
GRPCAPI grpc_auth_property_iterator grpc_auth_context_property_iterator(const grpc_auth_context *ctx)
Definition: security_context.cc:173
value
const char * value
Definition: hpack_parser_table.cc:165
key
const char * key
Definition: hpack_parser_table.cc:164
grpc_auth_context_peer_identity
GRPCAPI grpc_auth_property_iterator grpc_auth_context_peer_identity(const grpc_auth_context *ctx)
Definition: security_context.cc:218
grpc::AuthPropertyIterator
Definition: grpcpp/impl/codegen/security/auth_context.h:39
values
std::array< int64_t, Size > values
Definition: abseil-cpp/absl/container/btree_benchmark.cc:608
grpc_auth_context_add_property
GRPCAPI void grpc_auth_context_add_property(grpc_auth_context *ctx, const char *name, const char *value, size_t value_length)
Definition: security_context.cc:248
grpc_auth_context_peer_identity_property_name
const GRPCAPI char * grpc_auth_context_peer_identity_property_name(const grpc_auth_context *ctx)
Definition: security_context.cc:144
grpc::SecureAuthContext::ctx_
grpc_core::RefCountedPtr< grpc_auth_context > ctx_
Definition: secure_auth_context.h:61
grpc::SecureAuthContext::SetPeerIdentityPropertyName
bool SetPeerIdentityPropertyName(const std::string &name) override
Definition: secure_auth_context.cc:88
iter
Definition: test_winkernel.cpp:47
grpc_auth_context_find_properties_by_name
GRPCAPI grpc_auth_property_iterator grpc_auth_context_find_properties_by_name(const grpc_auth_context *ctx, const char *name)
Definition: security_context.cc:207


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:15