Interface SecurityEnforcerHandle
This interface defines the security enforcement contract that
ActionExecutor uses. The concrete implementation
(SecurityEnforcer) lives in tnsai-quality
and is discovered via SpiLoader.
When tnsai-quality is not on the classpath, the factory returns a no-op
handle that retains undeclared legacy behavior but rejects declared access policies.
On an action whose target is not a Role, it also refuses the declared
@Security encryption, timeout and audit features and @AuditLog.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFactory for creating SecurityEnforcerHandle instances. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SecurityEnforcerHandleNo-op implementation used when tnsai-quality is absent. -
Method Summary
Modifier and TypeMethodDescriptionvoidaudit(ActionMetadata action, Role role, String callerAgentId, Map<String, Object> parameters, Object result, long durationMs) Logs audit information based on audit level.default voidaudit(ActionMetadata action, Object target, String callerAgentId, Map<String, Object> parameters, Object result, long durationMs) Logs audit information based on audit level and@AuditLog, for an action whose target is not aRole.default voidenforceAccess(AccessRequest request) Canonical role-independent access evaluation.voidenforceAccessControl(ActionMetadata action, Role role, String callerAgentId, Set<String> callerRoles) Enforces access control based on @Security annotation.<T> TexecuteWithTimeout(ActionMetadata action, Role role, Callable<T> task) Executes an action with security timeout enforcement.default <T> TexecuteWithTimeout(ActionMetadata action, Object target, Callable<T> task) Executes an action with security timeout enforcement, for an action whose target is not aRole.processParameters(ActionMetadata action, Role role, Map<String, Object> parameters) Processes parameters based on security settings.processParameters(ActionMetadata action, Object target, Map<String, Object> parameters) Processes parameters based on security settings, for an action whose target is not aRole.processResult(ActionMetadata action, Role role, Object result) Processes the result based on security settings.default ObjectprocessResult(ActionMetadata action, Object target, Object result) Processes the result based on security settings, for an action whose target is not aRole.default voidrequireHonored(ActionMetadata action, Object target) Refuses, before the action's body runs, an action whose target is not aRoleand whose features this handle cannot honor.
-
Field Details
-
NOOP
No-op implementation used when tnsai-quality is absent.
-
-
Method Details
-
enforceAccess
Canonical role-independent access evaluation. Implementations predating this contract cannot silently authorize declared policies. Optional providers stay outside core; the default is deliberately fail-closed. -
enforceAccessControl
void enforceAccessControl(ActionMetadata action, Role role, String callerAgentId, Set<String> callerRoles) Enforces access control based on @Security annotation.- Parameters:
action- the action metadatarole- the role containing the actioncallerAgentId- the ID of the calling agent (null if unknown)callerRoles- the roles of the calling agent- Throws:
SecurityException- if access is denied
-
processParameters
Map<String,Object> processParameters(ActionMetadata action, Role role, Map<String, Object> parameters) Processes parameters based on security settings.- Parameters:
action- the action metadatarole- the role containing the actionparameters- the original parameters- Returns:
- processed parameters (encrypted if required)
-
executeWithTimeout
Executes an action with security timeout enforcement.- Type Parameters:
T- the result type- Parameters:
action- the action metadatarole- the role containing the actiontask- the task to execute- Returns:
- the execution result
-
processResult
Processes the result based on security settings.- Parameters:
action- the action metadatarole- the role containing the actionresult- the original result- Returns:
- processed result (encrypted if required)
-
audit
void audit(ActionMetadata action, Role role, String callerAgentId, Map<String, Object> parameters, Object result, long durationMs) Logs audit information based on audit level.- Parameters:
action- the action metadatarole- the role containing the actioncallerAgentId- the caller agent IDparameters- the action parametersresult- the action resultdurationMs- execution duration in milliseconds
-
requireHonored
Refuses, before the action's body runs, an action whose target is not aRoleand whose features this handle cannot honor. The executor calls it beforeprocessParameters(ActionMetadata, Object, Map).The default refuses when the action declares any feature the target-typed methods carry (
encryptParams,encryptResult, asecurityTimeout, an audit level or@AuditLog), so a handle that overrides only some of those methods is refused before the body runs, never after it. A handle that honors all four overrides this method to do nothing.- Parameters:
action- the action metadatatarget- the object containing the action- Throws:
SecurityException-UNAUTHORIZEDwhen the handle cannot honor a declared feature
-
processParameters
default Map<String,Object> processParameters(ActionMetadata action, Object target, Map<String, Object> parameters) Processes parameters based on security settings, for an action whose target is not aRole.The action's
@Securityfeatures areSecurityFeatures.of(Object, java.lang.reflect.Method): every@Securityon the target's class hierarchy, the action method and the methods it overrides. The default refuses asrequireHonored(ActionMetadata, Object)does, and otherwise returnsparametersunchanged. A handle overrides all four target-typed methods andrequireHonored, or none of them.- Parameters:
action- the action metadatatarget- the object containing the actionparameters- the original parameters- Returns:
- processed parameters (encrypted if required)
- Throws:
SecurityException-UNAUTHORIZEDwhen the default cannot honor a declared feature
-
executeWithTimeout
default <T> T executeWithTimeout(ActionMetadata action, Object target, Callable<T> task) throws Exception Executes an action with security timeout enforcement, for an action whose target is not aRole. A failure oftaskpropagates unchanged.The default refuses when the action declares a
securityTimeout, and otherwise callstaskon the calling thread.- Type Parameters:
T- the result type- Parameters:
action- the action metadatatarget- the object containing the actiontask- the task to execute- Returns:
- the execution result
- Throws:
Exception- whatevertaskthrowsSecurityException-UNAUTHORIZEDwhen the default cannot honor a declared timeout
-
processResult
Processes the result based on security settings, for an action whose target is not aRole.The default refuses when the action declares
encryptResult, and otherwise returnsresultunchanged.- Parameters:
action- the action metadatatarget- the object containing the actionresult- the original result- Returns:
- processed result (encrypted if required)
- Throws:
SecurityException-UNAUTHORIZEDwhen the default cannot honor a declared encryption
-
audit
default void audit(ActionMetadata action, Object target, String callerAgentId, Map<String, Object> parameters, Object result, long durationMs) Logs audit information based on audit level and@AuditLog, for an action whose target is not aRole.The default refuses when the action declares an audit level or
@AuditLog, and otherwise does nothing.- Parameters:
action- the action metadatatarget- the object containing the actioncallerAgentId- the caller agent IDparameters- the action parametersresult- the action resultdurationMs- execution duration in milliseconds- Throws:
SecurityException-UNAUTHORIZEDwhen the default cannot honor a declared audit
-