GRPC C++  1.39.1
secure_server_credentials.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_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H
20 #define GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H
21 
22 #include <memory>
23 
26 
27 #include <grpc/grpc_security.h>
28 
30 
31 namespace grpc {
32 
33 class SecureServerCredentials;
34 
36  public:
37  static void Destroy(void* wrapper);
38 
39  static void Process(void* wrapper, grpc_auth_context* context,
40  const grpc_metadata* md, size_t num_md,
41  grpc_process_auth_metadata_done_cb cb, void* user_data);
42 
44  const std::shared_ptr<AuthMetadataProcessor>& processor)
45  : processor_(processor) {
46  if (processor && processor->IsBlocking()) {
47  thread_pool_.reset(CreateDefaultThreadPool());
48  }
49  }
50 
51  private:
52  void InvokeProcessor(grpc_auth_context* context, const grpc_metadata* md,
53  size_t num_md, grpc_process_auth_metadata_done_cb cb,
54  void* user_data);
55  std::unique_ptr<ThreadPoolInterface> thread_pool_;
56  std::shared_ptr<AuthMetadataProcessor> processor_;
57 };
58 
60  public:
62  : creds_(creds) {}
65  }
66 
67  int AddPortToServer(const std::string& addr, grpc_server* server) override;
68 
70  const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) override;
71 
72  grpc_server_credentials* c_creds() { return creds_; }
73 
74  private:
75  SecureServerCredentials* AsSecureServerCredentials() override { return this; }
76 
78  std::unique_ptr<grpc::AuthMetadataProcessorAyncWrapper> processor_;
79 };
80 
81 } // namespace grpc
82 
83 #endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H
Definition: secure_server_credentials.h:35
static void Destroy(void *wrapper)
Definition: secure_server_credentials.cc:32
static void Process(void *wrapper, grpc_auth_context *context, const grpc_metadata *md, size_t num_md, grpc_process_auth_metadata_done_cb cb, void *user_data)
Definition: secure_server_credentials.cc:37
AuthMetadataProcessorAyncWrapper(const std::shared_ptr< AuthMetadataProcessor > &processor)
Definition: secure_server_credentials.h:43
Definition: secure_server_credentials.h:59
grpc_server_credentials * c_creds()
Definition: secure_server_credentials.h:72
SecureServerCredentials(grpc_server_credentials *creds)
Definition: secure_server_credentials.h:61
~SecureServerCredentials() override
Definition: secure_server_credentials.h:63
void SetAuthMetadataProcessor(const std::shared_ptr< grpc::AuthMetadataProcessor > &processor) override
This method is not thread-safe and has to be called before the server is started.
Definition: secure_server_credentials.cc:100
int AddPortToServer(const std::string &addr, grpc_server *server) override
Tries to bind server to the given addr (eg, localhost:1234, 192.168.1.1:31416, [::1]:27182,...
Definition: secure_server_credentials.cc:95
Wrapper around grpc_server_credentials, a way to authenticate a server.
Definition: server_credentials.h:70
void(* grpc_process_auth_metadata_done_cb)(void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md, const grpc_metadata *response_md, size_t num_response_md, grpc_status_code status, const char *error_details)
— Auth Metadata Processing —
Definition: grpc_security.h:629
GRPCAPI void grpc_server_credentials_release(grpc_server_credentials *creds)
Releases a server_credentials object.
Definition: credentials.cc:98
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
ThreadPoolInterface * CreateDefaultThreadPool()
Definition: create_default_thread_pool.cc:38
Definition: security_context.h:51
A single metadata element.
Definition: grpc_types.h:519
Definition: credentials.h:224
Definition: server.h:450