com.adventnet.snmp.snmp2.security.community
Class SnmpCommunityEntry

java.lang.Object
  |
  +--com.adventnet.snmp.snmp2.SecurityModelEntry
        |
        +--com.adventnet.snmp.snmp2.security.community.SnmpCommunityEntry
All Implemented Interfaces:
java.io.Serializable

public class SnmpCommunityEntry
extends SecurityModelEntry
implements java.io.Serializable

The SnmpCommunityEntry holds the information about a particular community string.

See Also:
Serialized Form

Field Summary
static int V1_COMMUNITY_MODEL
          Constant for the V1 Community Model.
static int V2C_COMMUNITY_MODEL
          Constant for the V2C Community Model.
 
Constructor Summary
SnmpCommunityEntry()
          Constructs a default SnmpCommunityEntry with default index as "public".
SnmpCommunityEntry(byte[] index)
          Constructs a new SnmpCommunityEntry with the specified snmpCommunityIndex.
SnmpCommunityEntry(java.lang.String index)
          Constructs a new SnmpCommunityEntry with the specified snmpCommunityIndex.
SnmpCommunityEntry(java.lang.String index, java.lang.String encoding)
          Constructs a new SnmpCommunityEntry with the specified snmpCommunityIndex.
 
Method Summary
 void authenticateMessageToSend(Snmp3Message msg, SnmpSession session)
          This method resets the version of the PDU, to the version which was in it, when authenticateReceivedMessage was invoked.
 int authenticateReceivedMessage(Snmp3Message msg, SnmpSession session)
          Performs authentication of the received message as per the standard.
 SecurityModelEntry copy()
          This returns, the copy of this Security Entry object.
 void decodeMsgSecurityParams(Snmp3Message msg, SnmpSession session, ASN1Parser parser)
          This method will decode the security parameters that are dependent on the security model.
 byte[] decrypt(byte[] data, int offset, byte[] key, int protocol, byte[] privParams)
          This method is used to decrypt the data.
 boolean encodeMsgSecurityParams(Snmp3Message msg, SnmpAPI API, ASN1Parser asnParser)
          This method will encode the security parameters that are dependent on the security model.
 int encrypt(byte[] data, int spaceLeft, byte[] key, int protocol, byte[] privParams)
          This method is used to encrypt the data.
 byte[] getCommunityIndex()
          This method gets the community index of this entry.
 byte[] getCommunityName()
          Retrieves the snmpCommunityName value associated with this object.
 byte[] getContextEngineID()
          Retrieves the snmpCommunityContextEngineID value associated with this object.
 byte[] getContextName()
          Retrieves the snmpCommunityContextName value associated with this object.
 byte[] getEngineID()
          Returns, the engineID of this SnmpEngine.
 java.lang.Object getKey()
          Returns the key associated with this SnmpCommunityEntry.
 java.lang.Object getKey(byte[] index)
          Returns the key as the String value of this index value.
 int getRowStatus()
          Retrieves the snmpCommunityStatus value associated with this object.
 byte[] getSecurityID(byte[] securityID)
          Returns, a security model dependent securityID, using the security model independent security name.
 byte getSecurityLevel()
          Returns, the security level associated with this securityEntry.
 int getSecurityModel()
          Returns, the security model.
 byte[] getSecurityName()
          Retrieves the snmpCommunitySecurityName value associated with this object.
 byte[] getSecurityName(byte[] securityID)
          Returns, a security model independent security name using the security model dependent securityID.
 int getStorageType()
          Retrieves the snmpCommunityStorageType value associated with this object.
 byte[] getTransportTag()
          Retrieves the snmpCommunityTransportTag value associated with this object.
 void processEncodedMsg(Snmp3Message msg, ASN1Parser parser)
          This method is called after encoding the message version.
 void setCommunityIndex(byte[] index)
          This method sets the community index value.
 void setCommunityIndex(java.lang.String index)
          This methods sets the community index value.
 void setCommunityIndex(java.lang.String index, java.lang.String encoding)
          This methods sets the community index value.
 void setCommunityName(byte[] name)
          Sets the snmpCommunityName value associated with this object.
 void setContextEngineID(byte[] contextID)
          Sets the snmpCommunityContextEngineID value associated with this object.
 void setContextName(byte[] contextName)
          Sets the snmpCommunityContextName value associated with this object.
 void setRowStatus(int status)
          Sets the snmpCommunityStatus value associated with this object.
 void setSecurityLevel(byte level)
          Sets the security level associated with this securityEntry.
 void setSecurityName(byte[] secName)
          Sets the snmpCommunitySecurityName value associated with this object.
 void setStorageType(int type)
          Sets the snmpCommunityStorageType value associated with this object.
 void setTransportTag(byte[] tagValue)
          Sets the snmpCommunityTransportTag value associated with this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

