changeset 218:24199565c7e6

use core HttpClient to enable SSL support
author Alain Mazy <am@orthanc.team>
date Thu, 27 Feb 2025 15:05:50 +0100 (2 months ago)
parents 380ac7bda84e
children e8feeebcf643
files CMakeLists.txt NEWS Plugin/AuthorizationWebService.cpp
diffstat 3 files changed, 63 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Thu Feb 27 12:47:43 2025 +0100
+++ b/CMakeLists.txt	Thu Feb 27 15:05:50 2025 +0100
@@ -32,7 +32,7 @@
 endif()
 
 # Parameters of the build
-set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
+set(STATIC_BUILD ON CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
 set(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages")
 set(ORTHANC_FRAMEWORK_SOURCE "${ORTHANC_FRAMEWORK_DEFAULT_SOURCE}" CACHE STRING "Source of the Orthanc source code (can be \"hg\", \"archive\", \"web\" or \"path\")")
 set(ORTHANC_FRAMEWORK_ARCHIVE "" CACHE STRING "Path to the Orthanc archive, if ORTHANC_FRAMEWORK_SOURCE is \"archive\"")
@@ -73,7 +73,7 @@
   set(ENABLE_MODULE_JOBS OFF)
   set(ENABLE_MODULE_DICOM OFF)
   set(ENABLE_WEB_CLIENT ON)
-
+  
   include(${ORTHANC_FRAMEWORK_ROOT}/../Resources/CMake/OrthancFrameworkConfiguration.cmake)
   include_directories(${ORTHANC_FRAMEWORK_ROOT})
 endif()
--- a/NEWS	Thu Feb 27 12:47:43 2025 +0100
+++ b/NEWS	Thu Feb 27 15:05:50 2025 +0100
@@ -1,3 +1,11 @@
+Pending changes in the mainline
+===============================
+
+* The plugin is now using the HttpClient from the Orthanc core instead of its
+  own HttpClient which should enable support for https since the plugin
+  is not built with SSL support.
+
+
 2025-02-27 - v 0.9.0
 ====================
 
--- a/Plugin/AuthorizationWebService.cpp	Thu Feb 27 12:47:43 2025 +0100
+++ b/Plugin/AuthorizationWebService.cpp	Thu Feb 27 15:05:50 2025 +0100
@@ -24,7 +24,6 @@
 
 #include <Logging.h>
 #include <Toolbox.h>
-#include <HttpClient.h>
 #include <algorithm>
 #include "SerializationToolbox.h"
 
@@ -99,20 +98,17 @@
       Orthanc::SerializationToolbox::WriteSetOfStrings(body, access.GetLabels(), "labels");
     }
 
-    Orthanc::WebServiceParameters authWebservice;
-
-    if (!username_.empty())
-    {
-      authWebservice.SetCredentials(username_, password_);
-    }
-
     std::string bodyAsString;
     Orthanc::Toolbox::WriteFastJson(bodyAsString, body);
 
-    Orthanc::HttpClient authClient(authWebservice, "");
+    HttpClient authClient;
     authClient.SetUrl(tokenValidationUrl_);
-    authClient.AssignBody(bodyAsString);
-    authClient.SetMethod(Orthanc::HttpMethod_Post);
+    if (!username_.empty())
+    {
+      authClient.SetCredentials(username_, password_);
+    }
+    authClient.SetBody(bodyAsString);
+    authClient.SetMethod(OrthancPluginHttpMethod_Post);
     authClient.AddHeader("Content-Type", "application/json");
     authClient.AddHeader("Expect", "");
     authClient.SetTimeout(10);
@@ -132,7 +128,8 @@
     }
       
     Json::Value answer;
-    authClient.ApplyAndThrowException(answer);
+    OrthancPlugins::HttpHeaders answerHeaders;
+    authClient.Execute(answerHeaders, answer);
 
     if (answer.type() != Json::objectValue ||
         !answer.isMember(GRANTED) ||
@@ -182,12 +179,6 @@
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "Can not create tokens if the 'WebServiceTokenValidationUrl' is not configured");
     }
-    Orthanc::WebServiceParameters authWebservice;
-
-    if (!username_.empty())
-    {
-      authWebservice.SetCredentials(username_, password_);
-    }
 
     Json::Value body;
 
