Module org.snmp4j
Package org.snmp4j

Class DirectUserTarget<A extends Address>

All Implemented Interfaces:
Serializable, Cloneable, Target<A>

public class DirectUserTarget<A extends Address> extends UserTarget<A>
User-based target for SNMPv3 User-Based Security Model USM or later that includes any necessary authentication and privacy information, i.e., protocol references and localized keys. In contrast to the base class UserTarget, the DirectUserTarget does not refer to user information of a USM Local Configuration Storage except for caching engine times and boot counter for the authoritative engine ID.
Since:
3.4.0
Version:
3.9.3
Author:
Frank Fock
See Also:
  • Constructor Details

    • DirectUserTarget

      public DirectUserTarget()
      Creates a target for a user-based security model target.
    • DirectUserTarget

      public DirectUserTarget(UserTarget<A> userTarget)
      Creates a target for a user-based security model target without referencing security information from elsewhere.
      Parameters:
      userTarget - the target based on an USM.
    • DirectUserTarget

      public DirectUserTarget(A address, OctetString securityName, byte[] authoritativeEngineID, AuthenticationProtocol authenticationProtocol, OctetString authenticationKey, PrivacyProtocol privacyProtocol, OctetString privacyKey)
      Creates an SNMPv3 USM target with the supplied security level, one second time-out without retries. The security level is deducted from the keys given (authenticationKey and privacyKey). If both are null or have zero-length, SecurityLevel.noAuthNoPriv is used; if authenticationKey is given but privacyKey not, then SecurityLevel.authNoPriv, and SecurityLevel.authPriv otherwise.
      Parameters:
      address - the transport Address of the target.
      securityName - the USM security name to be used to access the target.
      authoritativeEngineID - the authoritative engine ID as a possibly zero-length byte array which must not be null.
      authenticationProtocol - the authentication protocol to be used (or null for SecurityLevel.noAuthNoPriv.
      authenticationKey - the localized authentication key (localized with the authoritativeEngineID) that will be used for this target instead of looking up the authentication key from the USM.
      privacyProtocol - the privacy protocol to be used (or null for SecurityLevel.noAuthNoPriv or SecurityLevel.authNoPriv.
      privacyKey - the localized privacy key (localized with the authoritativeEngineID) that will be used for this target instead of looking up the privacy key from the USM.
      Since:
      3.4.0
    • DirectUserTarget

      public DirectUserTarget(A address, OctetString securityName, AuthenticationProtocol authenticationProtocol, OctetString authenticationPassphrase, PrivacyProtocol privacyProtocol, OctetString privacyPassphrase)
      Creates an SNMPv3 USM target with the supplied security level, one second time-out without retries. The security level is deducted from the passphrases given (authenticationPassphrase and privacyPassphrase). If both are null or have zero-length, SecurityLevel.noAuthNoPriv is used; if authenticationPassphrase is given but privacyPassphrase not, then SecurityLevel.authNoPriv, and SecurityLevel.authPriv otherwise. This constructor sets the UserTarget.authoritativeEngineID to new byte[0], which means that the authoritative engine ID needs to be either looked up from the USM or discovered by the SNMPv3 MPv3 model before sending a request to this target by calling setAuthenticationKey(OctetString) with a non-zero length engine ID which will then internally call localize(byte[]) to localize the provided passphrases for that engine ID.
      Parameters:
      address - the transport Address of the target.
      securityName - the USM security name to be used to access the target.
      authenticationProtocol - the authentication protocol to be used (or null for SecurityLevel.noAuthNoPriv.
      authenticationPassphrase - the localized authentication key that will be localized when actually sending a request to this target instead of looking up the authentication key from the USM.
      privacyProtocol - the privacy protocol to be used (or null for SecurityLevel.noAuthNoPriv or SecurityLevel.authNoPriv.
      privacyPassphrase - the non-localized privacy passphrase that will be localized when actually sending a request to this target instead of looking up the privacy key from the USM.
      Since:
      3.9.3
  • Method Details

    • getAuthenticationKey

      public OctetString getAuthenticationKey()
      Gets the authentication key associated directly with this user target (without USM user table lookup). If null is returned and the AbstractTarget.securityLevel is not SecurityLevel.noAuthNoPriv, then the authentication must be looked up from a USM instance, when sending a SNMPv3 message to a target,
      Returns:
      the localized authentication key directly associated with this target.
      Since:
      3.4.0
    • setAuthenticationKey

      public void setAuthenticationKey(OctetString authenticationKey)
      Sets the authentication key (localized for the UserTarget.authoritativeEngineID) to be used for this target directly. Note: This has no effect unless AbstractTarget.securityLevel is SecurityLevel.authNoPriv or SecurityLevel.authPriv.
      Parameters:
      authenticationKey - the localized authentication key (localized with the authoritativeEngineID) that will be used for this target instead of looking up the authentication key from the USM by the AbstractTarget.securityName.
      Since:
      3.4.0
    • getPrivacyKey

      public OctetString getPrivacyKey()
      Gets the privacy key associated directly with this user target (without USM user table lookup). If null is returned and the AbstractTarget.securityLevel is SecurityLevel.authPriv then the privacy key must be looked up from a USM instance, when sending a SNMPv3 message to a target.
      Returns:
      the localized privacy key directly associated with this target.
      Since:
      3.4.0
    • setPrivacyKey

      public void setPrivacyKey(OctetString privacyKey)
      Sets the privacy key (localized for the UserTarget.authoritativeEngineID) to be used for this target directly. Note: This has no effect unless authenticationKey is also set and AbstractTarget.securityLevel is SecurityLevel.authPriv.
      Parameters:
      privacyKey - the localized privacy key (localized with the authoritativeEngineID) that will be used for this target instead of looking up the privacy key from the USM by the AbstractTarget.securityName.
      Since:
      3.4.0
    • getAuthenticationProtocol

      public AuthenticationProtocol getAuthenticationProtocol()
      Get the AuthenticationProtocol associated with this target or null if there is no direct user information provided but referenced by the AbstractTarget.securityName from the USM or if there is no authentication.
      Returns:
      the (optional) authentication protocol associated with this target by direct reference (i.e., not via USM).
      Since:
      3.4.0
    • setAuthenticationProtocol

      public void setAuthenticationProtocol(AuthenticationProtocol authenticationProtocol)
      Set the AuthenticationProtocol associated with this target or null if there is no direct user information provided but referenced by the AbstractTarget.securityName from the USM or if there is no authentication.
      Parameters:
      authenticationProtocol - the (optional) authentication protocol associated with this target by direct reference (i.e., not via USM).
      Since:
      3.4.0
    • getPrivacyProtocol

      public PrivacyProtocol getPrivacyProtocol()
      Get the PrivacyProtocol associated with this target or null if there is no direct user information provided but referenced by the AbstractTarget.securityName from the USM or there is no privacy.
      Returns:
      the (optional) privacy protocol associated with this target by direct reference (i.e., not via USM).
      Since:
      3.4.0
    • setPrivacyProtocol

      public void setPrivacyProtocol(PrivacyProtocol privacyProtocol)
      /** Set the PrivacyProtocol associated with this target or null if there is no direct user information provided but referenced by the AbstractTarget.securityName from the USM or if there is no privacy.
      Parameters:
      privacyProtocol - the (optional) privacy protocol associated with this target by direct reference (i.e., not via USM).
      Since:
      3.4.0
    • toString

      public String toString()
      Overrides:
      toString in class UserTarget<A extends Address>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class UserTarget<A extends Address>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class UserTarget<A extends Address>
    • duplicate

      public Target<A> duplicate()
      Description copied from interface: Target
      Creates a new copy of this target with the same address type.
      Specified by:
      duplicate in interface Target<A extends Address>
      Overrides:
      duplicate in class UserTarget<A extends Address>
      Returns:
      a copy of this target with the same address type.
    • setAuthoritativeEngineID

      public void setAuthoritativeEngineID(byte[] authoritativeEngineID)
      Sets the authoritative engine ID of this target. If the authoritative engine ID has currently a length of zero and getAuthenticationKey() is not null then localize(byte[]) is being called with the provided authoritative engine ID to localize the provisioned auth and priv passphrases with the discovered authoritative engine ID.
      Overrides:
      setAuthoritativeEngineID in class UserTarget<A extends Address>
      Parameters:
      authoritativeEngineID - a possibly zero-length byte array (must not be null).
      Since:
      3.9.3