auth_metadata_processor.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. class AuthMetadataProcessor {
  29. public:
  30. typedef std::multimap<grpc::string_ref, grpc::string_ref> InputMetadata;
  31. typedef std::multimap<std::string, std::string> OutputMetadata;
  32. virtual ~AuthMetadataProcessor() {}
  33. /// If this method returns true, the \a Process function will be scheduled in
  34. /// a different thread from the one processing the call.
  35. virtual bool IsBlocking() const { return true; }
  36. /// context is read/write: it contains the properties of the channel peer and
  37. /// it is the job of the Process method to augment it with properties derived
  38. /// from the passed-in auth_metadata.
  39. /// consumed_auth_metadata needs to be filled with metadata that has been
  40. /// consumed by the processor and will be removed from the call.
  41. /// response_metadata is the metadata that will be sent as part of the
  42. /// response.
  43. /// If the return value is not Status::OK, the rpc call will be aborted with
  44. /// the error code and error message sent back to the client.
  45. virtual grpc::Status Process(const InputMetadata& auth_metadata,
  46. grpc::AuthContext* context,
  47. OutputMetadata* consumed_auth_metadata,
  48. OutputMetadata* response_metadata) = 0;
  49. };
  50. } // namespace grpc
  51. #endif // GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_H