Package com.tnsai.quality.security
Class ToolFilter
java.lang.Object
com.tnsai.quality.security.ToolFilter
Glob-based tool filtering with allow/deny patterns.
Supports glob patterns for bulk tool permission rules. Deny patterns always take precedence over allow patterns.
Pattern Syntax
*matches any sequence of characters (except separator)?matches exactly one character- Matching is case-insensitive (via
Locale.ROOT)
Evaluation Rules
- If tool matches any deny pattern: DENIED
- If allow patterns are configured and tool matches one: ALLOWED
- If allow patterns are configured but tool matches none: DENIED
- If no allow patterns configured: ALLOWED (open by default)
Usage
ToolFilter filter = ToolFilter.builder()
.allow("search_*", "file_read")
.deny("file_delete", "shell_*")
.build();
filter.isAllowed("search_web"); // true
filter.isAllowed("file_delete"); // false (deny takes precedence)
filter.isAllowed("shell_exec"); // false (matches shell_*)
filter.isAllowed("file_write"); // false (not in allow list)
- Since:
- 0.2.3
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic ToolFilterallowAll()Creates an open filter that allows everything.static ToolFilter.Builderbuilder()Creates a builder for ToolFilter.filterAllowed(List<String> toolNames) Filters a list of tool names, returning only the allowed ones.Returns the configured allow globs.Returns the configured deny globs.booleanReturns true if this filter has any allow patterns configured.booleanReturns true if this filter has any deny patterns configured.booleanChecks if a tool is allowed by this filter.booleanChecks if a tool is denied by this filter.
-
Method Details
-
allowAll
Creates an open filter that allows everything.- Returns:
- permissive filter
-
builder
Creates a builder for ToolFilter.- Returns:
- new builder
-
isAllowed
Checks if a tool is allowed by this filter.- Parameters:
toolName- the tool name to check- Returns:
- true if the tool is allowed
-
isDenied
Checks if a tool is denied by this filter.- Parameters:
toolName- the tool name to check- Returns:
- true if the tool is denied
-
filterAllowed
Filters a list of tool names, returning only the allowed ones.- Parameters:
toolNames- the tool names to filter- Returns:
- list of allowed tool names
-
getAllowGlobs
Returns the configured allow globs.- Returns:
- unmodifiable list of allow glob patterns
-
getDenyGlobs
Returns the configured deny globs.- Returns:
- unmodifiable list of deny glob patterns
-
hasAllowPatterns
public boolean hasAllowPatterns()Returns true if this filter has any allow patterns configured.- Returns:
- true if allowlist is non-empty
-
hasDenyPatterns
public boolean hasDenyPatterns()Returns true if this filter has any deny patterns configured.- Returns:
- true if denylist is non-empty
-