diff Plugin/CachedAuthorizationService.cpp @ 72:e381ba725669

new PUT auth/tokens/{token-type} API route + updated interface with WebService
author Alain Mazy <am@osimis.io>
date Fri, 24 Feb 2023 18:13:36 +0100
parents 30fb3ce960d9
children 7381a7674b36
line wrap: on
line diff
--- a/Plugin/CachedAuthorizationService.cpp	Wed Feb 22 13:13:38 2023 +0100
+++ b/Plugin/CachedAuthorizationService.cpp	Fri Feb 24 18:13:36 2023 +0100
@@ -27,20 +27,36 @@
 {
   std::string CachedAuthorizationService::ComputeKey(OrthancPluginHttpMethod method,
                                                      const AccessedResource& access,
-                                                     const Token& token,
+                                                     const Token* token,
                                                      const std::string& tokenValue) const
   {
-    return (boost::lexical_cast<std::string>(method) + "|" +
-            boost::lexical_cast<std::string>(access.GetLevel()) + "|" +
-            access.GetOrthancId() + "|" + token.GetKey() + "|" + tokenValue);
+    if (token != NULL)
+    {
+      return (boost::lexical_cast<std::string>(method) + "|" +
+              boost::lexical_cast<std::string>(access.GetLevel()) + "|" +
+              access.GetOrthancId() + "|" + token->GetKey() + "|" + tokenValue);
+    }
+    else
+    {
+      return (boost::lexical_cast<std::string>(method) + "|" +
+              boost::lexical_cast<std::string>(access.GetLevel()) + "|" +
+              access.GetOrthancId() + "|anonymous");
+    }
   }
     
 
   std::string CachedAuthorizationService::ComputeKey(const std::string& permission,
-                                                     const Token& token,
+                                                     const Token* token,
                                                      const std::string& tokenValue) const
   {
-    return (permission + "|" + token.GetKey() + "|" + tokenValue);
+    if (token != NULL)
+    {
+      return (permission + "|" + token->GetKey() + "|" + tokenValue);
+    }
+    else
+    {
+      return (permission + "|anonymous");
+    }
   }
 
 
@@ -64,7 +80,7 @@
   {
     assert(decorated_.get() != NULL);
 
-    std::string key = ComputeKey(method, access, *token, tokenValue);
+    std::string key = ComputeKey(method, access, token, tokenValue);
     std::string value;
 
     if (cache_->Retrieve(value, key))
@@ -112,7 +128,7 @@
   {
     assert(decorated_.get() != NULL);
 
-    std::string key = ComputeKey(permission, *token, tokenValue);
+    std::string key = ComputeKey(permission, token, tokenValue);
     std::string value;
 
     if (cache_->Retrieve(value, key))