- java.lang.Object
-
- org.snmp4j.security.UsmUser
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<UsmUser>
,User
public class UsmUser extends java.lang.Object implements User, java.lang.Comparable<UsmUser>, java.lang.Cloneable
TheUsmUser
class represents USM user providing information to secure SNMPv3 message exchange. A user is characterized by its security name and optionally by a authentication protocol and passphrase as well as a privacy protocol and passphrase.There are no setters for the attributes of this class, to prevent inconsistent states in the USM, when a user is changed from outside.
- Version:
- 3.6.1
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private SecretOctetString
authenticationPassphrase
private OID
authenticationProtocol
private OctetString
localizationEngineID
private SecretOctetString
privacyPassphrase
private OID
privacyProtocol
private OctetString
securityName
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description UsmUser(OctetString securityName, OID authenticationProtocol, OctetString authenticationPassphrase, OID privacyProtocol, OctetString privacyPassphrase)
Creates a USM user.UsmUser(OctetString securityName, OID authenticationProtocol, OctetString authenticationPassphrase, OID privacyProtocol, OctetString privacyPassphrase, OctetString localizationEngineID)
Creates a localized USM user.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
int
compareTo(UsmUser other)
Compares two USM users by their security names.boolean
equals(java.lang.Object o)
OctetString
getAuthenticationPassphrase()
Gets the authentication passphrase.OID
getAuthenticationProtocol()
Gets the authentication protocol ID.OctetString
getLocalizationEngineID()
Returns the localization engine ID for which this USM user has been already localized.OctetString
getPrivacyPassphrase()
Gets the privacy passphrase.OID
getPrivacyProtocol()
Gets the privacy protocol ID.int
getSecurityModel()
Gets the security model ID of the USM.OctetString
getSecurityName()
Gets the user's security name.int
hashCode()
boolean
isLocalized()
Indicates whether the passphrases of this USM user need to be localized or not (true
is returned in that case).UsmUser
localizeUser(OctetString localizationEngineID, OctetString localizedAuthenticationKey, OctetString localizedPrivacyKey, SecurityProtocols securityProtocols)
Return a copy of the current user with (updated) localized keys.java.lang.String
toString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
securityName
private final OctetString securityName
-
authenticationPassphrase
private final SecretOctetString authenticationPassphrase
-
privacyPassphrase
private final SecretOctetString privacyPassphrase
-
authenticationProtocol
private final OID authenticationProtocol
-
privacyProtocol
private final OID privacyProtocol
-
localizationEngineID
private OctetString localizationEngineID
-
-
Constructor Detail
-
UsmUser
public UsmUser(OctetString securityName, OID authenticationProtocol, OctetString authenticationPassphrase, OID privacyProtocol, OctetString privacyPassphrase)
Creates a USM user.- Parameters:
securityName
- the security name of the user (typically the user name).authenticationProtocol
- the authentication protocol ID to be associated with this user. If set tonull
, this user only supports unauthenticated messages.authenticationPassphrase
- the authentication passphrase. If notnull
,authenticationProtocol
must also be notnull
. RFC3414 §11.2 requires passphrases to have a minimum length of 8 bytes. If the length ofauthenticationPassphrase
is less than 8 bytes anIllegalArgumentException
is thrown.privacyProtocol
- the privacy protocol ID to be associated with this user. If set tonull
, this user only supports unencrypted messages.privacyPassphrase
- the privacy passphrase. If notnull
,privacyProtocol
must also be notnull
. RFC3414 §11.2 requires passphrases to have a minimum length of 8 bytes. If the length ofauthenticationPassphrase
is less than 8 bytes anIllegalArgumentException
is thrown.
-
UsmUser
public UsmUser(OctetString securityName, OID authenticationProtocol, OctetString authenticationPassphrase, OID privacyProtocol, OctetString privacyPassphrase, OctetString localizationEngineID)
Creates a localized USM user.- Parameters:
securityName
- the security name of the user (typically the user name).authenticationProtocol
- the authentication protcol ID to be associated with this user. If set tonull
, this user only supports unauthenticated messages.authenticationPassphrase
- the authentication passphrase. If notnull
,authenticationProtocol
must also be notnull
. RFC3414 §11.2 requires passphrases to have a minimum length of 8 bytes. If the length ofauthenticationPassphrase
is less than 8 bytes anIllegalArgumentException
is thrown.privacyProtocol
- the privacy protocol ID to be associated with this user. If set tonull
, this user only supports unencrypted messages.privacyPassphrase
- the privacy passphrase. If notnull
,privacyProtocol
must also be notnull
. RFC3414 §11.2 requires passphrases to have a minimum length of 8 bytes. If the length ofauthenticationPassphrase
is less than 8 bytes anIllegalArgumentException
is thrown.localizationEngineID
- if notnull
, the localizationEngineID specifies the engine ID for which the supplied passphrases are already localized. Such an USM user can only be used with the target whose engine ID equals localizationEngineID.
-
-
Method Detail
-
getSecurityName
public OctetString getSecurityName()
Gets the user's security name.- Returns:
- a clone of the user's security name.
-
getAuthenticationProtocol
public OID getAuthenticationProtocol()
Gets the authentication protocol ID.- Returns:
- a clone of the authentication protocol ID or
null
.
-
getPrivacyProtocol
public OID getPrivacyProtocol()
Gets the privacy protocol ID.- Returns:
- a clone of the privacy protocol ID or
null
.
-
getAuthenticationPassphrase
public OctetString getAuthenticationPassphrase()
Gets the authentication passphrase.- Returns:
- a clone of the authentication passphrase or
null
.
-
getPrivacyPassphrase
public OctetString getPrivacyPassphrase()
Gets the privacy passphrase.- Returns:
- a clone of the privacy passphrase or
null
.
-
getLocalizationEngineID
public OctetString getLocalizationEngineID()
Returns the localization engine ID for which this USM user has been already localized.- Returns:
null
if this USM user is not localized or the SNMP engine ID of the target for which this user has been localized.- Since:
- 1.6
-
isLocalized
public boolean isLocalized()
Indicates whether the passphrases of this USM user need to be localized or not (true
is returned in that case).- Returns:
true
if the passphrases of this USM user represent localized keys.- Since:
- 1.6
-
getSecurityModel
public int getSecurityModel()
Gets the security model ID of the USM.- Returns:
USM.getID()
-
compareTo
public int compareTo(UsmUser other)
Compares two USM users by their security names.- Specified by:
compareTo
in interfacejava.lang.Comparable<UsmUser>
- Parameters:
other
- anotherUsmUser
instance.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
localizeUser
public UsmUser localizeUser(OctetString localizationEngineID, OctetString localizedAuthenticationKey, OctetString localizedPrivacyKey, SecurityProtocols securityProtocols)
Return a copy of the current user with (updated) localized keys.- Parameters:
localizationEngineID
- thelocalizationEngineID
specifies the engine ID for which the supplied keys are already localized. Such an USM user can only be used with the target whose engine ID equalslocalizationEngineID
. Ifnull
, then aNullPointerException
will be thrown.localizedAuthenticationKey
- the optional new (localized) authentication key. Ifnull
, then the existing authentication key of this user is preserved and it is returned byUsmUser
in its localized representation.localizedPrivacyKey
- the optional new (localized) privacy key. Ifnull
, then the existing privacy key of this user is preserved and it is returned byUsmUser
in its localized representation.securityProtocols
- a collection ofSecurityProtocol
instances providing security protocols used by theSecurityProtocols.passwordToKey(OID, OctetString, byte[])
operation to localize existing passphrases. If not provided (i.e.null
) and at least one of the existing passphrases is notnull
, then aNullPointerException
is thrown.- Returns:
- a copy of this user but with localized (optionally new) authentication or privacy keys.
- Since:
- 3.4.0
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-