changeset 54:317b31e99501

Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
author Alain Mazy <am@osimis.io>
date Mon, 26 Sep 2022 15:20:39 +0200
parents 01e0c35e004c
children 2ebe20e3d9a8 c02f0646297d
files NEWS Plugin/AuthorizationWebService.cpp Plugin/AuthorizationWebService.h Plugin/Plugin.cpp
diffstat 4 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri May 13 09:51:18 2022 +0200
+++ b/NEWS	Mon Sep 26 15:20:39 2022 +0200
@@ -1,6 +1,13 @@
 Pending changes in the mainline
 ===============================
 
+2022-09-26 - v 0.3.0
+====================
+
+* Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier.
+* The WebServiceIdentifier is now included in the payload sent to the WebService as the 
+  "identifier" field.
+
 
 2022-05-13 - v 0.2.5
 ====================
--- a/Plugin/AuthorizationWebService.cpp	Fri May 13 09:51:18 2022 +0200
+++ b/Plugin/AuthorizationWebService.cpp	Mon Sep 26 15:20:39 2022 +0200
@@ -72,6 +72,15 @@
       body["token-value"] = tokenValue;
     }
 
+    if (!identifier_.empty())
+    {
+      body["identifier"] = identifier_;
+    }
+    else
+    {
+      body["identifier"] = Json::nullValue;
+    }
+
     MemoryBuffer answerBody;
     MemoryBuffer answerHeaders;
     uint16_t httpStatus = 0;
@@ -148,4 +157,10 @@
     username_ = username;
     password_ = password;
   }
+
+  void AuthorizationWebService::SetIdentifier(const std::string& webServiceIdentifier)
+  {
+    identifier_ = webServiceIdentifier;
+  }
+
 }
--- a/Plugin/AuthorizationWebService.h	Fri May 13 09:51:18 2022 +0200
+++ b/Plugin/AuthorizationWebService.h	Mon Sep 26 15:20:39 2022 +0200
@@ -28,6 +28,7 @@
     std::string url_;
     std::string username_;
     std::string password_;
+    std::string identifier_;
 
     bool IsGrantedInternal(unsigned int& validity,
                            OrthancPluginHttpMethod method,
@@ -44,6 +45,8 @@
     void SetCredentials(const std::string& username,
                         const std::string& password);
 
+    void SetIdentifier(const std::string& webServiceIdentifier);
+
     virtual bool IsGranted(unsigned int& validity,
                            OrthancPluginHttpMethod method,
                            const AccessedResource& access,
--- a/Plugin/Plugin.cpp	Fri May 13 09:51:18 2022 +0200
+++ b/Plugin/Plugin.cpp	Mon Sep 26 15:20:39 2022 +0200
@@ -348,9 +348,24 @@
           }
         }
 
+        std::unique_ptr<OrthancPlugins::AuthorizationWebService> webService(new OrthancPlugins::AuthorizationWebService(url));
+
+        std::string webServiceIdentifier;
+        if (configuration.LookupStringValue(webServiceIdentifier, "WebServiceIdentifier"))
+        {
+          webService->SetIdentifier(webServiceIdentifier);
+        }
+
+        std::string webServiceUsername;
+        std::string webServicePassword;
+        if (configuration.LookupStringValue(webServiceUsername, "WebServiceUsername") && configuration.LookupStringValue(webServicePassword, "WebServicePassword"))
+        {
+          webService->SetCredentials(webServiceUsername, webServicePassword);
+        }
+
         authorizationService_.reset
           (new OrthancPlugins::CachedAuthorizationService
-           (new OrthancPlugins::AuthorizationWebService(url), factory));
+           (webService.release(), factory));
 
         OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);