V1_COMMUNITY_MODEL

public static final int V1_COMMUNITY_MODEL
Constant for the V1 Community Model.

V2C_COMMUNITY_MODEL

public static final int V2C_COMMUNITY_MODEL
Constant for the V2C Community Model.
Constructor Detail

SnmpCommunityEntry

public SnmpCommunityEntry()
Constructs a default SnmpCommunityEntry with default index as "public". The API user should not use this constructor.

SnmpCommunityEntry

public SnmpCommunityEntry(byte[] index)
Constructs a new SnmpCommunityEntry with the specified snmpCommunityIndex.
Parameters:
index - The snmpCommunityIndex to be used for creating a new SnmpCommunityEntry.

SnmpCommunityEntry

public SnmpCommunityEntry(java.lang.String index)
                   throws java.io.UnsupportedEncodingException
Constructs a new SnmpCommunityEntry with the specified snmpCommunityIndex. The bytes will be got from this string using the default character encoding namely ISO8859_1. If the bytes are to be got using some other encoding then the constructor with the index and encoding as argument can be used.
Parameters:
index - The String index which is to be used as the community index.
Throws:
java.lang.NullPointerException - if the index is null.
java.lang.IllegalArgumentException - if the length of the index is zero or greater than 32, since the length of the community index should be from 1 to 32 as defined in RFC2576.
UnsupportedEncodingException - if the encoding ISO8859_1 is not supported.
Since:
AdventNet SNMP API 4.0

SnmpCommunityEntry

public SnmpCommunityEntry(java.lang.String index,
                          java.lang.String encoding)
                   throws java.io.UnsupportedEncodingException
Constructs a new SnmpCommunityEntry with the specified snmpCommunityIndex. The bytes will be got from the encoding string given as argument.
Parameters:
index - The String index which is to be used as the community index.
encoding - The name of a supported character encoding.
Throws:
java.lang.NullPointerException - if the index or encoding is null.
java.lang.IllegalArgumentException - if the length of the index is zero or greater than 32, since the length of the community index should be from 1 to 32 as defined in RFC2576.
UnsupportedEncodingException - if the encoding string is not supported.
Since:
AdventNet SNMP API 4.0
Method Detail

setCommunityIndex

public void setCommunityIndex(byte[] index)
This method sets the community index value.
Parameters:
index - the community index value.

setCommunityIndex

public void setCommunityIndex(java.lang.String index)
                       throws java.io.UnsupportedEncodingException
This methods sets the community index value.
Parameters:
index - the string value of the community index. From this string value, the bytes will be got using the default character encoding namely ISO8859_1.
Throws:
java.lang.NullPointerException - if index is null.
java.lang.IllegalArgumentException - if the length of the index is zero or greater than 32. Since the length of the community index should be from 1 to 32 as defined in RFC2576.
UnsupportedEncodingException - if the encoding string is not supported.
Since:
AdventNet SNMP API 4.0

setCommunityIndex

public void setCommunityIndex(java.lang.String index,
                              java.lang.String encoding)
                       throws java.io.UnsupportedEncodingException
This methods sets the community index value.
Parameters:
index - the string value of the community index.
encoding - The name of a supported character encoding.
Throws:
java.lang.NullPointerException - if index or encoding is null.
java.lang.IllegalArgumentException - if the length of the index is zero or greater than 32. Since the length of the community index should be from 1 to 32 as defined in RFC2576.
UnsupportedEncodingException - if the encoding string is not supported.
Since:
AdventNet SNMP API 4.0

getCommunityIndex

public byte[] getCommunityIndex()
This method gets the community index of this entry.
Returns:
the community index of this entry.

