# HG changeset patch # User Sebastien Jodogne # Date 1571340303 -7200 # Node ID e6d2ff8f1ab4e7e5ecc36dfcbcc97ee4bb0e89de # Parent 53d9c3b96b9e6df9b413c846b3d83200ad6acc31 credentials in HttpCommand diff -r 53d9c3b96b9e -r e6d2ff8f1ab4 Framework/Oracle/GenericOracleRunner.cpp --- a/Framework/Oracle/GenericOracleRunner.cpp Thu Oct 17 18:36:52 2019 +0200 +++ b/Framework/Oracle/GenericOracleRunner.cpp Thu Oct 17 21:25:03 2019 +0200 @@ -98,6 +98,11 @@ CopyHttpHeaders(client, command.GetHttpHeaders()); + if (command.HasCredentials()) + { + client.SetCredentials(command.GetUsername().c_str(), command.GetPassword().c_str()); + } + if (command.GetMethod() == Orthanc::HttpMethod_Post || command.GetMethod() == Orthanc::HttpMethod_Put) { @@ -196,8 +201,7 @@ break; case IOracleCommand::Type_Http: - Execute(emitter_, receiver, - dynamic_cast(command)); + Execute(emitter_, receiver, dynamic_cast(command)); break; case IOracleCommand::Type_OrthancRestApi: diff -r 53d9c3b96b9e -r e6d2ff8f1ab4 Framework/Oracle/HttpCommand.cpp --- a/Framework/Oracle/HttpCommand.cpp Thu Oct 17 18:36:52 2019 +0200 +++ b/Framework/Oracle/HttpCommand.cpp Thu Oct 17 21:25:03 2019 +0200 @@ -76,4 +76,30 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); } } + + + const std::string& HttpCommand::GetUsername() const + { + if (HasCredentials()) + { + return username_; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + } + + + const std::string& HttpCommand::GetPassword() const + { + if (HasCredentials()) + { + return password_; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + } } diff -r 53d9c3b96b9e -r e6d2ff8f1ab4 Framework/Oracle/HttpCommand.h --- a/Framework/Oracle/HttpCommand.h Thu Oct 17 18:36:52 2019 +0200 +++ b/Framework/Oracle/HttpCommand.h Thu Oct 17 21:25:03 2019 +0200 @@ -69,6 +69,8 @@ std::string body_; HttpHeaders headers_; unsigned int timeout_; + std::string username_; + std::string password_; public: HttpCommand(); @@ -137,5 +139,27 @@ { return timeout_; } + + void SetCredentials(const std::string& username, + const std::string& password) + { + username_ = username; + password_ = password; + } + + void ClearCredentials() + { + username_.clear(); + password_.clear(); + } + + bool HasCredentials() const + { + return !username_.empty(); + } + + const std::string& GetUsername() const; + + const std::string& GetPassword() const; }; }