Class UnixDomainAgentProfilePolicy

java.lang.Object
org.snmp4j.agent.audit.DefaultAgentAuditPolicy
org.snmp4j.transport.unix.audit.UnixDomainAgentProfilePolicy
All Implemented Interfaces:
Serializable, EventListener, org.snmp4j.agent.audit.AgentAuditPolicy, org.snmp4j.agent.audit.FileAuditListener, org.snmp4j.agent.MOServerLookupListener, org.snmp4j.transport.TransportAuditListener

public class UnixDomainAgentProfilePolicy extends org.snmp4j.agent.audit.DefaultAgentAuditPolicy
The UnixDomainAgentProfilePolicy extends the DefaultAgentAuditPolicy by support for the "unix" address domain of UnixDomainAddress.

A Unix domain socket operation is always local, so the AgentPolicyProfile.NetworkAccess restrictions of the policy profile - which are based on the comparison of InetAddress instances and therefore not applicable to a socket file path - are not evaluated for such an operation. The file system operations that are necessary for a Unix domain socket operation are checked instead: the socket's (local) file path is matched against the allowed files and directories of the AgentPolicyProfile exactly like any other file access audited through DefaultAgentAuditPolicy.fileAudit(FileAuditEvent). The audited transport operation is mapped to the file operation it implies:

  • TransportAuditEvent.TransportOperation.LISTEN: FileAuditEvent.FileOperation.CREATE of the local socket file, because binding a Unix domain server socket creates that file.
  • TransportAuditEvent.TransportOperation.CLOSE: FileAuditEvent.FileOperation.DELETE of the local socket file, because closing the transport removes that file.
  • TransportAuditEvent.TransportOperation.SEND: FileAuditEvent.FileOperation.WRITE of the peer's socket file.
  • TransportAuditEvent.TransportOperation.RECEIVE: FileAuditEvent.FileOperation.READ of the peer's socket file.
For SEND and RECEIVE the local socket file is checked instead of the peer's file if the peer socket is unnamed (auto-bound), which is the regular case for an accepted client connection. Transport operations of any other address domain are audited by DefaultAgentAuditPolicy unchanged, thus this policy can be used for an agent that serves Unix domain sockets and IP transports at the same time.

Like its superclass, this policy denies a violating operation only on audit level AgentAuditLevel.RESTRICT.

