auth_context.h 3.0 KB

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