1
0

auth_info.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef LIB_FS_AUTHINFO_H
  19. #define LIB_FS_AUTHINFO_H
  20. #include "common/optional_wrapper.h"
  21. namespace hdfs {
  22. class Token {
  23. public:
  24. std::string identifier;
  25. std::string password;
  26. };
  27. class AuthInfo {
  28. public:
  29. enum AuthMethod {
  30. kSimple,
  31. kKerberos,
  32. kToken,
  33. kUnknownAuth,
  34. kAuthFailed
  35. };
  36. AuthInfo() :
  37. method(kSimple) {
  38. }
  39. explicit AuthInfo(AuthMethod mech) :
  40. method(mech) {
  41. }
  42. bool useSASL() {
  43. return method != kSimple;
  44. }
  45. const std::string & getUser() const {
  46. return user;
  47. }
  48. void setUser(const std::string & user) {
  49. this->user = user;
  50. }
  51. AuthMethod getMethod() const {
  52. return method;
  53. }
  54. void setMethod(AuthMethod method) {
  55. this->method = method;
  56. }
  57. const std::experimental::optional<Token> & getToken() const {
  58. return token;
  59. }
  60. void setToken(const Token & token) {
  61. this->token = token;
  62. }
  63. void clearToken() {
  64. this->token = std::experimental::nullopt;
  65. }
  66. private:
  67. AuthMethod method;
  68. std::string user;
  69. std::experimental::optional<Token> token;
  70. };
  71. }
  72. #endif /* RPCAUTHINFO_H */