• 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 GRPC_CORE_LIB_SECURITY_CREDENTIALS_COMPOSITE_COMPOSITE_CREDENTIALS_H
20 #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_COMPOSITE_COMPOSITE_CREDENTIALS_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include <string>
25 
26 #include "absl/container/inlined_vector.h"
27 
28 #include "src/core/lib/gprpp/ref_counted_ptr.h"
29 #include "src/core/lib/security/credentials/credentials.h"
30 
31 /* -- Composite channel credentials. -- */
32 
33 class grpc_composite_channel_credentials : public grpc_channel_credentials {
34  public:
grpc_composite_channel_credentials(grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,grpc_core::RefCountedPtr<grpc_call_credentials> call_creds)35   grpc_composite_channel_credentials(
36       grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
37       grpc_core::RefCountedPtr<grpc_call_credentials> call_creds)
38       : grpc_channel_credentials(channel_creds->type()),
39         inner_creds_(std::move(channel_creds)),
40         call_creds_(std::move(call_creds)) {}
41 
42   ~grpc_composite_channel_credentials() override = default;
43 
44   grpc_core::RefCountedPtr<grpc_channel_credentials>
duplicate_without_call_credentials()45   duplicate_without_call_credentials() override {
46     return inner_creds_;
47   }
48 
49   grpc_core::RefCountedPtr<grpc_channel_security_connector>
50   create_security_connector(
51       grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
52       const char* target, const grpc_channel_args* args,
53       grpc_channel_args** new_args) override;
54 
update_arguments(grpc_channel_args * args)55   grpc_channel_args* update_arguments(grpc_channel_args* args) override {
56     return inner_creds_->update_arguments(args);
57   }
58 
inner_creds()59   const grpc_channel_credentials* inner_creds() const {
60     return inner_creds_.get();
61   }
call_creds()62   const grpc_call_credentials* call_creds() const { return call_creds_.get(); }
mutable_call_creds()63   grpc_call_credentials* mutable_call_creds() { return call_creds_.get(); }
64 
65  private:
66   grpc_core::RefCountedPtr<grpc_channel_credentials> inner_creds_;
67   grpc_core::RefCountedPtr<grpc_call_credentials> call_creds_;
68 };
69 
70 /* -- Composite call credentials. -- */
71 
72 class grpc_composite_call_credentials : public grpc_call_credentials {
73  public:
74   using CallCredentialsList =
75       absl::InlinedVector<grpc_core::RefCountedPtr<grpc_call_credentials>, 2>;
76 
77   grpc_composite_call_credentials(
78       grpc_core::RefCountedPtr<grpc_call_credentials> creds1,
79       grpc_core::RefCountedPtr<grpc_call_credentials> creds2);
80   ~grpc_composite_call_credentials() override = default;
81 
82   bool get_request_metadata(grpc_polling_entity* pollent,
83                             grpc_auth_metadata_context context,
84                             grpc_credentials_mdelem_array* md_array,
85                             grpc_closure* on_request_metadata,
86                             grpc_error** error) override;
87 
88   void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
89                                    grpc_error* error) override;
90 
min_security_level()91   grpc_security_level min_security_level() const override {
92     return min_security_level_;
93   }
94 
inner()95   const CallCredentialsList& inner() const { return inner_; }
96   std::string debug_string() override;
97 
98  private:
99   void push_to_inner(grpc_core::RefCountedPtr<grpc_call_credentials> creds,
100                      bool is_composite);
101   grpc_security_level min_security_level_;
102   CallCredentialsList inner_;
103 };
104 
105 #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_COMPOSITE_COMPOSITE_CREDENTIALS_H \
106         */
107