Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TSaslServerTransport.h
Go to the documentation of this file.
1 // This file will be removed when the code is accepted into the Thrift library.
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20 
21 #ifndef _THRIFT_TRANSPORT_TSASLSERVERTRANSPORT_H_
22 #define _THRIFT_TRANSPORT_TSASLSERVERTRANSPORT_H_ 1
23 
24 #include <string>
25 #include <pthread.h>
26 
27 #include <boost/shared_ptr.hpp>
28 #include <boost/thread/mutex.hpp>
29 #include <thrift/transport/TTransport.h>
30 #include "transport/TSasl.h"
32 
33 namespace apache { namespace thrift { namespace transport {
34 
43  private:
44  /* Handle the initial message from the client. */
45  virtual void handleSaslStartMessage();
46 
47  /* Structure that defines a Sasl Server. */
49  /* Mechanism implemented */
50  std::string mechanism_;
51 
52  /* Protocol */
53  std::string protocol_;
54 
55  /* Name of the server node. */
56  std::string serverName_;
57 
58  /* Realm - for Kerberos */
59  std::string realm_;
60 
61  /* Sasl Flags: see sasl.h */
62  unsigned flags_;
63 
64  /* Properties of this server. */
65  std::map<std::string, std::string> props_;
66 
67  /* Callbacks to the application program. */
68  std::vector<struct sasl_callback> callbacks_;
69 
70  TSaslServerDefinition(const std::string& mechanism, const std::string& protocol,
71  const std::string& serverName, const std::string& realm,
72  unsigned flags, const std::map<std::string, std::string>& props,
73  const std::vector<struct sasl_callback>& callbacks)
74  : mechanism_(mechanism),
75  protocol_(protocol),
76  serverName_(serverName),
77  realm_(realm),
78  flags_(flags),
79  props_(props),
80  callbacks_(callbacks) {
81  }
82  };
83 
84  /* Map from a mechanism to a server definition. */
85  std::map<std::string, TSaslServerDefinition*> serverDefinitionMap_;
86 
87  /* Wrap the passed transport in a transport for the defined server. */
88  TSaslServerTransport(const std::map<std::string, TSaslServerDefinition*>& serverMap,
89  boost::shared_ptr<TTransport> transport);
90 
91  public:
92 
98  TSaslServerTransport(boost::shared_ptr<TTransport> transport);
99 
103  TSaslServerTransport(const std::string& mechanism,
104  const std::string& protocol,
105  const std::string& serverName,
106  const std::string& realm,
107  unsigned flags,
108  const std::map<std::string, std::string>& props,
109  const std::vector<struct sasl_callback>& callbacks,
110  boost::shared_ptr<TTransport> transport);
111 
112  /* Add a definition to a server transport */
113  void addServerDefinition(const std::string& mechanism,
114  const std::string& protocol,
115  const std::string& serverName,
116  const std::string& realm,
117  unsigned int flags,
118  std::map<std::string, std::string> props,
119  std::vector<struct sasl_callback> callbacks) {
120  serverDefinitionMap_.insert(std::pair<std::string,
121  TSaslServerDefinition*>(mechanism,
122  new TSaslServerDefinition(mechanism,
123  protocol, serverName, realm, flags, props, callbacks)));
124  }
125 
126  /* Set the server */
127  void setSaslServer(sasl::TSasl* saslServer);
128 
133  class Factory : public TTransportFactory {
134  public:
136  }
141  Factory(const std::string& mechanism, const std::string& protocol,
142  const std::string& serverName, const std::string& realm,
143  unsigned flags, std::map<std::string, std::string> props,
144  std::vector<struct sasl_callback> callbacks)
145  : TTransportFactory() {
146  addServerDefinition(mechanism, protocol, serverName, realm, flags,
147  props, callbacks);
148  }
149 
150  virtual ~Factory() {}
151 
155  virtual boost::shared_ptr<TTransport> getTransport(
156  boost::shared_ptr<TTransport> trans);
157 
158  /* Add a definition to a server transport factory */
159  void addServerDefinition(const std::string& mechanism,
160  const std::string& protocol,
161  const std::string& serverName,
162  const std::string& realm,
163  unsigned int flags,
164  std::map<std::string, std::string> props,
165  std::vector<struct sasl_callback> callbacks) {
166  serverDefinitionMap_.insert(
167  std::pair<std::string, TSaslServerDefinition*>(mechanism,
168  new TSaslServerDefinition(mechanism, protocol,
169  serverName, realm, flags, props, callbacks)));
170  }
171  private:
172  /* Map for holding and returning server definitions. */
173  std::map<std::string, TSaslServerDefinition*> serverDefinitionMap_;
174 
175  /* Map from a transport to its Sasl Transport (wrapped by a TBufferedTransport). */
176  std::map<boost::shared_ptr<TTransport>,
177  boost::shared_ptr<TBufferedTransport> > transportMap_;
178 
179  /* Lock to synchronize the transport map. */
180  boost::mutex transportMap_mutex_;
181 
182  };
183 
184 };
185 
186 }}} // apache::thrift::transport
187 
188 #endif // #ifndef _THRIFT_TRANSPORT_TSSLSERVERTRANSPORT_H_
std::map< boost::shared_ptr< TTransport >, boost::shared_ptr< TBufferedTransport > > transportMap_
const StringSearch UrlParser::protocol_search & protocol
Definition: url-parser.cc:36
std::map< std::string, TSaslServerDefinition * > serverDefinitionMap_
TSaslServerTransport(const std::map< std::string, TSaslServerDefinition * > &serverMap, boost::shared_ptr< TTransport > transport)
Factory(const std::string &mechanism, const std::string &protocol, const std::string &serverName, const std::string &realm, unsigned flags, std::map< std::string, std::string > props, std::vector< struct sasl_callback > callbacks)
void addServerDefinition(const std::string &mechanism, const std::string &protocol, const std::string &serverName, const std::string &realm, unsigned int flags, std::map< std::string, std::string > props, std::vector< struct sasl_callback > callbacks)
void addServerDefinition(const std::string &mechanism, const std::string &protocol, const std::string &serverName, const std::string &realm, unsigned int flags, std::map< std::string, std::string > props, std::vector< struct sasl_callback > callbacks)
TSaslServerDefinition(const std::string &mechanism, const std::string &protocol, const std::string &serverName, const std::string &realm, unsigned flags, const std::map< std::string, std::string > &props, const std::vector< struct sasl_callback > &callbacks)
virtual boost::shared_ptr< TTransport > getTransport(boost::shared_ptr< TTransport > trans)
std::map< std::string, TSaslServerDefinition * > serverDefinitionMap_