XRootD
SubpathMatch Class Referencefinal

#include <XrdSciTokensAccess.hh>

+ Collaboration diagram for SubpathMatch:

Public Member Functions

 SubpathMatch ()=default
 
 SubpathMatch (const AccessRulesRaw &rules)
 
bool apply (Access_Operation oper, const std::string_view path) const
 
bool empty () const
 
size_t size () const
 
std::string str () const
 

Detailed Description

Definition at line 88 of file XrdSciTokensAccess.hh.

Constructor & Destructor Documentation

◆ SubpathMatch() [1/2]

SubpathMatch::SubpathMatch ( )
default

◆ SubpathMatch() [2/2]

SubpathMatch::SubpathMatch ( const AccessRulesRaw rules)
inline

Definition at line 91 of file XrdSciTokensAccess.hh.

92  : m_rules(rules)
93  {}

Member Function Documentation

◆ apply()

bool SubpathMatch::apply ( Access_Operation  oper,
const std::string_view  path 
) const
inline

Definition at line 96 of file XrdSciTokensAccess.hh.

96  {
97  auto is_subdirectory = [](const std::string_view& dir, const std::string_view& subdir) {
98  if (subdir.size() < dir.size())
99  return false;
100 
101  if (subdir.compare(0, dir.size(), dir, 0, dir.size()) != 0)
102  return false;
103 
104  return dir.size() == subdir.size() || subdir[dir.size()] == '/' || dir == "/";
105  };
106 
107  for (const auto & rule : m_rules) {
108  // Skip rules that don't match the current operation
109  if (rule.first != oper)
110  continue;
111 
112  // If the rule allows any path, allow the operation
113  if (rule.second == "/")
114  return true;
115 
116  // Allow operation if path is a subdirectory of the rule's path
117  if (is_subdirectory(rule.second, path)) {
118  return true;
119  } else {
120  // Allow stat and mkdir of parent directories to comply with WLCG token specs
121  if (oper == AOP_Stat || oper == AOP_Mkdir)
122  if (is_subdirectory(path, rule.second))
123  return true;
124  }
125  }
126  return false;
127  }
@ AOP_Mkdir
mkdir()
@ AOP_Stat
exists(), stat()

References AOP_Mkdir, and AOP_Stat.

Referenced by XrdAccRules::apply().

+ Here is the caller graph for this function:

◆ empty()

bool SubpathMatch::empty ( ) const
inline

Definition at line 129 of file XrdSciTokensAccess.hh.

129 {return m_rules.empty();} // Returns true if there are no rules to match

Referenced by XrdAccRules::str().

+ Here is the caller graph for this function:

◆ size()

size_t SubpathMatch::size ( ) const
inline

Definition at line 133 of file XrdSciTokensAccess.hh.

133 {return m_rules.size();} // Returns the count of rules

Referenced by XrdAccRules::size().

+ Here is the caller graph for this function:

◆ str()

std::string SubpathMatch::str ( ) const

Definition at line 325 of file XrdSciTokensAccess.cc.

325  {
326  return AccessRuleStr(m_rules); // Returns a human-friendly representation of the access rules
327 }

Referenced by XrdAccRules::str().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: