Class DefaultAgentAuditPolicy
java.lang.Object
org.snmp4j.agent.audit.DefaultAgentAuditPolicy
- All Implemented Interfaces:
Serializable, EventListener, AgentAuditPolicy, FileAuditListener, MOServerLookupListener, org.snmp4j.transport.TransportAuditListener
The default
AgentAuditPolicy implementation for SNMP4J-Agent. It enforces the access
restrictions defined by an AgentPolicyProfile and audits (logs) the relevant transport,
file and managed object access events according to the configured AgentAuditLevel:
AgentAuditLevel.OFF: auditing is disabled. No event is logged and all operations are permitted (this policy does not interfere).AgentAuditLevel.LOG: every audited operation is logged (at INFO level). No operation is denied.AgentAuditLevel.WARN: likeLOG, but operations that violate the policy profile are logged as warnings. No operation is denied.AgentAuditLevel.RESTRICT: likeWARN, and in addition operations that violate the policy profile are denied where this is possible, i.e. for the boolean returningtransportAudit(TransportAuditEvent)andfileAudit(FileAuditEvent)methods.
lookupEvent(MOServerLookupEvent) and
queryEvent(MOServerLookupEvent)) cannot be denied through these (void) listener callbacks -
the actual enforcement of managed object access is performed by the View-based Access Control Model
(VACM). This policy therefore audits managed object access and logs policy violations (as warnings
on WARN and RESTRICT level) so that misconfigurations and VACM gaps become visible.
Audit records are written through a LogAdapter obtained from LogFactory. In addition,
an optional OutputStream (backed for example by a file, System.out or
System.err) can be supplied to receive a copy of every audit record independent of the
logging configuration.
- Since:
- 3.12.0
- Version:
- 3.12.0
- Author:
- Frank Fock
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DefaultAgentAuditPolicystatic final DefaultAgentAuditPolicystatic final DefaultAgentAuditPolicystatic final DefaultAgentAuditPolicystatic final DefaultAgentAuditPolicystatic final DefaultAgentAuditPolicy -
Constructor Summary
ConstructorsConstructorDescriptionDefaultAgentAuditPolicy(AgentPolicyProfile agentPolicyProfile, AgentAuditLevel auditLevel) Creates aDefaultAgentAuditPolicythat logs audit records through theLogFactorylogging only.DefaultAgentAuditPolicy(AgentPolicyProfile agentPolicyProfile, AgentAuditLevel auditLevel, OutputStream auditOutputStream) Creates aDefaultAgentAuditPolicythat logs audit records through theLogFactorylogging and, in addition, writes a copy of every audit record to the suppliedOutputStream. -
Method Summary
Modifier and TypeMethodDescriptionbooleanfileAudit(FileAuditEvent event) Audits a file system operation described by the providedFileAuditEventand decides whether the operation is permitted.Gets the policy profile that defines the access restrictions enforced by this policy.Retrieves the current audit level for the agent.protected booleanEvaluates whether the supplied file operation is permitted by theAgentPolicyProfile.protected booleanEvaluates whether the managed object access described by the supplied lookup event conforms to theAgentPolicyProfile.protected booleanisTransportOperationAllowed(org.snmp4j.transport.TransportAuditEvent event) Evaluates whether the supplied transport operation is permitted by theAgentPolicyProfile.protected booleanlogDecision(boolean permittedByPolicy, boolean enforceable, String category, Object eventDescription) Logs the outcome of a policy decision according to the configuredAgentAuditLeveland returns whether the audited operation is permitted.voidlookupEvent(MOServerLookupEvent event) AMOServerinstance has looked up a managed object for which the listener has been registered.voidqueryEvent(MOServerLookupEvent event) AMOServerinstance is about to check if the managed object for which the listener had been registered matches a query.final voidsetAuditOutputStream(OutputStream auditOutputStream) Sets (or clears) the optional output stream that receives a copy of every audit record.booleantransportAudit(org.snmp4j.transport.TransportAuditEvent event) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AgentAuditPolicy
isAuditEnabledMethods inherited from interface MOServerLookupListener
completedUse
-
Field Details
-
OFF
-
LOG
-
DEFAULT
-
CONFIDENTIAL
-
WARN
-
TEST
-
-
Constructor Details
-
DefaultAgentAuditPolicy
Creates aDefaultAgentAuditPolicythat logs audit records through theLogFactorylogging only.- Parameters:
agentPolicyProfile- the policy profile that defines the access restrictions to enforce, ornullto permit all operations (audit only).auditLevel- the audit level to apply, ornullwhich is interpreted asAgentAuditLevel.OFF.
-
DefaultAgentAuditPolicy
public DefaultAgentAuditPolicy(AgentPolicyProfile agentPolicyProfile, AgentAuditLevel auditLevel, OutputStream auditOutputStream) Creates aDefaultAgentAuditPolicythat logs audit records through theLogFactorylogging and, in addition, writes a copy of every audit record to the suppliedOutputStream.- Parameters:
agentPolicyProfile- the policy profile that defines the access restrictions to enforce, ornullto permit all operations (audit only).auditLevel- the audit level to apply, ornullwhich is interpreted asAgentAuditLevel.OFF.auditOutputStream- an optional output stream that receives a copy of every audit record (for example aFileOutputStream,System.outorSystem.err), ornullfor logging throughLogFactoryonly.
-
-
Method Details
-
getAuditLevel
Description copied from interface:AgentAuditPolicyRetrieves the current audit level for the agent. The audit level specifies the behavior of the agent in logging and enforcing access to managed objects and transport operations.- Specified by:
getAuditLevelin interfaceAgentAuditPolicy- Returns:
- the current audit level, which can be one of the following:
OFF,LOG,WARN, orRESTRICT.
-
getAgentPolicyProfile
Gets the policy profile that defines the access restrictions enforced by this policy.- Returns:
- the
AgentPolicyProfileornullif all operations are permitted (audit only).
-
setAuditOutputStream
Sets (or clears) the optional output stream that receives a copy of every audit record. This can be used to write the audit trail to a dedicated file or toSystem.out/System.errin clear text, independent of theLogFactorylogging configuration.- Parameters:
auditOutputStream- the output stream to use, ornullto disable audit stream output.
-
fileAudit
Description copied from interface:FileAuditListenerAudits a file system operation described by the providedFileAuditEventand decides whether the operation is permitted.- Specified by:
fileAuditin interfaceFileAuditListener- Parameters:
event- theFileAuditEventdescribing the file operation to be audited.- Returns:
trueif the operation is permitted,falseto deny (prevent) it. The return value is ignored forFileAuditEvent.FileOperation.DELETEevents that report an already executed deletion.
-
transportAudit
public boolean transportAudit(org.snmp4j.transport.TransportAuditEvent event) - Specified by:
transportAuditin interfaceorg.snmp4j.transport.TransportAuditListener
-
lookupEvent
Description copied from interface:MOServerLookupListenerAMOServerinstance has looked up a managed object for which the listener has been registered.- Specified by:
lookupEventin interfaceMOServerLookupListener- Parameters:
event- aMOServerLookupEventdescribing the lookup query and the managed object that has been looked up.
-
queryEvent
Description copied from interface:MOServerLookupListenerAMOServerinstance is about to check if the managed object for which the listener had been registered matches a query. A managed object with dynamic content like a non-static table might use this event to update its content.- Specified by:
queryEventin interfaceMOServerLookupListener- Parameters:
event- aMOServerLookupEventdescribing the lookup query and the managed object that is to be queried.
-
isTransportOperationAllowed
protected boolean isTransportOperationAllowed(org.snmp4j.transport.TransportAuditEvent event) Evaluates whether the supplied transport operation is permitted by theAgentPolicyProfile.- Parameters:
event- the transport audit event to evaluate.- Returns:
trueif the operation is permitted by the policy profile,falseotherwise.
-
isFileOperationAllowed
Evaluates whether the supplied file operation is permitted by theAgentPolicyProfile.- Parameters:
event- the file audit event to evaluate.- Returns:
trueif the operation is permitted by the policy profile,falseotherwise.
-
isManagedObjectAccessAllowed
Evaluates whether the managed object access described by the supplied lookup event conforms to theAgentPolicyProfile. The result is used for auditing only (logging), since managed object access is enforced by VACM.- Parameters:
event- the managed object server lookup event to evaluate.- Returns:
trueif the access conforms to the policy profile,falseotherwise.
-
logDecision
protected boolean logDecision(boolean permittedByPolicy, boolean enforceable, String category, Object eventDescription) Logs the outcome of a policy decision according to the configuredAgentAuditLeveland returns whether the audited operation is permitted.- Parameters:
permittedByPolicy-trueif the operation conforms to the policy profile.enforceable-trueif the calling listener method can actually deny the operation (transport and file audits),falsefor observational audits (managed object lookups).category- a short category label for the audit record (e.g."TRANSPORT").eventDescription- the audited event (itstoString()is included in the audit record).- Returns:
trueif the operation is permitted (alwaystrueunless the level isAgentAuditLevel.RESTRICT, the operation violates the policy and isenforceable).
-