diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 99564106a2..276813b500 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -66,9 +66,17 @@ namespace graphene { namespace app { bool login_api::login(const string& user, const string& password) { - optional< api_access_info > acc = _app.get_api_access_info( user ); + optional< api_access_info > acc; + // signal to connect to for the external acquisition of an api_access_info + api_access_info_external( user, acc ); + if( !acc.valid() ) - return false; + { + acc = _app.get_api_access_info( user ); + if( !acc.valid() ) + return false; + } + if( acc->password_hash_b64 != "*" ) { std::string password_salt = fc::base64_decode( acc->password_salt_b64 ); diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index de5bf8a334..6b9a6b5222 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -255,7 +255,11 @@ void application_impl::new_connection( const fc::http::websocket_connection_ptr& password = parts[1]; } - login->login(username, password); + bool external_login_active = false; + // signal to pass the login_api to an external login service + _self->login_attempt( external_login_active, username, password, *login ); + if( !external_login_active ) + login->login(username, password); } void application_impl::reset_websocket_server() @@ -406,7 +410,7 @@ void application_impl::startup() modified_genesis = true; ilog( - "Used genesis timestamp: ${timestamp} (PLEASE RECORD THIS)", + "Used genesis timestamp: ${timestamp} (PLEASE RECORD THIS)", ("timestamp", genesis.initial_timestamp.to_iso_string()) ); } @@ -514,7 +518,7 @@ void application_impl::startup() fc::path api_access_file = _options->at("api-access").as(); - FC_ASSERT( fc::exists(api_access_file), + FC_ASSERT( fc::exists(api_access_file), "Failed to load file from ${path}", ("path", api_access_file) ); _apiaccess = fc::json::from_file( api_access_file ).as( 20 ); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 191380091c..a3cd3d2b55 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -602,6 +602,10 @@ namespace graphene { namespace app { /// @brief Called to enable an API, not reflected. void enable_api( const string& api_name ); + + /// @brief Can be used to externally acquire the api_access_info for a user + boost::signals2::signal&)> api_access_info_external; + private: application& _app; diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index b9c37fb6c6..3308eb8b7b 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -69,6 +69,7 @@ namespace graphene { namespace app { uint64_t api_limit_get_withdraw_permissions_by_recipient = 101; }; + class login_api; class application { public: @@ -141,6 +142,9 @@ namespace graphene { namespace app { std::shared_ptr elasticsearch_thread; + /// Signal to reroute login requests + boost::signals2::signal< void(bool&, const string&, const string&, login_api&) > login_attempt; + private: void add_available_plugin( std::shared_ptr p ); std::shared_ptr my;