blob: 212f0d1df3bfa261333e6e01c13c973b58559488 [file] [log] [blame]
Julien Boeuf1d2240c2015-04-09 21:07:56 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Julien Boeuf1d2240c2015-04-09 21:07:56 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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
Julien Boeuf1d2240c2015-04-09 21:07:56 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Julien Boeuf1d2240c2015-04-09 21:07:56 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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.
Julien Boeuf1d2240c2015-04-09 21:07:56 -070016 *
17 */
18
Julien Boeuffce25ee2015-04-10 08:44:20 -070019#ifndef GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H
20#define GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H
21
Julien Boeufc2274e72015-08-10 12:45:17 -070022#include <memory>
23
Julien Boeuf5be92a32015-08-28 16:28:18 -070024#include <grpc++/security/server_credentials.h>
Julien Boeuf1d2240c2015-04-09 21:07:56 -070025
Julien Boeuf1d2240c2015-04-09 21:07:56 -070026#include <grpc/grpc_security.h>
27
Julien Boeuf5b3516e2015-08-26 11:19:10 -070028#include "src/cpp/server/thread_pool_interface.h"
Julien Boeuf1d2240c2015-04-09 21:07:56 -070029
30namespace grpc {
31
Vijay Paic0b2acb2016-11-01 16:31:56 -070032class AuthMetadataProcessorAyncWrapper final {
Julien Boeufc2274e72015-08-10 12:45:17 -070033 public:
Craig Tillerddf3a512015-09-24 13:03:44 -070034 static void Destroy(void* wrapper);
Julien Boeuf0c711ad2015-08-28 14:10:58 -070035
Julien Boeuf8da211f2015-08-14 12:57:42 -070036 static void Process(void* wrapper, grpc_auth_context* context,
37 const grpc_metadata* md, size_t num_md,
Julien Boeufc2274e72015-08-10 12:45:17 -070038 grpc_process_auth_metadata_done_cb cb, void* user_data);
39
40 AuthMetadataProcessorAyncWrapper(
41 const std::shared_ptr<AuthMetadataProcessor>& processor)
42 : thread_pool_(CreateDefaultThreadPool()), processor_(processor) {}
43
44 private:
Julien Boeufbf25bb02015-08-14 12:36:11 -070045 void InvokeProcessor(grpc_auth_context* context, const grpc_metadata* md,
Julien Boeuf8da211f2015-08-14 12:57:42 -070046 size_t num_md, grpc_process_auth_metadata_done_cb cb,
Julien Boeufbf25bb02015-08-14 12:36:11 -070047 void* user_data);
Julien Boeufc2274e72015-08-10 12:45:17 -070048 std::unique_ptr<ThreadPoolInterface> thread_pool_;
49 std::shared_ptr<AuthMetadataProcessor> processor_;
50};
51
Vijay Paic0b2acb2016-11-01 16:31:56 -070052class SecureServerCredentials final : public ServerCredentials {
Julien Boeuf1d2240c2015-04-09 21:07:56 -070053 public:
54 explicit SecureServerCredentials(grpc_server_credentials* creds)
55 : creds_(creds) {}
Vijay Paic0b2acb2016-11-01 16:31:56 -070056 ~SecureServerCredentials() override {
Julien Boeuf1d2240c2015-04-09 21:07:56 -070057 grpc_server_credentials_release(creds_);
58 }
59
Vijay Pai713c7b82016-11-01 16:33:18 -070060 int AddPortToServer(const grpc::string& addr, grpc_server* server) override;
Julien Boeuf1d2240c2015-04-09 21:07:56 -070061
Julien Boeufc2274e72015-08-10 12:45:17 -070062 void SetAuthMetadataProcessor(
Vijay Paic0b2acb2016-11-01 16:31:56 -070063 const std::shared_ptr<AuthMetadataProcessor>& processor) override;
Julien Boeufc2274e72015-08-10 12:45:17 -070064
Julien Boeuf1d2240c2015-04-09 21:07:56 -070065 private:
Julien Boeufc2274e72015-08-10 12:45:17 -070066 grpc_server_credentials* creds_;
67 std::unique_ptr<AuthMetadataProcessorAyncWrapper> processor_;
Julien Boeuf1d2240c2015-04-09 21:07:56 -070068};
69
70} // namespace grpc
71
Julien Boeuffce25ee2015-04-10 08:44:20 -070072#endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H