@@ -200,15 +191,20 @@
     Json::Value tokenResponse;
     try
     {
-      Orthanc::HttpClient authClient(authWebservice, "");
+      HttpClient authClient;
       authClient.SetUrl(tokenDecoderUrl_);
-      authClient.AssignBody(bodyAsString);
-      authClient.SetMethod(Orthanc::HttpMethod_Post);
+      if (!username_.empty())
+      {
+        authClient.SetCredentials(username_, password_);
+      }
+      authClient.SetBody(bodyAsString);
+      authClient.SetMethod(OrthancPluginHttpMethod_Post);
       authClient.AddHeader("Content-Type", "application/json");
       authClient.AddHeader("Expect", "");
       authClient.SetTimeout(10);
 
-      authClient.ApplyAndThrowException(tokenResponse);
+      OrthancPlugins::HttpHeaders answerHeaders;
+      authClient.Execute(answerHeaders, tokenResponse);
 
       if (tokenResponse.isMember("redirect-url"))
       {
@@ -247,13 +243,6 @@
     }
     std::string url = Orthanc::Toolbox::JoinUri(tokenCreationBaseUrl_, tokenType);
 
-    Orthanc::WebServiceParameters authWebservice;
-
-    if (!username_.empty())
-    {
-      authWebservice.SetCredentials(username_, password_);
-    }
-
     Json::Value body;
 
     if (!id.empty())
@@ -301,15 +290,20 @@
     Json::Value tokenResponse;
     try
     {
-      Orthanc::HttpClient authClient(authWebservice, "");
+      HttpClient authClient;
       authClient.SetUrl(url);
-      authClient.AssignBody(bodyAsString);
-      authClient.SetMethod(Orthanc::HttpMethod_Put);
+      if (!username_.empty())
+      {
+        authClient.SetCredentials(username_, password_);
+      }
+      authClient.SetBody(bodyAsString);
+      authClient.SetMethod(OrthancPluginHttpMethod_Put);
       authClient.AddHeader("Content-Type", "application/json");
       authClient.AddHeader("Expect", "");
       authClient.SetTimeout(10);
 
-      authClient.ApplyAndThrowException(tokenResponse);
+      OrthancPlugins::HttpHeaders answerHeaders;
+      authClient.Execute(answerHeaders, tokenResponse);
 
       response.token = tokenResponse["token"].asString();
       response.url = tokenResponse["url"].asString();
@@ -370,13 +364,6 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "Can not get user profile if the 'WebServiceUserProfileUrl' is not configured");
     }
 
-    Orthanc::WebServiceParameters authWebservice;
-
-    if (!username_.empty())
-    {
-      authWebservice.SetCredentials(username_, password_);
-    }
-
     Json::Value body;
 
     if (token != NULL)
@@ -399,16 +386,21 @@
 
     try
     {
-      Orthanc::HttpClient authClient(authWebservice, "");
+      HttpClient authClient;
       authClient.SetUrl(userProfileUrl_);
-      authClient.AssignBody(bodyAsString);
-      authClient.SetMethod(Orthanc::HttpMethod_Post);
+      if (!username_.empty())
+      {
+        authClient.SetCredentials(username_, password_);
+      }
+      authClient.SetBody(bodyAsString);
+      authClient.SetMethod(OrthancPluginHttpMethod_Put);
       authClient.AddHeader("Content-Type", "application/json");
       authClient.AddHeader("Expect", "");
       authClient.SetTimeout(10);
 
       Json::Value jsonProfile;
-      authClient.ApplyAndThrowException(jsonProfile);
+      OrthancPlugins::HttpHeaders answerHeaders;
+      authClient.Execute(answerHeaders, jsonProfile);
 
       if (!jsonProfile.isMember(VALIDITY) ||
         jsonProfile[VALIDITY].type() != Json::intValue)
@@ -460,22 +452,20 @@
       return false;
     }
 
-    Orthanc::WebServiceParameters authWebservice;
-
-    if (!username_.empty())
-    {
-      authWebservice.SetCredentials(username_, password_);
-    }
-
     try
     {
-      Orthanc::HttpClient authClient(authWebservice, "");
+      HttpClient authClient;
       authClient.SetUrl(settingsRolesUrl_);
-      authClient.SetMethod(Orthanc::HttpMethod_Get);
+      if (!username_.empty())
+      {
+        authClient.SetCredentials(username_, password_);
+      }
+      authClient.SetMethod(OrthancPluginHttpMethod_Get);
       authClient.AddHeader("Expect", "");
       authClient.SetTimeout(10);
 
-      authClient.ApplyAndThrowException(roles);
+      OrthancPlugins::HttpHeaders answerHeaders;
+      authClient.Execute(answerHeaders, roles);
 
       return true;
     }
@@ -493,27 +483,25 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "Can not update settings-roles if the 'WebServiceSettingsRolesUrl' is not configured");
     }
 
-    Orthanc::WebServiceParameters authWebservice;
-
-    if (!username_.empty())
-    {
-      authWebservice.SetCredentials(username_, password_);
-    }
-
     try
     {
       std::string bodyAsString;
       Orthanc::Toolbox::WriteFastJson(bodyAsString, roles);
 
-      Orthanc::HttpClient authClient(authWebservice, "");
+      HttpClient authClient;
       authClient.SetUrl(settingsRolesUrl_);
-      authClient.AssignBody(bodyAsString);
-      authClient.SetMethod(Orthanc::HttpMethod_Put);
+      if (!username_.empty())
+      {
+        authClient.SetCredentials(username_, password_);
+      }
+      authClient.SetBody(bodyAsString);
+      authClient.SetMethod(OrthancPluginHttpMethod_Put);
       authClient.AddHeader("Content-Type", "application/json");
       authClient.AddHeader("Expect", "");
       authClient.SetTimeout(10);
 
-      authClient.ApplyAndThrowException(response);
+      OrthancPlugins::HttpHeaders answerHeaders;
+      authClient.Execute(answerHeaders, response);
 
       return true;
     }