Package com.tnsai.quality.security
Class ToolPermissionManager
java.lang.Object
com.tnsai.quality.security.ToolPermissionManager
Manages per-tool permission levels using the 3-tier model.
Default permission for all tools is PermissionLevel.ASK
(backward compatible with existing confirmation-based flows).
Usage
ToolPermissionManager manager = new ToolPermissionManager();
// Auto-execute safe tools
manager.setToolPermission("search_web", PermissionLevel.ALWAYS);
// Block destructive tools
manager.setToolPermission("file_delete", PermissionLevel.DENY);
// Check permission
PermissionLevel level = manager.getPermission("file_delete");
if (!level.allowsExecution()) {
throw new SecurityException("Tool blocked");
}
- Since:
- 0.2.3
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a manager withPermissionLevel.ASKas the default.ToolPermissionManager(PermissionLevel defaultLevel) Creates a manager with the specified default permission level. -
Method Summary
Modifier and TypeMethodDescriptionvoidclearAll()Clears all explicit tool permissions, reverting everything to default.voidclearToolPermission(String toolName) Removes any explicit permission for a tool, reverting to the default.static ToolPermissionManagerCreates a manager that denies unknown tools by default (secure-by-default).Returns all explicit tool permissions (unmodifiable view).Returns the default permission level.getPermission(String toolName) Gets the permission level for a tool.booleanChecks if tool execution is allowed (not DENY).booleanrequiresConfirmation(String toolName) Checks if tool requires confirmation.voidsetToolPermission(String toolName, PermissionLevel level) Sets the permission level for a specific tool.
-
Constructor Details
-
ToolPermissionManager
public ToolPermissionManager()Creates a manager withPermissionLevel.ASKas the default. Note: ASK allows execution — usedefaultDeny()for secure-by-default. -
ToolPermissionManager
Creates a manager with the specified default permission level.- Parameters:
defaultLevel- the default permission for tools without explicit configuration
-
-
Method Details
-
defaultDeny
Creates a manager that denies unknown tools by default (secure-by-default). Only explicitly allowed tools will be executable.- Returns:
- a deny-by-default permission manager
-
setToolPermission
Sets the permission level for a specific tool.- Parameters:
toolName- the tool name (case-insensitive via Locale.ROOT)level- the permission level
-
getPermission
Gets the permission level for a tool. Returns the default level if no explicit permission is set.- Parameters:
toolName- the tool name- Returns:
- the permission level
-
clearToolPermission
Removes any explicit permission for a tool, reverting to the default.- Parameters:
toolName- the tool name
-
isAllowed
Checks if tool execution is allowed (not DENY).- Parameters:
toolName- the tool name- Returns:
- true if the tool is allowed to execute
-
requiresConfirmation
Checks if tool requires confirmation.- Parameters:
toolName- the tool name- Returns:
- true if confirmation is required
-
getDefaultLevel
Returns the default permission level.- Returns:
- the default level
-
getAllPermissions
Returns all explicit tool permissions (unmodifiable view).- Returns:
- map of tool name to permission level
-
clearAll
public void clearAll()Clears all explicit tool permissions, reverting everything to default.
-