auth_metadata_processor.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_H
  19. #define GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_H
  20. #include <map>
  21. #include <grpcpp/security/auth_context.h>
  22. #include <grpcpp/support/status.h>
  23. #include <grpcpp/support/string_ref.h>
  24. namespace grpc {
  25. /// Interface allowing custom server-side authorization based on credentials
  26. /// encoded in metadata. Objects of this type can be passed to
  27. /// \a ServerCredentials::SetAuthMetadataProcessor().
  28. /// Please also check out \a grpc::experimental::Interceptor for another way to
  29. /// do customized operations on the information provided by a specific call.
  30. class AuthMetadataProcessor {
  31. public:
  32. typedef std::multimap<grpc::string_ref, grpc::string_ref> InputMetadata;
  33. typedef std::multimap<TString, TString> OutputMetadata;
  34. virtual ~AuthMetadataProcessor() {}
  35. /// If this method returns true, the \a Process function will be scheduled in
  36. /// a different thread from the one processing the call.
  37. virtual bool IsBlocking() const { return true; }
  38. /// Processes a Call associated with a connection.
  39. /// auth_metadata: the authentication metadata associated with the particular
  40. /// call
  41. /// context: contains the connection-level info, e.g. the peer identity. This
  42. /// parameter is readable and writable. Note that since the information is
  43. /// shared for all calls associated with the connection, if the
  44. /// implementation updates the info in a specific call, all the subsequent
  45. /// calls will see the updates. A typical usage of context is to use
  46. /// |auth_metadata| to infer the peer identity, and augment it with
  47. /// properties.
  48. /// consumed_auth_metadata: contains the metadata that the implementation
  49. /// wants to remove from the current call, so that the server application is
  50. /// no longer able to see it anymore. A typical usage would be to do token
  51. /// authentication in the first call, and then remove the token information
  52. /// for all subsequent calls.
  53. /// response_metadata(CURRENTLY NOT SUPPORTED): the metadata that will be sent
  54. /// as part of the response.
  55. /// return: if the return value is not Status::OK, the rpc call will be
  56. /// aborted with the error code and error message sent back to the client.
  57. virtual grpc::Status Process(const InputMetadata& auth_metadata,
  58. grpc::AuthContext* context,
  59. OutputMetadata* consumed_auth_metadata,
  60. OutputMetadata* response_metadata) = 0;
  61. };
  62. } // namespace grpc
  63. #endif // GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_H