public class USM extends SNMPv3SecurityModel
USM
class implements the User Based Security Model (USM)
as defined in RFC 3414.
When a user is added or removed from the USM, a UsmUserEvent
is fired and forwarded to registered listeners.localEngineID
SECURITY_MODEL_ANY, SECURITY_MODEL_SNMPv1, SECURITY_MODEL_SNMPv2c, SECURITY_MODEL_TSM, SECURITY_MODEL_USM
Constructor and Description |
---|
USM()
Default constructor with random engine ID with the default enterprise ID and a zero engineBoots counter.
|
USM(SecurityProtocols securityProtocols,
OctetString localEngineID,
int engineBoots)
Creates a USM with the support for the supplied security protocols.
|
Modifier and Type | Method and Description |
---|---|
UsmUserEntry |
addLocalizedUser(byte[] engineID,
OctetString userName,
OID authProtocol,
byte[] authKey,
OID privProtocol,
byte[] privKey)
Adds a localized user to the USM.
|
void |
addUser(OctetString userName,
OctetString engineID,
UsmUser user)
Adds an USM user to the internal user name table and associates it with
an authoritative engine ID.
|
void |
addUser(OctetString userName,
UsmUser user)
Adds an USM user to the internal user name table.
|
void |
addUser(UsmUser user)
Adds an USM user to the internal user name table.
|
void |
addUsmUserEntry(UsmUserEntry usmUserEntry)
Adds an USM user to the internal user name table.
|
void |
addUsmUserListener(UsmUserListener l)
Adds a
UsmUserListener that should be informed whenever the
internal USM user table is changed. |
protected void |
fireIncrementCounter(CounterEvent e) |
protected void |
fireUsmUserChange(UsmUserEvent e)
Fires a
UsmUserEvent . |
int |
generateRequestMessage(int snmpVersion,
byte[] globalData,
int maxMessageSize,
int securityModel,
byte[] securityEngineID,
byte[] securityName,
int securityLevel,
BERInputStream scopedPDU,
SecurityParameters securityParameters,
BEROutputStream wholeMsg,
TransportStateReference tmStateReference)
Generate a request message.
|
int |
generateResponseMessage(int snmpVersion,
byte[] globalData,
int maxMessageSize,
int securityModel,
byte[] securityEngineID,
byte[] securityName,
int securityLevel,
BERInputStream scopedPDU,
SecurityStateReference securityStateReference,
SecurityParameters securityParameters,
BEROutputStream wholeMsg)
Generates a response message.
|
CounterSupport |
getCounterSupport()
Gets the counter support instance that can be used to register for
counter incrementation events.
|
int |
getEngineBoots()
Returns the number of engine boots counted for the local engine ID.
|
int |
getEngineTime()
Returns the number of seconds since the value of
the engineBoots object last changed.
|
int |
getID()
Gets the ID of the security model.
|
SecurityProtocols |
getSecurityProtocols()
Returns the security protocol collection used by this USM.
|
UsmTimeTable |
getTimeTable()
Returns the
UsmTimeTable instance used by this USM for holding
timing information about the local and remote SNMP entities. |
UsmUserEntry |
getUser(OctetString engineID,
OctetString securityName)
Looks up a
UsmUserEntry by an engine ID and
security name. |
UsmUserTable |
getUserTable()
Returns the
UsmUserTable instance used by the USM for local
storage of USM user information. |
boolean |
hasAuthoritativeEngineID()
Checks whether this
SecurityModel has an authoritative engine ID. |
boolean |
hasUser(OctetString engineID,
OctetString securityName)
Checks if the specified user is known by this USM.
|
boolean |
isEngineDiscoveryEnabled()
Checks whether engine ID discovery is enabled or not.
|
SecurityParameters |
newSecurityParametersInstance()
Creates a new
SecurityParameters instance that corresponds to this
security model. |
SecurityStateReference |
newSecurityStateReference()
Creates a new
SecurityStateReference instance that corresponds to
this security model. |
int |
processIncomingMsg(int snmpVersion,
int maxMessageSize,
SecurityParameters securityParameters,
SecurityModel securityModel,
int securityLevel,
BERInputStream wholeMsg,
TransportStateReference tmStateReference,
OctetString securityEngineID,
OctetString securityName,
BEROutputStream scopedPDU,
Integer32 maxSizeResponseScopedPDU,
SecurityStateReference securityStateReference,
StatusInformation statusInfo)
Processes an incoming message and returns its plaintext payload.
|
void |
removeAllUsers()
Removes all users from the USM.
|
List<UsmUser> |
removeAllUsers(OctetString userName)
Removes all USM user from the internal user name table with the specified user
name.
|
List<UsmUser> |
removeAllUsers(OctetString userName,
OctetString engineID)
Removes all USM user from the internal user name table with the specified user
name and (optional) engine ID.
|
void |
removeEngineTime(OctetString engineID)
Removes the specified engine ID from the internal time cache and thus
forces an engine time rediscovery the next time the SNMP engine with
the supplied ID is contacted.
|
UsmUser |
removeUser(OctetString engineID,
OctetString userName)
Deprecated.
If the engineID
null is provided this method does only
delete the generic user. All already localized users will not be deleted.
To delete those users too, use removeAllUsers() instead. |
void |
removeUsmUserListener(UsmUserListener l)
Removes a
UsmUserListener . |
void |
setCounterSupport(CounterSupport counterSupport)
Sets the counter support instance.
|
void |
setEngineBoots(int engineBoots)
Sets the number of engine boots.
|
void |
setEngineDiscoveryEnabled(boolean engineDiscoveryEnabled)
Enables or disables automatic engine ID discovery.
|
void |
setLocalEngine(OctetString localEngineID,
int engineBoots,
int engineTime)
Sets the local engine ID, number of boots, and time after boot.
|
void |
setUsers(UsmUser[] users)
Sets the users of this USM.
|
boolean |
supportsEngineIdDiscovery()
Checks whether this
SecurityModel supports authoritative
engine ID discovery. |
void |
updateUser(UsmUserEntry entry)
Updates the USM user entry with the same engine ID and user name as the
supplied instance and fires an appropriate
UsmUserEvent . |
buildMessageBuffer, buildWholeMessage, getLocalEngineID
public USM(SecurityProtocols securityProtocols, OctetString localEngineID, int engineBoots)
securityProtocols
- the security protocols to support.localEngineID
- the local engine ID.engineBoots
- the number of engine boots.public USM()
SecurityProtocols.getInstance()
with the
default protocols is used.public int getID()
SecurityModel
SecurityModel
interface.SecurityModel.SECURITY_MODEL_ANY
,
SecurityModel.SECURITY_MODEL_SNMPv1
,
SecurityModel.SECURITY_MODEL_SNMPv2c
,
SecurityModel.SECURITY_MODEL_USM
public boolean supportsEngineIdDiscovery()
SecurityModel
SecurityModel
supports authoritative
engine ID discovery.
The USM
for instance, returns true
whereas
TSM
returns false
.
See also RFC 5343 3.2 for details.true
if this security model has its own authoritative
engine ID discovery mechanism.public boolean hasAuthoritativeEngineID()
SecurityModel
SecurityModel
has an authoritative engine ID.true
if an authoritative engine ID is exchanged between
command sender and responder using this security model, false
otherwise.public void setLocalEngine(OctetString localEngineID, int engineBoots, int engineTime)
localEngineID
- the local engine ID.engineBoots
- the number of engine boots.engineTime
- the number sendonds since the last boot.public void setEngineBoots(int engineBoots)
engineBoots
- the number of engine boots.public int getEngineBoots()
public int getEngineTime()
public SecurityParameters newSecurityParametersInstance()
SecurityModel
SecurityParameters
instance that corresponds to this
security model.SecurityParameters
instance.public SecurityStateReference newSecurityStateReference()
SecurityModel
SecurityStateReference
instance that corresponds to
this security model.SecurityStateReference
instance.public int generateRequestMessage(int snmpVersion, byte[] globalData, int maxMessageSize, int securityModel, byte[] securityEngineID, byte[] securityName, int securityLevel, BERInputStream scopedPDU, SecurityParameters securityParameters, BEROutputStream wholeMsg, TransportStateReference tmStateReference) throws IOException
SecurityModel
snmpVersion
- the ID of the message processing model (SNMP version) to use.globalData
- the message header and admin data.maxMessageSize
- the maximum message size of the sending (this) SNMP entity for the
selected transport mapping (determined by the message processing model).securityModel
- the security model for the outgoing message.securityEngineID
- the authoritative SNMP entity.securityName
- the principal on behalf of this message is generated.securityLevel
- the requested SecurityLevel
.scopedPDU
- a BERInputStream containing the message (plain text) payload.securityParameters
- returns the SecurityParameters
filled by the security model.wholeMsg
- returns the complete generated message in a BEROutputStream
.
The buffer of wholeMsg
is set to null
by the
caller and must be set by the implementation of this method.tmStateReference
- the transport model state reference as defined by RFC 5590.SnmpConstants.SNMPv3_USM_OK
is returned, otherwise one of the
other SnmpConstants.SNMPv3_USM_*
values is returned.IOException
- if generation of the message fails because of an internal or an resource
error.public boolean hasUser(OctetString engineID, OctetString securityName)
engineID
- the engineID of the user (may be null
if any target should
match).securityName
- the security name of the user to earch for.true
if the user is either known for the specified engine ID
or without a specific engine ID (discovery only).public UsmUserEntry getUser(OctetString engineID, OctetString securityName)
UsmUserEntry
by an engine ID and
security name. If an user exists that is not localized for the provided
engine ID, it will be localized and then the localized user entry is
returned. If the provided engine ID has a zero length then an empty
UsmUserEntry
is returned with just the provided
securityName set.engineID
- an engine ID.securityName
- a security name.UsmUserEntry
if the provided
engineID's length is greater than zero and null
if the
securityName cannot be found in the USM.public int generateResponseMessage(int snmpVersion, byte[] globalData, int maxMessageSize, int securityModel, byte[] securityEngineID, byte[] securityName, int securityLevel, BERInputStream scopedPDU, SecurityStateReference securityStateReference, SecurityParameters securityParameters, BEROutputStream wholeMsg) throws IOException
SecurityModel
snmpVersion
- the ID of the message processing model (SNMP version) to use.globalData
- the message header and admin data.maxMessageSize
- the maximum message size of the sending (this) SNMP entity for the
selected transport mapping (determined by the message processing model).securityModel
- the security model for the outgoing message.securityEngineID
- the authoritative SNMP entity.securityName
- the principal on behalf of this message is generated.securityLevel
- the requested SecurityLevel
.scopedPDU
- a BERInputStream containing the message (plain text) payload.securityStateReference
- a SecurityStateReference
instance providing information from
original request.securityParameters
- returns the SecurityParameters
filled by the security model.wholeMsg
- returns the complete generated message in a BEROutputStream
.
The buffer of wholeMsg
is set to null
by the
caller and must be set by the implementation of this method.SnmpConstants.SNMPv3_USM_OK
is returned, otherwise one of the
other SnmpConstants.SNMPv3_USM_*
values is returned.IOException
- if generation of the message fails because of an internal or an resource
error.public int processIncomingMsg(int snmpVersion, int maxMessageSize, SecurityParameters securityParameters, SecurityModel securityModel, int securityLevel, BERInputStream wholeMsg, TransportStateReference tmStateReference, OctetString securityEngineID, OctetString securityName, BEROutputStream scopedPDU, Integer32 maxSizeResponseScopedPDU, SecurityStateReference securityStateReference, StatusInformation statusInfo) throws IOException
SecurityModel
snmpVersion
- the ID of the message processing model (SNMP version) to use.maxMessageSize
- the maximum message size of the message processing model for the
transport mapping associated with this message's source address less
the length of the maximum header length of the message processing model.
This value is used by the security model to determine the
maxSizeResponseScopedPDU
value.securityParameters
- the SecurityParameters
for the received message.securityModel
- the SecurityModel
instance for the received message.securityLevel
- the SecurityLevel
ID.wholeMsg
- the BERInputStream
containing the whole message as received
on the wire.tmStateReference
- the transport model state reference as defined by RFC 5590.securityEngineID
- the authoritative SNMP entity.securityName
- the identification of the principal.scopedPDU
- returns the message (plaintext) payload into the supplied
BEROutputStream
.
The buffer of scopedPDU
is set to null
by the
caller and must be set by the implementation of this method.maxSizeResponseScopedPDU
- the determined maximum size for a response PDU.securityStateReference
- the SecurityStateReference
information needed for
a response.statusInfo
- the StatusInformation
needed to generate reports if
processing of the incoming message failed.SnmpConstants.SNMPv3_USM_OK
is returned, otherwise one of the
other SnmpConstants.SNMPv3_USM_*
values is returned.IOException
- if an unexpected (internal) or an resource error occurred.protected void fireIncrementCounter(CounterEvent e)
public void addUser(OctetString userName, UsmUser user)
userName
- a user name.user
- the UsmUser
to add.public void addUser(UsmUser user)
user
- the UsmUser
to add.public void addUsmUserEntry(UsmUserEntry usmUserEntry)
UsmUserEntry.getStorageType()
defines the storage type
of the new USM user table entry.
Caution: This is a low level call and the provided UsmUserEntry must contain already correctly localized
authentication and privacy keys as well as a correct user engine ID.usmUserEntry
- the UsmUserEntry
to add.public void addUser(OctetString userName, OctetString engineID, UsmUser user)
The engine ID must be at least MPv3.MINLEN_ENGINE_ID
bytes long and
not longer than MPv3.MAXLEN_ENGINE_ID
.
user
must be not longer than MAXLEN_USMUSERNAME
bytes.userName
- a user name.engineID
- the authoritative engine ID to be associated with this entry. If
engineID
is null
this method behaves exactly
like addUser(OctetString userName, UsmUser user)
.user
- the UsmUser
to add.IllegalArgumentException
- if (a) the length of the engine ID is less than
MPv3.MINLEN_ENGINE_ID
or more than MPv3.MAXLEN_ENGINE_ID
bytes
(b) if the security name of the user
is longer than
MAXLEN_USMUSERNAME
.public void updateUser(UsmUserEntry entry)
UsmUserEvent
.
If the corresponding user entry does not yet exist then it will be added.entry
- an UsmUserEntry
instance not necessarily the same as an
already existing entry.public void setUsers(UsmUser[] users)
users
- a possibly empty UsmUser
array of users.public UsmUserTable getUserTable()
UsmUserTable
instance used by the USM for local
storage of USM user information. The returned table should not be modified,
because modifications will not be reported to registered
UsmUserListener
s.UsmUserTable
instance containing the users known by
this USM.public UsmTimeTable getTimeTable()
UsmTimeTable
instance used by this USM for holding
timing information about the local and remote SNMP entities.public List<UsmUser> removeAllUsers(OctetString userName, OctetString engineID)
userName
- a user name.engineID
- the authoritative engine ID associated with the user by localization, or
null
if all users with userName
should be
deleted.UsmUser
instances as a List. If the user could
be found, an empty list is returned.public List<UsmUser> removeAllUsers(OctetString userName)
removeAllUsers(org.snmp4j.smi.OctetString, org.snmp4j.smi.OctetString)
with engineID set to null
.userName
- a user name.UsmUser
instances as a List. If the user could
be found, an empty list is returned.public UsmUser removeUser(OctetString engineID, OctetString userName)
null
is provided this method does only
delete the generic user. All already localized users will not be deleted.
To delete those users too, use removeAllUsers()
instead.engineID
- the authoritative engine ID associated with the user, or
null
userName
- a user name.UsmUser
instance associate with the given
userName
or null
if such a user could not
be found.public void removeAllUsers()
public UsmUserEntry addLocalizedUser(byte[] engineID, OctetString userName, OID authProtocol, byte[] authKey, OID privProtocol, byte[] privKey)
engineID
- the engine ID for which the user has been localized.userName
- the user's name.authProtocol
- the authentication protocol ID.authKey
- the authentication key.privProtocol
- the privacy protocol ID.privKey
- the privacy key.UsmUserEntry
.public boolean isEngineDiscoveryEnabled()
true
if discovery is enabled, false
otherwise.public void setEngineDiscoveryEnabled(boolean engineDiscoveryEnabled)
engineDiscoveryEnabled
- true
if discovery should be enabled,
false
otherwise.public void removeUsmUserListener(UsmUserListener l)
UsmUserListener
.l
- a previously added UsmUserListener
.public void addUsmUserListener(UsmUserListener l)
UsmUserListener
that should be informed whenever the
internal USM user table is changed.l
- a UsmUserListener
that should be informed about
UsmUserEvent
events.public void removeEngineTime(OctetString engineID)
engineID
- the SNMP engine ID whose engine time to remove.protected void fireUsmUserChange(UsmUserEvent e)
UsmUserEvent
.e
- the UsmUserEvent
to fire.public CounterSupport getCounterSupport()
CounterSupport
instance that is used to fire
CounterEvent
.public SecurityProtocols getSecurityProtocols()
SecurityProtocols
instance which is by default the
same instance as returned by SecurityProtocols.getInstance()
.public void setCounterSupport(CounterSupport counterSupport)
CounterSupport
instance is used.counterSupport
- a CounterSupport
subclass instance.Copyright © 2018 SNMP4J.org. All rights reserved.