changeset 1079:e6d2ff8f1ab4 broker

credentials in HttpCommand
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Oct 2019 21:25:03 +0200
parents 53d9c3b96b9e
children f72d1ab42932
files Framework/Oracle/GenericOracleRunner.cpp Framework/Oracle/HttpCommand.cpp Framework/Oracle/HttpCommand.h
diffstat 3 files changed, 56 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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<const HttpCommand&>(command));
+          Execute(emitter_, receiver, dynamic_cast<const HttpCommand&>(command));
           break;
 
         case IOracleCommand::Type_OrthancRestApi:
--- 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);
+    }
+  }
 }
--- 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;
   };
 }