Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
auth-provider.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef IMPALA_RPC_AUTH_PROVIDER_H
16 #define IMPALA_RPC_AUTH_PROVIDER_H
17 
18 #include <string>
19 #include <boost/scoped_ptr.hpp>
20 #include <boost/thread/mutex.hpp>
21 #include <sasl/sasl.h>
22 
23 #include "common/status.h"
24 #include "util/promise.h"
25 
26 namespace sasl { class TSasl; }
27 
28 namespace impala {
29 
30 class Thread;
31 
36 class AuthProvider {
37  public:
39  virtual Status Start() = 0;
40 
44  boost::shared_ptr<apache::thrift::transport::TTransportFactory>* factory) = 0;
45 
48  virtual Status WrapClientTransport(const std::string& hostname,
49  boost::shared_ptr<apache::thrift::transport::TTransport> raw_transport,
50  const std::string& service_name,
51  boost::shared_ptr<apache::thrift::transport::TTransport>* wrapped_transport) = 0;
52 
54  virtual bool is_sasl() = 0;
55 };
56 
62  public:
63  SaslAuthProvider(bool is_internal) : has_ldap_(false), is_internal_(is_internal),
64  needs_kinit_(false) {}
65 
69  virtual Status Start();
70 
74  virtual Status WrapClientTransport(const std::string& hostname,
75  boost::shared_ptr<apache::thrift::transport::TTransport> raw_transport,
76  const std::string& service_name,
77  boost::shared_ptr<apache::thrift::transport::TTransport>* wrapped_transport);
78 
84  boost::shared_ptr<apache::thrift::transport::TTransportFactory>* factory);
85 
86  virtual bool is_sasl() { return true; }
87 
91  Status InitKerberos(const std::string& principal, const std::string& keytab_path);
92 
95  void InitLdap() { has_ldap_ = true; }
96 
98  const std::string& principal() const { return principal_; }
99  const std::string& service_name() const { return service_name_; }
100  const std::string& hostname() const { return hostname_; }
101  const std::string& realm() const { return realm_; }
102  bool has_ldap() { return has_ldap_; }
103 
104  private:
106  bool has_ldap_;
107 
110  std::string hostname_;
111 
114 
116 
119  std::string principal_;
120 
122  std::string keytab_file_;
123 
127  std::string service_name_;
128 
130  std::string realm_;
131 
136 
138  boost::scoped_ptr<Thread> kinit_thread_;
139 
146  void RunKinit(Promise<Status>* first_kinit);
147 
149  static bool env_setup_complete_;
150 
153 };
154 
157 class NoAuthProvider : public AuthProvider {
158  public:
160 
161  virtual Status Start() { return Status::OK; }
162 
164  boost::shared_ptr<apache::thrift::transport::TTransportFactory>* factory);
165 
166  virtual Status WrapClientTransport(const std::string& hostname,
167  boost::shared_ptr<apache::thrift::transport::TTransport> raw_transport,
168  const std::string& service_name,
169  boost::shared_ptr<apache::thrift::transport::TTransport>* wrapped_transport);
170 
171  virtual bool is_sasl() { return false; }
172 };
173 
177 Status InitAuth(const std::string& appname);
178 
179 }
180 
181 #endif
Status InitKerberosEnv()
One-time kerberos-specific environment variable setup. Called by InitKerberos().
virtual Status GetServerTransportFactory(boost::shared_ptr< apache::thrift::transport::TTransportFactory > *factory)
bool is_internal_
True if internal, false if external.
virtual Status WrapClientTransport(const std::string &hostname, boost::shared_ptr< apache::thrift::transport::TTransport > raw_transport, const std::string &service_name, boost::shared_ptr< apache::thrift::transport::TTransport > *wrapped_transport)=0
const std::string & principal() const
Used for testing.
Definition: auth-provider.h:98
virtual Status GetServerTransportFactory(boost::shared_ptr< apache::thrift::transport::TTransportFactory > *factory)=0
bool has_ldap_
Do we (the server side only) support ldap for this connnection?
const std::string & hostname() const
Status InitKerberos(const std::string &principal, const std::string &keytab_path)
std::string principal_
All the rest of these private items are Kerberos-specific.
static bool env_setup_complete_
We use this to ensure that we only set up environment variables one time.
virtual bool is_sasl()
Returns true if this provider uses Sasl at the transport layer.
Definition: auth-provider.h:86
virtual bool is_sasl()
Returns true if this provider uses Sasl at the transport layer.
std::string keytab_file_
The full path to the keytab where the above principal can be found.
void RunKinit(Promise< Status > *first_kinit)
SaslAuthProvider(bool is_internal)
Definition: auth-provider.h:63
virtual Status Start()
Initialises any state required to perform authentication using this provider.
virtual Status Start()=0
Initialises any state required to perform authentication using this provider.
boost::scoped_ptr< Thread > kinit_thread_
Runs "RunKinit" below if needs_kinit_ is true.
virtual Status WrapClientTransport(const std::string &hostname, boost::shared_ptr< apache::thrift::transport::TTransport > raw_transport, const std::string &service_name, boost::shared_ptr< apache::thrift::transport::TTransport > *wrapped_transport)
const std::string & service_name() const
Definition: auth-provider.h:99
const std::string & realm() const
static const Status OK
Definition: status.h:87
std::string realm_
Principal's realm, again derived from principal.
virtual Status WrapClientTransport(const std::string &hostname, boost::shared_ptr< apache::thrift::transport::TTransport > raw_transport, const std::string &service_name, boost::shared_ptr< apache::thrift::transport::TTransport > *wrapped_transport)
virtual Status GetServerTransportFactory(boost::shared_ptr< apache::thrift::transport::TTransportFactory > *factory)
virtual bool is_sasl()=0
Returns true if this provider uses Sasl at the transport layer.
Status InitAuth(const std::string &appname)