| 1 | /******************************************************************** |
| 2 | * Copyright (c) 2013 - 2014, Pivotal Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Author: Zhanwei Wang |
| 6 | ********************************************************************/ |
| 7 | /******************************************************************** |
| 8 | * 2014 - |
| 9 | * open source under Apache License Version 2.0 |
| 10 | ********************************************************************/ |
| 11 | /** |
| 12 | * Licensed to the Apache Software Foundation (ASF) under one |
| 13 | * or more contributor license agreements. See the NOTICE file |
| 14 | * distributed with this work for additional information |
| 15 | * regarding copyright ownership. The ASF licenses this file |
| 16 | * to you under the Apache License, Version 2.0 (the |
| 17 | * "License"); you may not use this file except in compliance |
| 18 | * with the License. You may obtain a copy of the License at |
| 19 | * |
| 20 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 21 | * |
| 22 | * Unless required by applicable law or agreed to in writing, software |
| 23 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 25 | * See the License for the specific language governing permissions and |
| 26 | * limitations under the License. |
| 27 | */ |
| 28 | #ifndef _HDFS_LIBHDFS3_RPC_RPCAUTH_H_ |
| 29 | #define _HDFS_LIBHDFS3_RPC_RPCAUTH_H_ |
| 30 | |
| 31 | #include "client/UserInfo.h" |
| 32 | #include "Hash.h" |
| 33 | |
| 34 | #include <string> |
| 35 | |
| 36 | namespace Hdfs { |
| 37 | namespace Internal { |
| 38 | |
| 39 | enum AuthMethod { |
| 40 | SIMPLE = 80, KERBEROS = 81, //"GSSAPI" |
| 41 | TOKEN = 82, //"DIGEST-MD5" |
| 42 | UNKNOWN = 255 |
| 43 | }; |
| 44 | |
| 45 | enum AuthProtocol { |
| 46 | NONE = 0, SASL = -33 |
| 47 | }; |
| 48 | |
| 49 | class RpcAuth { |
| 50 | public: |
| 51 | RpcAuth() : |
| 52 | method(SIMPLE) { |
| 53 | } |
| 54 | |
| 55 | explicit RpcAuth(AuthMethod mech) : |
| 56 | method(mech) { |
| 57 | } |
| 58 | |
| 59 | RpcAuth(const UserInfo & ui, AuthMethod mech) : |
| 60 | method(mech), user(ui) { |
| 61 | } |
| 62 | |
| 63 | AuthProtocol getProtocol() const { |
| 64 | return method == SIMPLE ? AuthProtocol::NONE : AuthProtocol::SASL; |
| 65 | } |
| 66 | |
| 67 | const UserInfo & getUser() const { |
| 68 | return user; |
| 69 | } |
| 70 | |
| 71 | UserInfo & getUser() { |
| 72 | return user; |
| 73 | } |
| 74 | |
| 75 | void setUser(const UserInfo & user) { |
| 76 | this->user = user; |
| 77 | } |
| 78 | |
| 79 | AuthMethod getMethod() const { |
| 80 | return method; |
| 81 | } |
| 82 | |
| 83 | void setMethod(AuthMethod method) { |
| 84 | this->method = method; |
| 85 | } |
| 86 | |
| 87 | size_t hash_value() const; |
| 88 | |
| 89 | bool operator ==(const RpcAuth & other) const { |
| 90 | return method == other.method && user == other.user; |
| 91 | } |
| 92 | |
| 93 | public: |
| 94 | static AuthMethod ParseMethod(const std::string & str); |
| 95 | |
| 96 | private: |
| 97 | AuthMethod method; |
| 98 | UserInfo user; |
| 99 | }; |
| 100 | |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | HDFS_HASH_DEFINE(::Hdfs::Internal::RpcAuth); |
| 105 | |
| 106 | #endif /* _HDFS_LIBHDFS3_RPC_RPCAUTH_H_ */ |
| 107 | |