setCommunityName

public void setCommunityName(byte[] name)
Sets the snmpCommunityName value associated with this object.
Parameters:
name - The snmpCommunityName value to be associated with this object.

getCommunityName

public byte[] getCommunityName()
Retrieves the snmpCommunityName value associated with this object.
Returns:
the snmpCommunityName value associated with this object.

setSecurityName

public void setSecurityName(byte[] secName)
Sets the snmpCommunitySecurityName value associated with this object.
Overrides:
setSecurityName in class SecurityModelEntry
Parameters:
secName - The snmpCommunitySecurityName value to be associated with this object.

getSecurityName

public byte[] getSecurityName()
Retrieves the snmpCommunitySecurityName value associated with this object.
Overrides:
getSecurityName in class SecurityModelEntry
Returns:
the snmpCommunitySecurityName value associated with this object.

setContextEngineID

public void setContextEngineID(byte[] contextID)
Sets the snmpCommunityContextEngineID value associated with this object.
Parameters:
contextID - The snmpCommunityContextEngineID value to be associated with this object.

getContextEngineID

public byte[] getContextEngineID()
Retrieves the snmpCommunityContextEngineID value associated with this object.
Returns:
the snmpCommunityContextEngineID value associated with this object.

setContextName

public void setContextName(byte[] contextName)
Sets the snmpCommunityContextName value associated with this object.
Parameters:
contextName - The snmpCommunityContextName value to be associated with this object.

getContextName

public byte[] getContextName()
Retrieves the snmpCommunityContextName value associated with this object.
Returns:
the snmpCommunityContextName value associated with this object.

setTransportTag

public void setTransportTag(byte[] tagValue)
Sets the snmpCommunityTransportTag value associated with this object.
Parameters:
tagValue - The snmpCommunityTransportTag value to be associated with this object.

getTransportTag

public byte[] getTransportTag()
Retrieves the snmpCommunityTransportTag value associated with this object.
Returns:
the snmpCommunityTransportTag value associated with this object.

setStorageType

public void setStorageType(int type)
Sets the snmpCommunityStorageType value associated with this object.
Parameters:
type - The snmpCommunityStorageType value to be associated with this object.

getStorageType

public int getStorageType()
Retrieves the snmpCommunityStorageType value associated with this object.
Returns:
the snmpCommunityStorageType value associated with this object.

setRowStatus

public void setRowStatus(int status)
Sets the snmpCommunityStatus value associated with this object.
Parameters:
status - The snmpCommunityStatus value to be associated with this object.

getRowStatus

public int getRowStatus()
Retrieves the snmpCommunityStatus value associated with this object.
Returns:
the snmpCommunityStatus value associated with this object.

getKey

public java.lang.Object getKey()
Returns the key associated with this SnmpCommunityEntry.
Overrides:
getKey in class SecurityModelEntry
Returns:
Thee key as a String Object.
Throws:
java.lang.NullPointerException - if the key value is null.

getKey

public java.lang.Object getKey(byte[] index)
Returns the key as the String value of this index value.
Returns:
The key as a String Object.

authenticateReceivedMessage

public int authenticateReceivedMessage(Snmp3Message msg,
                                       SnmpSession session)
Performs authentication of the received message as per the standard. Authenticates and fills in the security parameters. If authentication fails, noSuchName (V1 request) or authorizationError (V2 request) is set on the PDU.
Overrides:
authenticateReceivedMessage in class SecurityModelEntry
Parameters:
msg - The Snmp3Message instance.
session - The SnmpSession instance incase this module requires
Returns:
1 if the authentication is successful. If authentication fails, -1 is returned.

authenticateMessageToSend

public void authenticateMessageToSend(Snmp3Message msg,
                                      SnmpSession session)
This method resets the version of the PDU, to the version which was in it, when authenticateReceivedMessage was invoked.
Overrides:
authenticateMessageToSend in class SecurityModelEntry
Parameters:
msg - The Snmp3Message instance.
session - The SnmpSession instance.
Throws:
SnmpException - If the message could not be authenticated properly or a particular entry is not available.

getSecurityModel

