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_CLIENT_USERINFO_H_ |
29 | #define _HDFS_LIBHDFS3_CLIENT_USERINFO_H_ |
30 | |
31 | #include <map> |
32 | #include <string> |
33 | |
34 | #include "Hash.h" |
35 | #include "KerberosName.h" |
36 | #include "Token.h" |
37 | |
38 | #include "Logger.h" |
39 | |
40 | namespace Hdfs { |
41 | namespace Internal { |
42 | |
43 | class UserInfo { |
44 | public: |
45 | UserInfo() { |
46 | } |
47 | |
48 | explicit UserInfo(const std::string & u) : |
49 | effectiveUser(u) { |
50 | } |
51 | |
52 | const std::string & getRealUser() const { |
53 | return realUser; |
54 | } |
55 | |
56 | void setRealUser(const std::string & user) { |
57 | this->realUser = user; |
58 | } |
59 | |
60 | const std::string & getEffectiveUser() const { |
61 | return effectiveUser.getName(); |
62 | } |
63 | |
64 | void setEffectiveUser(const std::string & effectiveUser) { |
65 | this->effectiveUser = KerberosName(effectiveUser); |
66 | } |
67 | |
68 | std::string getPrincipal() const { |
69 | return effectiveUser.getPrincipal(); |
70 | } |
71 | |
72 | bool operator ==(const UserInfo & other) const { |
73 | return realUser == other.realUser |
74 | && effectiveUser == other.effectiveUser; |
75 | } |
76 | |
77 | void addToken(const Token & token) { |
78 | tokens[std::make_pair(token.getKind(), token.getService())] = token; |
79 | } |
80 | |
81 | const Token * selectToken(const std::string & kind, const std::string & service) const { |
82 | std::map<std::pair<std::string, std::string>, Token>::const_iterator it; |
83 | it = tokens.find(std::make_pair(kind, service)); |
84 | |
85 | if (it == tokens.end()) { |
86 | return NULL; |
87 | } |
88 | |
89 | return &it->second; |
90 | } |
91 | |
92 | size_t hash_value() const; |
93 | |
94 | public: |
95 | static UserInfo LocalUser(); |
96 | |
97 | private: |
98 | KerberosName effectiveUser; |
99 | std::map<std::pair<std::string, std::string>, Token> tokens; |
100 | std::string realUser; |
101 | }; |
102 | |
103 | } |
104 | } |
105 | |
106 | HDFS_HASH_DEFINE(::Hdfs::Internal::UserInfo); |
107 | |
108 | #endif /* _HDFS_LIBHDFS3_CLIENT_USERINFO_H_ */ |
109 | |