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_KERBEROSNAME_H_ |
29 | #define _HDFS_LIBHDFS3_CLIENT_KERBEROSNAME_H_ |
30 | |
31 | #include <string> |
32 | #include <sstream> |
33 | |
34 | #include "Hash.h" |
35 | |
36 | namespace Hdfs { |
37 | namespace Internal { |
38 | |
39 | class KerberosName { |
40 | public: |
41 | KerberosName(); |
42 | KerberosName(const std::string & principal); |
43 | |
44 | std::string getPrincipal() const { |
45 | std::stringstream ss; |
46 | ss.imbue(std::locale::classic()); |
47 | ss << name; |
48 | |
49 | if (!host.empty()) { |
50 | ss << "/" << host; |
51 | } |
52 | |
53 | if (!realm.empty()) { |
54 | ss << '@' << realm; |
55 | } |
56 | |
57 | return ss.str(); |
58 | } |
59 | |
60 | const std::string & getHost() const { |
61 | return host; |
62 | } |
63 | |
64 | void setHost(const std::string & host) { |
65 | this->host = host; |
66 | } |
67 | |
68 | const std::string & getName() const { |
69 | return name; |
70 | } |
71 | |
72 | void setName(const std::string & name) { |
73 | this->name = name; |
74 | } |
75 | |
76 | const std::string & getRealm() const { |
77 | return realm; |
78 | } |
79 | |
80 | void setRealm(const std::string & realm) { |
81 | this->realm = realm; |
82 | } |
83 | |
84 | size_t hash_value() const; |
85 | |
86 | bool operator ==(const KerberosName & other) const { |
87 | return name == other.name && host == other.host && realm == other.realm; |
88 | } |
89 | |
90 | private: |
91 | void parse(const std::string & principal); |
92 | |
93 | private: |
94 | std::string name; |
95 | std::string host; |
96 | std::string realm; |
97 | }; |
98 | |
99 | } |
100 | } |
101 | |
102 | HDFS_HASH_DEFINE(::Hdfs::Internal::KerberosName); |
103 | |
104 | #endif /* _HDFS_LIBHDFS3_CLIENT_KERBEROSNAME_H_ */ |
105 | |