public int getSecurityModel()
Returns, the security model. The default value is -1.
Overrides:
getSecurityModel in class SecurityModelEntry
Returns:
The securityModel, associated with this SnmpCommunityEntry.

getEngineID

public byte[] getEngineID()
Returns, the engineID of this SnmpEngine. This method should not be used by API user. This method has default implementation and returns null.
Overrides:
getEngineID in class SecurityModelEntry

getSecurityID

public byte[] getSecurityID(byte[] securityID)
Returns, a security model dependent securityID, using the security model independent security name. This method should not be used by API user. This method has default implementation and returns null.
Overrides:
getSecurityID in class SecurityModelEntry

getSecurityLevel

public byte getSecurityLevel()
Returns, the security level associated with this securityEntry.
Overrides:
getSecurityLevel in class SecurityModelEntry
Returns:
The securityLevel associated with this entry.

setSecurityLevel

public void setSecurityLevel(byte level)
Sets the security level associated with this securityEntry. This method should not be used by API user.
Overrides:
setSecurityLevel in class SecurityModelEntry

getSecurityName

public byte[] getSecurityName(byte[] securityID)
Returns, a security model independent security name using the security model dependent securityID. This method should not be used by API user. This method has default implementation and returns null.
Overrides:
getSecurityName in class SecurityModelEntry

copy

public SecurityModelEntry copy()
This returns, the copy of this Security Entry object.
Overrides:
copy in class SecurityModelEntry
Returns:
SecurityModelEntry - A copy of this SecurityModelEntry.

encodeMsgSecurityParams

public boolean encodeMsgSecurityParams(Snmp3Message msg,
                                       SnmpAPI API,
                                       ASN1Parser asnParser)
This method will encode the security parameters that are dependent on the security model.
Overrides:
encodeMsgSecurityParams in class SecurityModelEntry
Parameters:
msg - The Snmp3Message instance.
API - The SnmpAPI Instance.
asnParser - The reference to ASN1Parser which has the methods to encode the SnmpPDU. This method should not be used by API user. This method has default implementation and returns false.

decodeMsgSecurityParams

public void decodeMsgSecurityParams(Snmp3Message msg,
                                    SnmpSession session,
                                    ASN1Parser parser)
                             throws SnmpException,
                                    java.lang.ArrayIndexOutOfBoundsException
This method will decode the security parameters that are dependent on the security model.
Overrides:
decodeMsgSecurityParams in class SecurityModelEntry
Parameters:
msg - The Snmp3Message instance.
asnParser - The reference to ASN1Parser which has the data and methods to encode/decode the SnmpPDU.
Throws:
SnmpException - If the security parameters could not be decoded properly.
java.lang.ArrayIndexOutOfBoundsException - If an unrecognized snmp message This method should not be used by API user.

processEncodedMsg

public void processEncodedMsg(Snmp3Message msg,
                              ASN1Parser parser)
This method is called after encoding the message version. This method will be useful when the API user needs to calculate the digest over the message.
Overrides:
processEncodedMsg in class SecurityModelEntry
Parameters:
msg - Snmp3Messgage instance.
asnParser - The reference to ASN1Parser which has the encoded data and methods to encode the SnmpPDU. This method should not be used by API user.

encrypt

public int encrypt(byte[] data,
                   int spaceLeft,
                   byte[] key,
                   int protocol,
                   byte[] privParams)
            throws SnmpException
This method is used to encrypt the data.
Overrides:
encrypt in class SecurityModelEntry
Parameters:
data - The data to be encrypted.
spaceleft - The space left in the buffer while encoding
key - The key value used in encryption
protocol - The protocol used for encryption
privParams - The privacy params used in encryption This method should not be used by API user. This method has default implementation and returns -1.

decrypt

public byte[] decrypt(byte[] data,
                      int offset,
                      byte[] key,
                      int protocol,
                      byte[] privParams)
This method is used to decrypt the data.
Overrides:
decrypt in class SecurityModelEntry
Parameters:
data - The data to be decrypted.
offset - The offset value to be used in decryption.
key - The key value to be used in decryption.
protocol - The protocol used for decryption.
privParams - The privacy params used in decryption.
Returns:
data The decrypted data. This method should not be used by API user. This method has default implementation and returns null.


Copyright (c)AdventNet Inc., 1996-2004