Class FilesystemPolicy

java.lang.Object
eu.mrapik.minecraftservermcp.config.FilesystemPolicy

public final class FilesystemPolicy extends Object
Evaluates whether a path relative to the server root is allowed by ToolAccessConfig file/folder lists.

Semantics (high level):

  • null list = rule not in effect (no restriction from that list).
  • Empty list after parsing = deny-all for that dimension (whitelist with no entries blocks everything).
  • Folder whitelist/blacklist match path prefixes (directory containment).
  • File whitelist/blacklist match either exact relative paths or, for patterns without /, the final path segment (filename) anywhere under the tree.
Order of checks: normalize relative path → folder whitelist (if set) → folder blacklist → file whitelist → file blacklist.
  • Constructor Details

    • FilesystemPolicy

      public FilesystemPolicy(@Nullable @Nullable List<String> fileWhitelist, @Nullable @Nullable List<String> fileBlacklist, @Nullable @Nullable List<String> folderWhitelist, @Nullable @Nullable List<String> folderBlacklist)
      Internal constructor after optional list normalization.
      Parameters:
      fileWhitelist - normalized patterns, or null
      fileBlacklist - normalized patterns, or null
      folderWhitelist - normalized prefixes, or null
      folderBlacklist - normalized prefixes, or null
  • Method Details

    • fromToolConfig

      public static FilesystemPolicy fromToolConfig(ToolAccessConfig cfg)
      Builds a policy from the file-related fields of a tool config.
      Parameters:
      cfg - tool policy containing file/folder lists
      Returns:
      policy for allowsPath(String)
    • allowsPath

      public boolean allowsPath(String relativePathNormalized)
      Evaluates folder and file rules in order: folder whitelist, folder blacklist, file whitelist, file blacklist.
      Parameters:
      relativePathNormalized - path relative to server root, forward slashes, no leading slash
      Returns:
      true if all configured rules pass