Since:
1.2.2
Version:
1.2.2
Author:
Frank Fock
See Also:
  • Field Summary

    Fields inherited from class org.snmp4j.agent.audit.DefaultAgentAuditPolicy

    CONFIDENTIAL, DEFAULT, LOG, OFF, TEST, WARN
  • Constructor Summary

    Constructors
    Constructor
    Description
    UnixDomainAgentProfilePolicy(org.snmp4j.agent.audit.AgentPolicyProfile agentPolicyProfile, org.snmp4j.agent.audit.AgentAuditLevel auditLevel)
    Creates a UnixDomainAgentProfilePolicy that logs audit records through the LogFactory logging only.
    UnixDomainAgentProfilePolicy(org.snmp4j.agent.audit.AgentPolicyProfile agentPolicyProfile, org.snmp4j.agent.audit.AgentAuditLevel auditLevel, OutputStream auditOutputStream)
    Creates a UnixDomainAgentProfilePolicy that logs audit records through the LogFactory logging and, in addition, writes a copy of every audit record to the supplied OutputStream.
  • Method Summary

    Modifier and Type
    Method
    Description
    getAuditedSocketAddress(org.snmp4j.transport.TransportAuditEvent event)
    Determines the Unix domain address whose socket file is accessed by the audited transport operation.
    protected org.snmp4j.agent.audit.FileAuditEvent.FileOperation
    getImpliedFileOperation(org.snmp4j.transport.TransportAuditEvent.TransportOperation transportOperation)
    Maps an audited transport operation to the file operation it implies on the socket file of a Unix domain socket.
    protected static boolean
    Checks whether the supplied Unix domain address refers to a named socket, i.e. a socket that has a path in the file system.
    protected boolean
    isSocketFileAccessAllowed(org.snmp4j.transport.TransportAuditEvent event, UnixDomainAddress socketAddress)
    Checks whether the file access that the audited Unix domain socket operation needs on the socket file of the supplied address is permitted by the AgentPolicyProfile.
    protected boolean
    isTransportOperationAllowed(org.snmp4j.transport.TransportAuditEvent event)
    Evaluates whether the supplied transport operation is permitted by the AgentPolicyProfile.

    Methods inherited from class org.snmp4j.agent.audit.DefaultAgentAuditPolicy

    fileAudit, getAgentPolicyProfile, getAuditLevel, isFileOperationAllowed, isManagedObjectAccessAllowed, logDecision, lookupEvent, queryEvent, setAuditOutputStream, transportAudit

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.snmp4j.agent.audit.AgentAuditPolicy

    isAuditEnabled

    Methods inherited from interface org.snmp4j.agent.MOServerLookupListener

    completedUse
  • Constructor Details

    • UnixDomainAgentProfilePolicy

      public UnixDomainAgentProfilePolicy(org.snmp4j.agent.audit.AgentPolicyProfile agentPolicyProfile, org.snmp4j.agent.audit.AgentAuditLevel auditLevel)
      Creates a UnixDomainAgentProfilePolicy that logs audit records through the LogFactory logging only.
      Parameters:
      agentPolicyProfile - the policy profile that defines the access restrictions to enforce, or null to permit all operations (audit only).
      auditLevel - the audit level to apply, or null which is interpreted as AgentAuditLevel.OFF.
    • UnixDomainAgentProfilePolicy

      public UnixDomainAgentProfilePolicy(org.snmp4j.agent.audit.AgentPolicyProfile agentPolicyProfile, org.snmp4j.agent.audit.AgentAuditLevel auditLevel, OutputStream auditOutputStream)
      Creates a UnixDomainAgentProfilePolicy that logs audit records through the LogFactory logging and, in addition, writes a copy of every audit record to the supplied OutputStream.
      Parameters:
      agentPolicyProfile - the policy profile that defines the access restrictions to enforce, or null to permit all operations (audit only).
      auditLevel - the audit level to apply, or null which is interpreted as AgentAuditLevel.OFF.
      auditOutputStream - an optional output stream that receives a copy of every audit record (for example a FileOutputStream, System.out or System.err), or null for logging through LogFactory only.
  • Method Details

    • isTransportOperationAllowed

      protected boolean isTransportOperationAllowed(org.snmp4j.transport.TransportAuditEvent event)
      Evaluates whether the supplied transport operation is permitted by the AgentPolicyProfile. A Unix domain socket operation is evaluated by checking the socket file it operates on against the allowed files and directories of the policy profile (see isSocketFileAccessAllowed(TransportAuditEvent, UnixDomainAddress)), any other operation is evaluated by DefaultAgentAuditPolicy.
      Overrides:
      isTransportOperationAllowed in class org.snmp4j.agent.audit.DefaultAgentAuditPolicy
      Parameters:
      event - the transport audit event to evaluate.
      Returns:
      true if the operation is permitted by the policy profile, false otherwise.
    • isSocketFileAccessAllowed

      protected boolean isSocketFileAccessAllowed(org.snmp4j.transport.TransportAuditEvent event, UnixDomainAddress socketAddress)
      Checks whether the file access that the audited Unix domain socket operation needs on the socket file of the supplied address is permitted by the AgentPolicyProfile. The check is delegated to DefaultAgentAuditPolicy.isFileOperationAllowed(FileAuditEvent) with the file operation returned by getImpliedFileOperation(TransportAuditEvent.TransportOperation), so the same allowed files and directories apply as for any other file access of the agent.
      Parameters:
      event - the audited transport event.
      socketAddress - the Unix domain address whose socket file is accessed by the audited operation.
      Returns:
      true if the implied file operation is permitted by the policy profile, false otherwise.
    • getAuditedSocketAddress

      protected UnixDomainAddress getAuditedSocketAddress(org.snmp4j.transport.TransportAuditEvent event)
      Determines the Unix domain address whose socket file is accessed by the audited transport operation.
      Parameters:
      event - the audited transport event.
      Returns:
      the local UnixDomainAddress for TransportAuditEvent.TransportOperation.LISTEN and TransportAuditEvent.TransportOperation.CLOSE, the peer address for TransportAuditEvent.TransportOperation.SEND and TransportAuditEvent.TransportOperation.RECEIVE unless its socket is unnamed (then the local address is returned), or null if neither the peer nor the local address of the event is a UnixDomainAddress (i.e. the event does not refer to a Unix domain socket).
    • getImpliedFileOperation

      protected org.snmp4j.agent.audit.FileAuditEvent.FileOperation getImpliedFileOperation(org.snmp4j.transport.TransportAuditEvent.TransportOperation transportOperation)
      Maps an audited transport operation to the file operation it implies on the socket file of a Unix domain socket.
      Parameters:
      transportOperation - the audited transport operation.
      Returns:
      FileAuditEvent.FileOperation.CREATE for LISTEN (binding creates the socket file), FileAuditEvent.FileOperation.DELETE for CLOSE (closing removes the socket file), FileAuditEvent.FileOperation.WRITE for SEND, and FileAuditEvent.FileOperation.READ for RECEIVE.
    • hasSocketFile

      protected static boolean hasSocketFile(UnixDomainAddress address)
      Checks whether the supplied Unix domain address refers to a named socket, i.e. a socket that has a path in the file system.
      Parameters:
      address - a Unix domain address or null.
      Returns:
      true if address has a non-empty socket file path, false otherwise.