Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signals for the external acquisition of an api_access_info #2051

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
10 changes: 7 additions & 3 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
);
}
Expand Down Expand Up @@ -514,7 +518,7 @@ void application_impl::startup()

fc::path api_access_file = _options->at("api-access").as<boost::filesystem::path>();

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<api_access>( 20 );
Expand Down
4 changes: 4 additions & 0 deletions libraries/app/include/graphene/app/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(const string&, fc::optional<api_access_info>&)> api_access_info_external;

private:

application& _app;
Expand Down
4 changes: 4 additions & 0 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace graphene { namespace app {
uint64_t api_limit_get_withdraw_permissions_by_recipient = 101;
};

class login_api;
class application
{
public:
Expand Down Expand Up @@ -141,6 +142,9 @@ namespace graphene { namespace app {

std::shared_ptr<fc::thread> 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<abstract_plugin> p );
std::shared_ptr<detail::application_impl> my;
Expand Down