Skip to content
Snippets Groups Projects
Verified Commit f73a2785 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: authentication

parent 9c80b382
No related branches found
No related tags found
No related merge requests found
Pipeline #9517 passed with warnings
Pipeline: caosdb-cppinttest

#9518

    ...@@ -49,7 +49,8 @@ if(NOT clang_tidy) ...@@ -49,7 +49,8 @@ if(NOT clang_tidy)
    message(STATUS "clang-tidy: Not found") message(STATUS "clang-tidy: Not found")
    else() else()
    message(STATUS "clang-tidy: ${clang_tidy}") message(STATUS "clang-tidy: ${clang_tidy}")
    set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" "--header-filter=connection.h" set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}"
    "--header-filter=caosdb/.*[^\(\.pb\.h\)]$"
    "--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*" "--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*"
    "--warnings-as-errors=*") "--warnings-as-errors=*")
    endif() endif()
    ......
    ...@@ -27,12 +27,15 @@ ...@@ -27,12 +27,15 @@
    * @date 2021-06-28 * @date 2021-06-28
    * @brief Configuration and setup of the client authentication. * @brief Configuration and setup of the client authentication.
    */ */
    #include <string>
    #include <iosfwd> #include <grpcpp/security/credentials.h> // for MetadataCredentialsPlugin
    #include <memory> #include <map> // for multimap
    #include <grpc/grpc.h> #include <memory> // for shared_ptr
    #include <grpcpp/security/credentials.h> #include <string> // for string
    #include "caosdb/utils.h" #include "caosdb/utils.h" // for base64_encode
    #include "grpcpp/impl/codegen/status.h" // for Status
    #include "grpcpp/impl/codegen/string_ref.h" // for string_ref
    namespace grpc { class AuthContext; }
    namespace caosdb { namespace caosdb {
    namespace authentication { namespace authentication {
    ...@@ -47,7 +50,7 @@ using grpc::string_ref; ...@@ -47,7 +50,7 @@ using grpc::string_ref;
    */ */
    class Authenticator { class Authenticator {
    public: public:
    virtual auto getCallCredentials() const [[nodiscard]] virtual auto getCallCredentials() const
    -> std::shared_ptr<grpc::CallCredentials> = 0; -> std::shared_ptr<grpc::CallCredentials> = 0;
    }; };
    ...@@ -64,10 +67,10 @@ private: ...@@ -64,10 +67,10 @@ private:
    public: public:
    MetadataCredentialsPluginImpl(std::string key, std::string value); MetadataCredentialsPluginImpl(std::string key, std::string value);
    Status auto
    GetMetadata(string_ref service_url, string_ref method_name, GetMetadata(string_ref service_url, string_ref method_name,
    const AuthContext &channel_auth_context, const AuthContext &channel_auth_context,
    std::multimap<grpc::string, grpc::string> *metadata) override; std::multimap<grpc::string, grpc::string> *metadata) -> Status override;
    }; };
    class PlainPasswordAuthenticator : public Authenticator { class PlainPasswordAuthenticator : public Authenticator {
    ...@@ -78,7 +81,7 @@ public: ...@@ -78,7 +81,7 @@ public:
    PlainPasswordAuthenticator(const std::string &username, PlainPasswordAuthenticator(const std::string &username,
    const std::string &password); const std::string &password);
    auto getCallCredentials() const [[nodiscard]] auto getCallCredentials() const
    -> std::shared_ptr<grpc::CallCredentials> override; -> std::shared_ptr<grpc::CallCredentials> override;
    }; };
    } // namespace authentication } // namespace authentication
    ......
    ...@@ -27,26 +27,13 @@ ...@@ -27,26 +27,13 @@
    * @date 2021-05-18 * @date 2021-05-18
    * @brief Configuration and setup of the connection. * @brief Configuration and setup of the connection.
    */ */
    #include <string> #include <iosfwd> // for ostream
    #include <iosfwd> #include <memory> // for shared_ptr, unique_ptr
    #include "caosdb/authentication.h" #include <string> // for string
    #include <memory> #include "caosdb/info/v1alpha1/main.grpc.pb.h" // for GeneralInfoService
    #include <grpc/grpc.h> namespace caosdb { namespace authentication { class Authenticator; } }
    #include <grpcpp/channel.h> namespace caosdb { namespace info { namespace v1alpha1 { class VersionInfo; } } }
    #include <grpcpp/client_context.h> namespace grpc { class ChannelCredentials; }
    #include <grpcpp/create_channel.h>
    #include <grpcpp/security/credentials.h>
    #include "caosdb/info/v1alpha1/main.grpc.pb.h"
    namespace grpc {
    class ChannelCredentials;
    } // namespace grpc
    namespace caosdb {
    namespace info {
    namespace v1alpha1 {
    class VersionInfo;
    } // namespace v1alpha1
    } // namespace info
    } // namespace caosdb
    namespace caosdb::connection { namespace caosdb::connection {
    using caosdb::authentication::Authenticator; using caosdb::authentication::Authenticator;
    ......
    ...@@ -52,14 +52,14 @@ inline auto load_string_file(const std::string &path) -> std::string { ...@@ -52,14 +52,14 @@ inline auto load_string_file(const std::string &path) -> std::string {
    * fall_back value. * fall_back value.
    */ */
    inline auto get_env_var(const std::string &key, const std::string &fall_back) inline auto get_env_var(const std::string &key, const std::string &fall_back)
    -> const std::string { -> std::string {
    const char *val = getenv(key.c_str()); const char *val = getenv(key.c_str());
    if (val == nullptr) { if (val == nullptr) {
    return fall_back; return fall_back;
    } else {
    const auto result = std::string(val);
    return result;
    } }
    auto result = std::string(val);
    return result;
    } }
    /** /**
    ......
    ...@@ -18,13 +18,14 @@ ...@@ -18,13 +18,14 @@
    * along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
    * *
    */ */
    #include <string>
    #include <memory>
    #include "caosdb/authentication.h" #include "caosdb/authentication.h"
    #include <grpcpp/impl/codegen/status.h> #include <grpcpp/impl/codegen/status.h> // for Status, Status::OK
    #include <grpcpp/impl/codegen/string_ref.h> #include <grpcpp/impl/codegen/string_ref.h> // for string_ref
    #include <map> #include <map> // for multimap
    #include <utility> #include <memory> // for allocator, shared_ptr
    #include <string> // for basic_string, operator+
    #include <utility> // for pair, move, make_pair
    #include "grpcpp/security/credentials.h" // for MetadataCredentialsFromP...
    namespace caosdb::authentication { namespace caosdb::authentication {
    using caosdb::utils::base64_encode; using caosdb::utils::base64_encode;
    ......
    ...@@ -19,20 +19,21 @@ ...@@ -19,20 +19,21 @@
    * along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
    * *
    */ */
    #include "caosdb/connection.h" #include "caosdb/connection.h"
    #include "caosdb/utils.h" #include <grpcpp/create_channel.h> // for CreateChannel
    #include "caosdb/authentication.h" #include <grpcpp/impl/codegen/client_context.h> // for ClientContext
    #include <grpcpp/create_channel.h> #include <grpcpp/impl/codegen/status.h> // for Status
    #include <grpcpp/impl/codegen/client_context.h> #include <grpcpp/security/credentials.h> // for SslCredentials
    #include <grpcpp/impl/codegen/status.h> #include <iostream> // for operator<<, basic_...
    #include <grpcpp/security/credentials.h> #include <stdexcept> // for runtime_error
    #include <iostream> #include <string> // for operator+, char_tr...
    #include <stdexcept> #include "caosdb/authentication.h" // for Authenticator
    #include <string> #include "caosdb/exceptions.h" // for AuthenticationError
    #include "caosdb/info/v1alpha1/main.grpc.pb.h" #include "caosdb/info/v1alpha1/main.grpc.pb.h" // for GeneralInfoService
    #include "caosdb/info/v1alpha1/main.pb.h" #include "caosdb/info/v1alpha1/main.pb.h" // for GetVersionInfoResp...
    #include "caosdb/exceptions.h" #include "caosdb/utils.h" // for load_string_file
    #include "grpcpp/impl/codegen/status_code_enum.h" // for StatusCode, UNAUTH...
    namespace grpc { class Channel; }
    namespace caosdb::connection { namespace caosdb::connection {
    using caosdb::authentication::Authenticator; using caosdb::authentication::Authenticator;
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment