changeset 245:a56513c56d0d inbox

added support for groups in UserProfile
author Alain Mazy <am@orthanc.team>
date Tue, 01 Jul 2025 15:29:03 +0200
parents 940944c43bd7
children 26ca67fe0659
files NEWS Plugin/AuthorizationWebService.cpp Plugin/IAuthorizationService.h Plugin/Plugin.cpp
diffstat 4 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Jun 18 12:29:19 2025 +0200
+++ b/NEWS	Tue Jul 01 15:29:03 2025 +0200
@@ -11,6 +11,8 @@
   are provided):  The plugin will now request the auth-service to
   get an anonymous user profile even if there are no auth-tokens in the
   HTTP request.
+* The User profile can now contain a "groups" field if the auth-service
+  provides it.
 
 
 2025-06-11 - v 0.9.3
--- a/Plugin/AuthorizationWebService.cpp	Wed Jun 18 12:29:19 2025 +0200
+++ b/Plugin/AuthorizationWebService.cpp	Tue Jul 01 15:29:03 2025 +0200
@@ -34,6 +34,8 @@
   static const char* PERMISSIONS = "permissions";
   static const char* AUTHORIZED_LABELS = "authorized-labels";
   static const char* USER_NAME = "name";
+  static const char* GROUPS = "groups";
+
   
 
   bool AuthorizationWebService::IsGrantedInternal(unsigned int& validity,
@@ -341,6 +343,7 @@
     jsonProfile[USER_NAME] = profile.name;
     Orthanc::SerializationToolbox::WriteSetOfStrings(jsonProfile, profile.authorizedLabels, AUTHORIZED_LABELS);
     Orthanc::SerializationToolbox::WriteSetOfStrings(jsonProfile, profile.permissions, PERMISSIONS);
+    Orthanc::SerializationToolbox::WriteSetOfStrings(jsonProfile, profile.groups, GROUPS);
   }
     
   void AuthorizationWebService::FromJson(UserProfile& profile, const Json::Value& jsonProfile)
@@ -368,6 +371,14 @@
     {
       profile.authorizedLabels.insert(jsonProfile[AUTHORIZED_LABELS][i].asString());
     }
+
+    if (jsonProfile.isMember(GROUPS) && jsonProfile[GROUPS].isArray())
+    {
+      for (Json::ArrayIndex i = 0; i < jsonProfile[GROUPS].size(); ++i)
+      {
+        profile.groups.insert(jsonProfile[GROUPS][i].asString());
+      }
+    }
   }
 
 
--- a/Plugin/IAuthorizationService.h	Wed Jun 18 12:29:19 2025 +0200
+++ b/Plugin/IAuthorizationService.h	Tue Jul 01 15:29:03 2025 +0200
@@ -63,6 +63,7 @@
       std::string name;
       std::set<std::string> permissions;
       std::set<std::string> authorizedLabels;
+      std::set<std::string> groups;
 
       // the source token key/value that identified the user
       TokenType   tokenType;
--- a/Plugin/Plugin.cpp	Wed Jun 18 12:29:19 2025 +0200
+++ b/Plugin/Plugin.cpp	Tue Jul 01 15:29:03 2025 +0200
@@ -1247,6 +1247,8 @@
       Json::Value jsonProfile;
       jsonProfile["name"] = profile.name;
       jsonProfile["permissions"] = Json::arrayValue;
+      jsonProfile["groups"] = Json::arrayValue;
+      
       for (std::set<std::string>::const_iterator it = profile.permissions.begin(); it != profile.permissions.end(); ++it)
       {
         jsonProfile["permissions"].append(*it);
@@ -1255,6 +1257,10 @@
       {
         jsonProfile["authorized-labels"].append(*it);
       }
+      for (std::set<std::string>::const_iterator it = profile.groups.begin(); it != profile.groups.end(); ++it)
+      {
+        jsonProfile["groups"].append(*it);
+      }
 
       OrthancPlugins::AnswerJson(jsonProfile, output);
     }