123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef LIB_RPC_SASLPROTOCOL_H
- #define LIB_RPC_SASLPROTOCOL_H
- #include "hdfspp/status.h"
- #include "common/auth_info.h"
- #include "common/libhdfs_events_impl.h"
- #include <RpcHeader.pb.h>
- #include <memory>
- #include <mutex>
- #include <functional>
- namespace hdfs {
- static constexpr const char * SASL_METHOD_NAME = "sasl message";
- class RpcConnection;
- class SaslEngine;
- class SaslProtocol : public std::enable_shared_from_this<SaslProtocol>
- {
- public:
- SaslProtocol(const std::string &cluster_name,
- const AuthInfo & auth_info,
- std::shared_ptr<RpcConnection> connection);
- virtual ~SaslProtocol();
- void SetEventHandlers(std::shared_ptr<LibhdfsEvents> event_handlers);
- // Start the async authentication process. Must be called while holding the
- // connection lock, but all callbacks will occur outside of the connection lock
- void authenticate(std::function<void(const Status & status, const AuthInfo new_auth_info)> callback);
- void OnServerResponse(const Status & status, const hadoop::common::RpcSaslProto * response);
- private:
- enum State {
- kUnstarted,
- kNegotiate,
- kAuthenticate,
- kComplete
- };
- // Lock for access to members of the class
- std::mutex sasl_state_lock_;
- State state_;
- const std::string cluster_name_;
- AuthInfo auth_info_;
- std::weak_ptr<RpcConnection> connection_;
- std::function<void(const Status & status, const AuthInfo new_auth_info)> callback_;
- std::unique_ptr<SaslEngine> sasl_engine_;
- std::shared_ptr<LibhdfsEvents> event_handlers_;
- bool SendSaslMessage(hadoop::common::RpcSaslProto & message);
- bool AuthComplete(const Status & status, const AuthInfo & auth_info);
- void Negotiate(const hadoop::common::RpcSaslProto * response);
- void Challenge(const hadoop::common::RpcSaslProto * response);
- };
- }
- #endif /* LIB_RPC_SASLPROTOCOL_H */
|