Class DefaultPermissionProvider

java.lang.Object
com.tnsai.quality.security.DefaultPermissionProvider
All Implemented Interfaces:
com.tnsai.security.PermissionProvider

public final class DefaultPermissionProvider extends Object implements com.tnsai.security.PermissionProvider
In-memory permission registry implementing PermissionProvider.

Permissions are stored per agent ID and can be granted/revoked at runtime. Thread-safe via ConcurrentHashMap.

Usage


 DefaultPermissionProvider provider = new DefaultPermissionProvider();
 provider.grant("agent-1", "file.write");
 provider.grant("agent-1", "shell.execute");

 provider.hasPermission("agent-1", "file.write"); // true
 provider.hasPermission("agent-2", "file.write"); // false
 
  • Constructor Details

    • DefaultPermissionProvider

      public DefaultPermissionProvider()
  • Method Details

    • hasPermission

      public boolean hasPermission(String agentId, String permission)
      Specified by:
      hasPermission in interface com.tnsai.security.PermissionProvider
    • getPermissions

      public Set<String> getPermissions(String agentId)
      Specified by:
      getPermissions in interface com.tnsai.security.PermissionProvider
    • grant

      public void grant(String agentId, String permission)
      Grants a permission to an agent.
      Parameters:
      agentId - the agent ID
      permission - the permission to grant
    • revoke

      public boolean revoke(String agentId, String permission)
      Revokes a permission from an agent.
      Parameters:
      agentId - the agent ID
      permission - the permission to revoke
      Returns:
      true if the permission was present and removed
    • revokeAll

      public void revokeAll(String agentId)
      Revokes all permissions from an agent.
      Parameters:
      agentId - the agent ID
    • grantAll

      public void grantAll(String agentId, Set<String> permissions)
      Grants multiple permissions to an agent.
      Parameters:
      agentId - the agent ID
      permissions - the permissions to grant