changeset 4182:1c9c2c41c015

When checking DICOM allowed methods, if there are multiple modalities with the same AET, differentiate them from the calling IP
author Alain Mazy <alain@mazy.be>
date Wed, 09 Sep 2020 14:46:59 +0200
parents 3576616904d3
children 32cda90ccf09
files NEWS OrthancServer/Sources/OrthancConfiguration.cpp OrthancServer/Sources/OrthancConfiguration.h OrthancServer/Sources/main.cpp
diffstat 4 files changed, 43 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Sep 07 15:08:52 2020 +0200
+++ b/NEWS	Wed Sep 09 14:46:59 2020 +0200
@@ -7,7 +7,8 @@
 * Underscores are now allowed in peers/modalities symbolic names
 * Fix compatibility with C-MOVE SCU requests issued by Ambra
 * Fix transcoding in C-MOVE SCP, in the case where "SynchronousCMove" is "true"
-
+* When checking DICOM allowed methods, if there are multiple modalities with the same AET, 
+  differentiate them from the calling IP
 
 Version 1.7.3 (2020-08-24)
 ==========================
--- a/OrthancServer/Sources/OrthancConfiguration.cpp	Mon Sep 07 15:08:52 2020 +0200
+++ b/OrthancServer/Sources/OrthancConfiguration.cpp	Wed Sep 09 14:46:59 2020 +0200
@@ -746,6 +746,23 @@
     return false;
   }
 
+  bool OrthancConfiguration::LookupDicomModalitiesUsingAETitle(std::list<RemoteModalityParameters>& modalities,
+                                                               const std::string& aet) const
+  {
+    modalities.clear();
+
+    for (Modalities::const_iterator it = modalities_.begin(); it != modalities_.end(); ++it)
+    {
+      if (IsSameAETitle(aet, it->second.GetApplicationEntityTitle()))
+      {
+        modalities.push_back(it->second);
+      }
+    }
+
+    return modalities.size() > 0;
+  }
+
+
 
   bool OrthancConfiguration::IsKnownAETitle(const std::string& aet,
                                             const std::string& ip) const
--- a/OrthancServer/Sources/OrthancConfiguration.h	Mon Sep 07 15:08:52 2020 +0200
+++ b/OrthancServer/Sources/OrthancConfiguration.h	Wed Sep 09 14:46:59 2020 +0200
@@ -202,6 +202,9 @@
     bool IsSameAETitle(const std::string& aet1,
                        const std::string& aet2) const;
 
+    bool LookupDicomModalitiesUsingAETitle(std::list<RemoteModalityParameters>& modalities,
+                                           const std::string& aet) const;
+
     bool LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality,
                                          const std::string& aet) const;
 
--- a/OrthancServer/Sources/main.cpp	Mon Sep 07 15:08:52 2020 +0200
+++ b/OrthancServer/Sources/main.cpp	Wed Sep 09 14:46:59 2020 +0200
@@ -323,10 +323,28 @@
     {
       OrthancConfiguration::ReaderLock lock;
 
-      RemoteModalityParameters modality;
-      if (lock.GetConfiguration().LookupDicomModalityUsingAETitle(modality, remoteAet))
+      std::list<RemoteModalityParameters> modalities;
+      if (lock.GetConfiguration().LookupDicomModalitiesUsingAETitle(modalities, remoteAet))
       {
-        return modality.IsRequestAllowed(type);
+        if (modalities.size() == 1) // don't check the IP if there's only one modality with this AET
+        {
+          return modalities.front().IsRequestAllowed(type);
+        }
+        else // if there are multiple modalities with the same AET, check the one matching this IP
+        {
+          for (std::list<RemoteModalityParameters>::const_iterator it = modalities.begin(); it != modalities.end(); ++it)
+          {
+            if (it->GetHost() == remoteIp)
+            {
+              return it->IsRequestAllowed(type);
+            }
+          }
+
+          LOG(WARNING) << "Unable to check DICOM authorization for AET " << remoteAet
+                       << " on IP " << remoteIp << ", " << modalities.size()
+                       << " modalites found with this AET but none of them matching the IP";
+        }
+        return false;
       }
       else
       {