auth_context.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H
  19. #define GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H
  20. // IWYU pragma: private, include <grpcpp/security/auth_context.h>
  21. #include <iterator>
  22. #include <vector>
  23. #include <grpcpp/impl/codegen/config.h>
  24. #include <grpcpp/impl/codegen/string_ref.h>
  25. struct grpc_auth_context;
  26. struct grpc_auth_property;
  27. struct grpc_auth_property_iterator;
  28. namespace grpc {
  29. class SecureAuthContext;
  30. typedef std::pair<string_ref, string_ref> AuthProperty;
  31. class AuthPropertyIterator {
  32. public:
  33. using iterator_category = std::forward_iterator_tag;
  34. using value_type = const AuthProperty;
  35. using pointer = void;
  36. using reference = void;
  37. using difference_type = std::ptrdiff_t;
  38. ~AuthPropertyIterator();
  39. AuthPropertyIterator& operator++();
  40. AuthPropertyIterator operator++(int);
  41. bool operator==(const AuthPropertyIterator& rhs) const;
  42. bool operator!=(const AuthPropertyIterator& rhs) const;
  43. AuthProperty operator*();
  44. protected:
  45. AuthPropertyIterator();
  46. AuthPropertyIterator(const grpc_auth_property* property,
  47. const grpc_auth_property_iterator* iter);
  48. private:
  49. friend class SecureAuthContext;
  50. const grpc_auth_property* property_;
  51. // The following items form a grpc_auth_property_iterator.
  52. const grpc_auth_context* ctx_;
  53. size_t index_;
  54. const char* name_;
  55. };
  56. /// Class encapsulating the Authentication Information.
  57. ///
  58. /// It includes the secure identity of the peer, the type of secure transport
  59. /// used as well as any other properties required by the authorization layer.
  60. class AuthContext {
  61. public:
  62. virtual ~AuthContext() {}
  63. /// Returns true if the peer is authenticated.
  64. virtual bool IsPeerAuthenticated() const = 0;
  65. /// A peer identity.
  66. ///
  67. /// It is, in general, comprised of one or more properties (in which case they
  68. /// have the same name).
  69. virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0;
  70. virtual std::string GetPeerIdentityPropertyName() const = 0;
  71. /// Returns all the property values with the given name.
  72. virtual std::vector<grpc::string_ref> FindPropertyValues(
  73. const std::string& name) const = 0;
  74. /// Iteration over all the properties.
  75. virtual AuthPropertyIterator begin() const = 0;
  76. virtual AuthPropertyIterator end() const = 0;
  77. /// Mutation functions: should only be used by an AuthMetadataProcessor.
  78. virtual void AddProperty(const std::string& key, const string_ref& value) = 0;
  79. virtual bool SetPeerIdentityPropertyName(const std::string& name) = 0;
  80. };
  81. } // namespace grpc
  82. #endif // GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H