Class MOXodusPersistence
- All Implemented Interfaces:
EventListener, org.snmp4j.agent.mo.MOChangeListener
MOXodusPersistence class provides persistent storage for SNMP4J-Agent using the
MOXodusPersistenceProvider wrapper that actually implements the
MOPersistenceProvider interface of SNMP4J-Agent.
As a storage engine, the Xodus open source (Apache 2 License) DB is used.
See https://github.com/JetBrains/xodus} for details.
The database approach has the following advantages compared to the standard sequential persistence provider coming
with SNMP4J-Agent:
- Only changed objects are written again to disk. The default DefaultMOPersistenceProvider needs to save all objects in a sequence.
- DB size is smaller - if changes are limited to approximately less than 40% of the MIB objects during runtime.
- Agent shutdown is much faster because no objects need to be saved anymore.
- No data loss if agent is killed.
SampleAgent illustrates how this class is created
and assigned to the agent during its initialization.
File configFile = new File(myConfigDir);
MOXodusPersistence moXodusPersistence = new MOXodusPersistence(moServers, Environments.newInstance(configFile));
MOXodusPersistenceProvider moXodusPersistenceProvider = new MOXodusPersistenceProvider(moXodusPersistence);
OctetString defaultEngineID = new OctetString(MPv3.createLocalEngineID());
OctetString engineID = moXodusPersistenceProvider.getEngineId(defaultEngineID);
...
agent = new AgentConfigManager(engineID, messageDispatcher, null, moServers, ThreadPool.create("SampleAgent", 3),
(defaultEngineID == engineID) ? configurationFactory : null,
moXodusPersistenceProvider,
new EngineBootsCounterFile(bootCounterFile), null, dhKickstartParameters);
agent.addAgentStateListener(new AgentStateListener() {
public void agentStateChanged(AgentConfigManager agentConfigManager, AgentState newState) {
switch (newState.getState()) {
case AgentState.STATE_INITIALIZED:
moXodusPersistence.registerChangeListenersWithServer(server);
break;
case AgentState.STATE_SHUTDOWN:
moXodusPersistence.unregisterChangeListenersWithServer(server);
break;
}
}
});
- Since:
- 3.0
- Version:
- 3.5.0
- Author:
- Frank Fock
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA parsed representation of an algorithm identifier as accepted bysetDefaultEncryptionAlgorithm(String).static enumTheMOXodusPersistence.SavingStrategydefines how and when persistent data is saved. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default encryption algorithm identifier used byMOXodusPersistencefor protectingSecretOctetStringvalues stored to disk. -
Constructor Summary
ConstructorsConstructorDescriptionMOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment) MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment, char[] masterPassword) Creates a newMOXodusPersistencefrom an array ofMOServerinstances, an XodusEnvironment, and a master password used to encrypt everySecretOctetStringvalue before it is written to persistent storage.MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment, MOXodusPersistence.SavingStrategy savingStrategy) MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment, MOXodusPersistence.SavingStrategy savingStrategy, org.snmp4j.agent.MOScopeComparator moScopeComparator) MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment, MOXodusPersistence.SavingStrategy savingStrategy, org.snmp4j.agent.MOScopeComparator moScopeComparator, char[] masterPassword) Creates a newMOXodusPersistencewith explicitMOXodusPersistence.SavingStrategy, comparator and master password. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterMOChange(org.snmp4j.agent.mo.MOChangeEvent changeEvent) A change has been committed.voidafterPrepareMOChange(org.snmp4j.agent.mo.MOChangeEvent changeEvent) A change has been prepared.voidbeforeMOChange(org.snmp4j.agent.mo.MOChangeEvent changeEvent) A ManagedObject change is being committed.voidbeforePrepareMOChange(org.snmp4j.agent.mo.MOChangeEvent changeEvent) A ManagedObject change is being prepared.protected jetbrains.exodus.env.StorecreateStore(jetbrains.exodus.env.Transaction txn, org.snmp4j.smi.OctetString context) Ceates aStorefor a context.protected org.snmp4j.smi.VariabledecodeEncryptedSecretOctetString(org.snmp4j.asn1.BERInputStream inputStream) Decodes a BER SEQUENCE that wraps an encryptedSecretOctetStringand returns the decrypted value asSecretOctetString.static int[]decodeIndexOID(org.snmp4j.asn1.BERInputStream is, org.snmp4j.asn1.BER.MutableByte type) Decode a indexOIDfrom a BER input stream.protected List<org.snmp4j.smi.VariableBinding> decodeInstanceData(jetbrains.exodus.ByteIterable rawData) Decode BER instance data from raw byte stream.protected org.snmp4j.smi.VariableBindingdecodeVariableBinding(org.snmp4j.asn1.BERInputStream inputStream) Decode aVariableBindingfrom anBERInputStream.protected SecretKeyderiveKey(char[] password, byte[] salt, MOXodusPersistence.EncryptionSpec spec) static voidencodeIndexOID(OutputStream os, byte type, int[] oid) Encodes an index OID.protected byte[]encodeInstanceData(List<org.snmp4j.smi.VariableBinding> vbs) Encode instance data from a list ofVariableBindings.protected voidencodeVariableBinding(org.snmp4j.smi.VariableBinding vb, org.snmp4j.asn1.BEROutputStream outputStream) Encode aVariableBindingto aBEROutputStream.protected voidencodeVariableBinding(org.snmp4j.smi.VariableBinding vb, org.snmp4j.asn1.BEROutputStream outputStream, byte[] preEncodedVariable) Encode aVariableBindingwhere theVariablepart may already be available as a pre-computed BER byte sequence.protected byte[]encryptSecretToBerSequence(org.snmp4j.security.SecretOctetString secret) Encrypts aSecretOctetStringvalue and returns the BER-encoded SEQUENCE that replaces the variable on the wire.protected Set<org.snmp4j.smi.OctetString> getContexts(org.snmp4j.agent.ManagedObject<?> managedObject) Get the contexts registered with allMOServerfor the givenManagedObject.Returns the encryption algorithm identifier used to protectSecretOctetStringvalues that are newly written to persistent storage.jetbrains.exodus.env.EnvironmentGets the XodusEnvironmentused by this persistent probvider.static intgetIndexOIDLength(int[] value) Get the index OID length from a index OID raw value.protected jetbrains.exodus.ByteIterablegetKey(org.snmp4j.smi.OID oid, org.snmp4j.smi.OID instanceID) Gets the key for an OID and instance ID.protected org.snmp4j.smi.OIDgetKeyOid(jetbrains.exodus.ByteIterable key) Gets the OID of a key.org.snmp4j.agent.MOScopeComparatorGets theMOScopeComparatorthat defines the default order in whichManagedObjects are stored and restored from persistent storage (unless the parameterMOPriorityProvideris used).org.snmp4j.agent.MOServer[]Get the associatedMOServers.Gets the current exception list for keepingRandomAccessManagedObjects persistent regardless theirRandomAccessManagedObject.isVolatile()value or not.Gets the saving strategy as defined byMOXodusPersistence.SavingStrategy.booleanisContextLoadable(org.snmp4j.smi.OctetString context) Checks if there is already MIB data stored for the specified context.booleanReturntrueif theregisterChangeListenersWithServer(MOServer)for any server, butunregisterChangeListenersWithServer(MOServer)has not been called yet.booleanReturnstrueif a master password is configured andSecretOctetStringvalues will therefore be encrypted on save and decrypted on load.booleanCheck whether change listener events are actually suppressed (i.e. ignored) or not.booleanReturns the flag controlling how encrypted secrets are handled when loading data without a master password set.voidload(org.snmp4j.agent.io.ImportMode importMode) Loads the contents of all managed objects using the specified import mode and the default load order.voidload(org.snmp4j.agent.io.ImportMode importMode, org.snmp4j.agent.mo.MOPriorityProvider priorityProvider) Load the contents of allRandomAccessManagedObjects usingRandomAccessManagedObject.importInstance(OID, List, ImportMode)calls.voidload(org.snmp4j.agent.io.ImportMode importMode, org.snmp4j.agent.mo.MOPriorityProvider priorityProvider, boolean includeVolatile) Load the contents of allRandomAccessManagedObjects usingRandomAccessManagedObject.importInstance(OID, List, ImportMode)calls.protected MOXodusPersistence.EncryptionSpecParses aMOXodusPersistenceencryption algorithm identifier into a structuredMOXodusPersistence.EncryptionSpec.voidregisterChangeListenersWithServer(org.snmp4j.agent.MOServer moServer) Register this object asMOChangeListeneron allRandomAccessManagedObjectinstances in the providedMOServer.protected voidrunSynchronization(Map<org.snmp4j.smi.OctetString, jetbrains.exodus.env.Store> stores, jetbrains.exodus.env.Transaction txn, org.snmp4j.agent.io.ImportMode importMode, Iterator<Map.Entry<org.snmp4j.agent.MOScope, org.snmp4j.agent.ManagedObject<?>>> moIterator, boolean includeVolatile) Run synchronisation between in memory data and on disk data.protected org.snmp4j.agent.ManagedObject<?> runSyncOnBootMO(jetbrains.exodus.env.Transaction txn, org.snmp4j.agent.MOServer moServer, Map<org.snmp4j.smi.OctetString, jetbrains.exodus.env.Store> stores, org.snmp4j.agent.io.ImportMode importMode, org.snmp4j.agent.mo.MOPriorityProvider priorityProvider, org.snmp4j.smi.OctetString context) Run synchronisation on the bootManagedObject(i.e. theManagedObjectrestored before any other.voidsave()Saves the data of theMOServers associated with this instance to persistent storage depending on the currently configuredMOXodusPersistence.SavingStrategy.voidsave(org.snmp4j.agent.mo.MOPriorityProvider priorityProvider) Saves the data of theMOServers associated with this instance to persistent storage depending on the currently configuredMOXodusPersistence.SavingStrategy.voidsaveFullDump(org.snmp4j.agent.mo.MOPriorityProvider priorityProvider, boolean includeVolatile) Saves the data of theMOServers associated with this instance to persistent storage independent of the currently setMOXodusPersistence.SavingStrategy.voidsetDefaultEncryptionAlgorithm(String defaultEncryptionAlgorithm) Sets the encryption algorithm identifier used to protectSecretOctetStringvalues that are subsequently written to persistent storage.voidsetIgnoreChangeListenerEvents(boolean ignoreChangeListenerEvents) Defines whetherMOChangeEvents should be ignored or not.voidsetIgnoreEncryptedDataWithoutPassword(boolean ignoreEncryptedDataWithoutPassword) Controls how the persistence loader reacts when it encounters an encryptedSecretOctetStringbut no master password has been configured.voidsetMoScopeComparator(org.snmp4j.agent.MOScopeComparator moScopeComparator) Sets theMOScopeComparatorand by this defines the default order in whichManagedObjects are stored and restored from persistent storage as long as parameterMOPriorityProviderofsave(MOPriorityProvider)andload(ImportMode, MOPriorityProvider)are not used.voidsetPersistenceExceptionList(Map<org.snmp4j.smi.OID, Boolean> persistenceExceptionList) Sets the current exception list for keepingRandomAccessManagedObjects persistent regardless theirRandomAccessManagedObject.isVolatile()value or not.voidsetSavingStrategy(MOXodusPersistence.SavingStrategy savingStrategy) Sets the saving strategy for this persistence provider as defined byMOXodusPersistence.SavingStrategy.protected StringstoreNameFromContext(org.snmp4j.smi.OctetString context) Return a string store name for the provided SNMPv3 context.voidunregisterChangeListenersWithServer(org.snmp4j.agent.MOServer moServer) Removes a former registration of this object asMOChangeListeneron allRandomAccessManagedObjectinstances in the providedMOServer.
-
Field Details
-
DEFAULT_ENCRYPTION_ALGORITHM
The default encryption algorithm identifier used byMOXodusPersistencefor protectingSecretOctetStringvalues stored to disk. The format is:<KDF>:<iterations>:<cipherTransformation>:<keyBits>
The default uses PBKDF2 with HMAC-SHA-256 (600.000 iterations as recommended by OWASP) for key derivation and AES in GCM mode with a 256-bit key for authenticated encryption.- Since:
- 3.8.0
- See Also:
-
-
Constructor Details
-
MOXodusPersistence
public MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment) Creates a newMOXodusPersistencefrom an array ofMOServerinstances and an XodusEnvironment. The data of modified objects are stored whenever a correspondingMOChangeEventis received.- Parameters:
moServers- theManagedObjectservers of the agent to be supported with persistent storage capabilities by this object.environment- the Xodus environment that actually holds the persistent data.
-
MOXodusPersistence
public MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment, MOXodusPersistence.SavingStrategy savingStrategy) - Parameters:
moServers- theManagedObjectservers of the agent to be supported with persistent storage capabilities by this object.environment- the Xodus environment that actually holds the persistent data.savingStrategy- defines when and how modified objects of the agent should be saved into persistent storage.
-
MOXodusPersistence
public MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment, MOXodusPersistence.SavingStrategy savingStrategy, org.snmp4j.agent.MOScopeComparator moScopeComparator) - Parameters:
moServers- theManagedObjectservers of the agent to be supported with persistent storage capabilities by this object.environment- the Xodus environment that actually holds the persistent data.savingStrategy- defines when and how modified objects of the agent should be saved into persistent storage.moScopeComparator- defines the order in whichManagedObjects are stored and restored from persistent storage. Ifnull, theMOScopeComparatoris used that sorts the registered managed objects by their lower bound OID in ascending order.- Since:
- 3.5.0
-
MOXodusPersistence
public MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment, char[] masterPassword) Creates a newMOXodusPersistencefrom an array ofMOServerinstances, an XodusEnvironment, and a master password used to encrypt everySecretOctetStringvalue before it is written to persistent storage. The agent's data is restored using the same master password to decrypt those values again whenload(ImportMode)(or one of its overloads) is invoked.Existing constructors of this class create instances without encryption; passing a non-null master password is the only way to activate encryption. The default encryption algorithm is
DEFAULT_ENCRYPTION_ALGORITHMand can be changed viasetDefaultEncryptionAlgorithm(String)for newly written data. Already stored secrets carry their own algorithm identifier and can be decrypted independently of the current default.- Parameters:
moServers- theManagedObjectservers of the agent to be supported with persistent storage capabilities.environment- the Xodus environment that actually holds the persistent data.masterPassword- the master password used to derive the symmetric key that protectsSecretOctetStringvalues. The array is defensively copied. Passnullto disable encryption (in which case you should use one of the password-less constructors instead).- Since:
- 3.8.0
-
MOXodusPersistence
public MOXodusPersistence(org.snmp4j.agent.MOServer[] moServers, jetbrains.exodus.env.Environment environment, MOXodusPersistence.SavingStrategy savingStrategy, org.snmp4j.agent.MOScopeComparator moScopeComparator, char[] masterPassword) Creates a newMOXodusPersistencewith explicitMOXodusPersistence.SavingStrategy, comparator and master password. SeeMOXodusPersistence(MOServer[], Environment, char[])for the encryption semantics.- Parameters:
moServers- theManagedObjectservers of the agent to be supported with persistent storage capabilities.environment- the Xodus environment that actually holds the persistent data.savingStrategy- defines when and how modified objects of the agent should be saved into persistent storage.moScopeComparator- defines the order in whichManagedObjects are stored and restored from persistent storage. Ifnull, a defaultMOScopeComparatoris used.masterPassword- the master password used to derive the symmetric key that protectsSecretOctetStringvalues. The array is defensively copied. Passnullto disable encryption.- Since:
- 3.8.0
-
-
Method Details
-
getSavingStrategy
Gets the saving strategy as defined byMOXodusPersistence.SavingStrategy.- Returns:
- the current managed object saving strategy.
-
setSavingStrategy
Sets the saving strategy for this persistence provider as defined byMOXodusPersistence.SavingStrategy.- Parameters:
savingStrategy- the new managed object saving strategy.
-
isIgnoreChangeListenerEvents
public boolean isIgnoreChangeListenerEvents()Check whether change listener events are actually suppressed (i.e. ignored) or not.- Returns:
trueif change listener events will be ignored.
-
setIgnoreChangeListenerEvents
public void setIgnoreChangeListenerEvents(boolean ignoreChangeListenerEvents) Defines whetherMOChangeEvents should be ignored or not. This method can be used to disable persistent storage activities when the default strategyMOXodusPersistence.SavingStrategy.onChangeEventsOnlyis active and other bulk operations change MIB data in the agent. When activating the processing ofMOChangeEvents is activated again by setting this value tofalse, the missed events will not be processed again. Thus, if data has changed that need to be persistent, thesave()has to be called with strategyMOXodusPersistence.SavingStrategy.checkForModificationsOnSaveorMOXodusPersistence.SavingStrategy.fullDumpOnSavemanually.- Parameters:
ignoreChangeListenerEvents-trueto disable event processing and saving changes triggered byMOChangeEvents.
-
isEncryptionEnabled
public boolean isEncryptionEnabled()Returnstrueif a master password is configured andSecretOctetStringvalues will therefore be encrypted on save and decrypted on load.- Returns:
- whether encryption of
SecretOctetStringvalues is active. - Since:
- 3.8.0
-
getDefaultEncryptionAlgorithm
Returns the encryption algorithm identifier used to protectSecretOctetStringvalues that are newly written to persistent storage. Values that have already been stored carry their own algorithm identifier and remain decryptable independent of this setting.- Returns:
- an algorithm identifier of the form
<KDF>:<iterations>:<cipherTransformation>:<keyBits>, by defaultDEFAULT_ENCRYPTION_ALGORITHM. - Since:
- 3.8.0
-
setDefaultEncryptionAlgorithm
Sets the encryption algorithm identifier used to protectSecretOctetStringvalues that are subsequently written to persistent storage. The value must be parseable byparseEncryptionAlgorithm(String).- Parameters:
defaultEncryptionAlgorithm- a non-null algorithm identifier of the form<KDF>:<iterations>:<cipherTransformation>:<keyBits>.- Since:
- 3.8.0
-
isIgnoreEncryptedDataWithoutPassword
public boolean isIgnoreEncryptedDataWithoutPassword()Returns the flag controlling how encrypted secrets are handled when loading data without a master password set. SeesetIgnoreEncryptedDataWithoutPassword(boolean)for details.- Returns:
trueif encrypted secrets are passed through as opaqueSecretOctetStrings when no master password is set;false(the default) if loading aborts in that situation.- Since:
- 3.8.0
-
setIgnoreEncryptedDataWithoutPassword
public void setIgnoreEncryptedDataWithoutPassword(boolean ignoreEncryptedDataWithoutPassword) Controls how the persistence loader reacts when it encounters an encryptedSecretOctetStringbut no master password has been configured. Iftrue, the raw BER encoded sequence representing the encrypted value is wrapped into aSecretOctetStringand returned to the agent as-is — allowing data to be re-saved untouched when the password is unknown. Iffalse(the default), the loader logs a fatal error and aborts with aRuntimeException.- Parameters:
ignoreEncryptedDataWithoutPassword-trueto suppress the fatal error and return the encrypted bytes as aSecretOctetString.- Since:
- 3.8.0
-
getEnvironment
public jetbrains.exodus.env.Environment getEnvironment()Gets the XodusEnvironmentused by this persistent probvider.- Returns:
- a
Environment.
-
isContinuousChangeListening
public boolean isContinuousChangeListening()Returntrueif theregisterChangeListenersWithServer(MOServer)for any server, butunregisterChangeListenersWithServer(MOServer)has not been called yet.- Returns:
trueif theregisterChangeListenersWithServer(MOServer)for any server.
-
registerChangeListenersWithServer
public void registerChangeListenersWithServer(org.snmp4j.agent.MOServer moServer) Register this object asMOChangeListeneron allRandomAccessManagedObjectinstances in the providedMOServer.- Parameters:
moServer- aMOServerholdingRandomAccessManagedObjects that should be persisted.
-
unregisterChangeListenersWithServer
public void unregisterChangeListenersWithServer(org.snmp4j.agent.MOServer moServer) Removes a former registration of this object asMOChangeListeneron allRandomAccessManagedObjectinstances in the providedMOServer.- Parameters:
moServer- aMOServerholdingRandomAccessManagedObjects that should not be persisted anymore.
-
isContextLoadable
public boolean isContextLoadable(org.snmp4j.smi.OctetString context) Checks if there is already MIB data stored for the specified context. To check the default context (null), please use the emptyOctetString. This method should be called before callingload(ImportMode)because afterwards it will returntruefor all contexts that were present ingetMOServer()and for the default context (empty context).- Parameters:
context- a non-null context string. The empty (zero length)OctetStringrepresents the default context.- Returns:
trueif there has been data stored for this context - even if noRandomAccessManagedObjectactually has stored any data.- Since:
- 3.0.1
-
load
public void load(org.snmp4j.agent.io.ImportMode importMode) Loads the contents of all managed objects using the specified import mode and the default load order. This is a convenience method that callsload(ImportMode, MOPriorityProvider)with anullpriority provider.- Parameters:
importMode- controls how existing data is used or not used during import.
-
load
public void load(org.snmp4j.agent.io.ImportMode importMode, org.snmp4j.agent.mo.MOPriorityProvider priorityProvider) Load the contents of allRandomAccessManagedObjects usingRandomAccessManagedObject.importInstance(OID, List, ImportMode)calls. The providedImportModethereby defines how the data handles existing data. Data is loaded for all contexts and managed objects found in the {link MOServer} instances provided during object creation. While loading, the memberignoreChangeListenerEventsis set totrueto ignore updates caused by loading data into theRandomAccessManagedObjectinstances. UsesetMoScopeComparator(MOScopeComparator)to modify the order in whichManagedObjects are loaded. Since version 3.5.0, objects are loaded in the order defined by theMOPriorityProvidergiven in order to facilitate loading and especially initialization ofManagedObjects that augment or extend base tables or depend on each other. For each context, a load order defined by the content of single bootManagedObjectcan be defined. In most cases, a single order defined in the default (null) context is sufficient.- Parameters:
importMode- controls how existing data is used or not used during import.priorityProvider- if notnull, it provides the order for loading and initializing managed objects byMOPriorityProvider.getPriorityMap(OctetString).
-
load
public void load(org.snmp4j.agent.io.ImportMode importMode, org.snmp4j.agent.mo.MOPriorityProvider priorityProvider, boolean includeVolatile) Load the contents of allRandomAccessManagedObjects usingRandomAccessManagedObject.importInstance(OID, List, ImportMode)calls. The providedImportModethereby defines how the data handles existing data. Data is loaded for all contexts and managed objects found in the {link MOServer} instances provided during object creation. While loading, the memberignoreChangeListenerEventsis set totrueto ignore updates caused by loading data into theRandomAccessManagedObjectinstances. UsesetMoScopeComparator(MOScopeComparator)to modify the order in whichManagedObjects are loaded. Since version 3.5.0, objects are loaded in the order defined by theMOPriorityProvidergiven in order to facilitate loading and especially initialization ofManagedObjects that augment or extend base tables or depend on each other. For each context, a load order defined by the content of single bootManagedObjectcan be defined. In most cases, a single order defined in the default (null) context is sufficient.- Parameters:
importMode- controls how existing data is used or not used during import.priorityProvider- if notnull, it provides the order for loading and initializing managed objects byMOPriorityProvider.getPriorityMap(OctetString).includeVolatile- iftrue,RandomAccessManagedObjects withRandomAccessManagedObject.isVolatile()truewill be saved too, otherwise those objects will not be saved.- Since:
- 3.6.0
-
runSyncOnBootMO
protected org.snmp4j.agent.ManagedObject<?> runSyncOnBootMO(jetbrains.exodus.env.Transaction txn, org.snmp4j.agent.MOServer moServer, Map<org.snmp4j.smi.OctetString, jetbrains.exodus.env.Store> stores, org.snmp4j.agent.io.ImportMode importMode, org.snmp4j.agent.mo.MOPriorityProvider priorityProvider, org.snmp4j.smi.OctetString context) Run synchronisation on the bootManagedObject(i.e. theManagedObjectrestored before any other.- Parameters:
txn- theTransaction.moServer- theMOServer.stores- the stores containing the persistent data.importMode- theImportModeto be used.priorityProvider- theMOPriorityProviderthat defines the restore priorities.context- the context to restore- Returns:
- the boot
ManagedObject.
-
createStore
protected jetbrains.exodus.env.Store createStore(jetbrains.exodus.env.Transaction txn, org.snmp4j.smi.OctetString context) Ceates aStorefor a context.- Parameters:
txn- theTransaction.context- the context.- Returns:
- a new opened
Store;
-
storeNameFromContext
Return a string store name for the provided SNMPv3 context.- Parameters:
context- a context name ornullfor the default context.- Returns:
- a store name, by default
context == null ? "" : context.toHexString(). - Since:
- 3.0.1
-
getMOServer
public org.snmp4j.agent.MOServer[] getMOServer()Get the associatedMOServers.- Returns:
- an array of
MOServerinstances.
-
getMoScopeComparator
public org.snmp4j.agent.MOScopeComparator getMoScopeComparator()Gets theMOScopeComparatorthat defines the default order in whichManagedObjects are stored and restored from persistent storage (unless the parameterMOPriorityProvideris used).- Returns:
- a
MOScopeComparatorinstance.
-
setMoScopeComparator
public void setMoScopeComparator(org.snmp4j.agent.MOScopeComparator moScopeComparator) Sets theMOScopeComparatorand by this defines the default order in whichManagedObjects are stored and restored from persistent storage as long as parameterMOPriorityProviderofsave(MOPriorityProvider)andload(ImportMode, MOPriorityProvider)are not used. If set tonull, theMOScopeComparatoris used that sorts the registered managed objects by their lower bound OID in ascending order.- Parameters:
moScopeComparator- defines the order in whichManagedObjects are stored and restored from persistent storage. Ifnull, theMOScopeComparatoris used that sorts the registered managed objects by their lower bound OID in ascending order.
-
runSynchronization
protected void runSynchronization(Map<org.snmp4j.smi.OctetString, jetbrains.exodus.env.Store> stores, jetbrains.exodus.env.Transaction txn, org.snmp4j.agent.io.ImportMode importMode, Iterator<Map.Entry<org.snmp4j.agent.MOScope, org.snmp4j.agent.ManagedObject<?>>> moIterator, boolean includeVolatile) Run synchronisation between in memory data and on disk data.- Parameters:
stores- the context stores.txn- theTransaction.importMode- the import mode to use.moIterator- the object iterator over theManagedObjects to be synchronized.includeVolatile- iftrue,RandomAccessManagedObjects withRandomAccessManagedObject.isVolatile()truewill be saved too, otherwise those objects will not be saved.
-
decodeInstanceData
protected List<org.snmp4j.smi.VariableBinding> decodeInstanceData(jetbrains.exodus.ByteIterable rawData) Decode BER instance data from raw byte stream.- Parameters:
rawData- the BER encoded data.- Returns:
- the decoded list of
VariableBindings.
-
encodeInstanceData
Encode instance data from a list ofVariableBindings.- Parameters:
vbs- a list ofVariableBindings.- Returns:
- a BER encoded byte array.
-
decodeVariableBinding
protected org.snmp4j.smi.VariableBinding decodeVariableBinding(org.snmp4j.asn1.BERInputStream inputStream) throws IOException Decode aVariableBindingfrom anBERInputStream.- Parameters:
inputStream- theBERInputStream- Returns:
- the decoded
VariableBinding. - Throws:
IOException- if BER encoding is wrong.
-
encodeVariableBinding
protected void encodeVariableBinding(org.snmp4j.smi.VariableBinding vb, org.snmp4j.asn1.BEROutputStream outputStream) throws IOException Encode aVariableBindingto aBEROutputStream. If a master password has been configured (seeMOXodusPersistence(MOServer[], Environment, char[])) and the value ofvbis aSecretOctetString, the value is encrypted before being written. The encrypted representation replaces the originalVariablewith a BERBER.SEQUENCEconsisting of three OCTET STRINGs (algorithm identifier, ciphertext with IV prefix, KDF salt).- Parameters:
vb- aVariableBinding.outputStream- aBEROutputStream.- Throws:
IOException- on a buffer overflow.
-
encodeVariableBinding
protected void encodeVariableBinding(org.snmp4j.smi.VariableBinding vb, org.snmp4j.asn1.BEROutputStream outputStream, byte[] preEncodedVariable) throws IOException Encode aVariableBindingwhere theVariablepart may already be available as a pre-computed BER byte sequence. This overload is used internally to avoid encrypting twice (once during size calculation, once during the actual write).- Parameters:
vb- theVariableBinding.outputStream- the targetBEROutputStream.preEncodedVariable- if non-null, the bytes are written verbatim in place ofvb.getVariable().encodeBER(...); if null, the variable encodes itself.- Throws:
IOException- on a buffer overflow.- Since:
- 3.8.0
-
getKey
protected jetbrains.exodus.ByteIterable getKey(org.snmp4j.smi.OID oid, org.snmp4j.smi.OID instanceID) Gets the key for an OID and instance ID.- Parameters:
oid- a OID.instanceID- an instance ID.- Returns:
- a byte stream encoded unique key.
-
getKeyOid
protected org.snmp4j.smi.OID getKeyOid(jetbrains.exodus.ByteIterable key) Gets the OID of a key.- Parameters:
key- a byte stream containing a key.- Returns:
- the OID portion of the key.
-
save
public void save()Saves the data of theMOServers associated with this instance to persistent storage depending on the currently configuredMOXodusPersistence.SavingStrategy. If that strategy isMOXodusPersistence.SavingStrategy.onChangeEventsOnly, calling this method will have no effect, except that it setssetIgnoreChangeListenerEvents(boolean)tofalsein any case. UsesetMoScopeComparator(MOScopeComparator)to modify the order in whichManagedObjects are stored. -
save
public void save(org.snmp4j.agent.mo.MOPriorityProvider priorityProvider) Saves the data of theMOServers associated with this instance to persistent storage depending on the currently configuredMOXodusPersistence.SavingStrategy. If that strategy isMOXodusPersistence.SavingStrategy.onChangeEventsOnly, calling this method will have no effect, except that it setssetIgnoreChangeListenerEvents(boolean)tofalsein any case. UsesetMoScopeComparator(MOScopeComparator)to modify the order in whichManagedObjects are stored. Since version 3.5.0, objects are saved in the order defined by theMOPriorityProvidergiven in order to facilitate saving ofManagedObjects that augment or extend base tables or depend on each other.- Parameters:
priorityProvider- if notnull, it provides the order for saving the managed objects byMOPriorityProvider.getPriorityMap(OctetString).
-
saveFullDump
public void saveFullDump(org.snmp4j.agent.mo.MOPriorityProvider priorityProvider, boolean includeVolatile) Saves the data of theMOServers associated with this instance to persistent storage independent of the currently setMOXodusPersistence.SavingStrategy. In other words, any non-volatileManagedObjectwill be saved to persistent storage.- Parameters:
priorityProvider- if notnull, it provides the order for saving the managed objects byMOPriorityProvider.getPriorityMap(OctetString).includeVolatile- iftrue,RandomAccessManagedObjects withRandomAccessManagedObject.isVolatile()truewill be saved too, otherwise those objects will not be saved.- Since:
- 3.6.0
-
encodeIndexOID
Encodes an index OID.- Parameters:
os- theBEROutputStreamto encode to.type- the type of the index OID (i.e.OID.getSyntax().oid- the OID value to encode.- Throws:
IOException- if the output stream throws anIOException.
-
getIndexOIDLength
public static int getIndexOIDLength(int[] value) Get the index OID length from a index OID raw value.- Parameters:
value- the OID raw value (seeOID.getValue().- Returns:
- the length of the index.
-
decodeIndexOID
public static int[] decodeIndexOID(org.snmp4j.asn1.BERInputStream is, org.snmp4j.asn1.BER.MutableByte type) throws IOException Decode a indexOIDfrom a BER input stream.- Parameters:
is- theBERInputStreamcontaining the OID.type- the object type read is returned here.- Returns:
- the decoded OID.
- Throws:
IOException- if the encoded is wrong.
-
beforePrepareMOChange
public void beforePrepareMOChange(org.snmp4j.agent.mo.MOChangeEvent changeEvent) A ManagedObject change is being prepared. To cancel preparation set the deny reason to a SNMPv2/v3 error status.- Specified by:
beforePrepareMOChangein interfaceorg.snmp4j.agent.mo.MOChangeListener- Parameters:
changeEvent- the change event object.
-
afterPrepareMOChange
public void afterPrepareMOChange(org.snmp4j.agent.mo.MOChangeEvent changeEvent) A change has been prepared. Setting the deny reason of the supplied event object will be ignored.- Specified by:
afterPrepareMOChangein interfaceorg.snmp4j.agent.mo.MOChangeListener- Parameters:
changeEvent- the change event object.
-
beforeMOChange
public void beforeMOChange(org.snmp4j.agent.mo.MOChangeEvent changeEvent) A ManagedObject change is being committed. To cancel the commit phase set the deny reason to a SNMPv2/v3 error status.NOTE: Canceling the commit phase must be avoided. Setting a deny reason has only an effect if
DeniableEventObject.isDeniable()returnstrue. Otherwise, you will need to throw an exception.- Specified by:
beforeMOChangein interfaceorg.snmp4j.agent.mo.MOChangeListener- Parameters:
changeEvent- the change event object.
-
getPersistenceExceptionList
Gets the current exception list for keepingRandomAccessManagedObjects persistent regardless theirRandomAccessManagedObject.isVolatile()value or not. ARandomAccessManagedObjectis kept exceptionally persistent if its OID is key of the returned list and its value istrue. If the value isfalse, the correspondingRandomAccessManagedObjectwill not be stored/restored even if it is non-volatile (i.e.,RandomAccessManagedObject.isVolatile()returnsfalse).- Returns:
- the exception list. If
nullis returned, there are no exceptions defined/active (same effect as an empty exception list). - Since:
- 3.6.0
-
setPersistenceExceptionList
Sets the current exception list for keepingRandomAccessManagedObjects persistent regardless theirRandomAccessManagedObject.isVolatile()value or not. ARandomAccessManagedObjectis kept exceptionally persistent if its OID is key of the provided list and its value istrue. If the value isfalse, the correspondingRandomAccessManagedObjectwill not be stored/restored even if it is non-volatile (i.e.,RandomAccessManagedObject.isVolatile()returnsfalse). ForRandomAccessManagedObjects with a rang eof OIDs, the lower bound of itsMOScopehas to be provided.- Parameters:
persistenceExceptionList- the exception list. Ifnullis provided, there are no exceptions defined/active (same effect as an empty exception list).- Since:
- 3.6.0
-
afterMOChange
public void afterMOChange(org.snmp4j.agent.mo.MOChangeEvent changeEvent) A change has been committed. Setting the deny reason of the supplied event object will be ignored.- Specified by:
afterMOChangein interfaceorg.snmp4j.agent.mo.MOChangeListener- Parameters:
changeEvent- the change event object.
-
getContexts
protected Set<org.snmp4j.smi.OctetString> getContexts(org.snmp4j.agent.ManagedObject<?> managedObject) Get the contexts registered with allMOServerfor the givenManagedObject.- Parameters:
managedObject- the managed object.- Returns:
- the set of registered contexts, see also
MOServer.getRegisteredContexts(ManagedObject).
-
encryptSecretToBerSequence
protected byte[] encryptSecretToBerSequence(org.snmp4j.security.SecretOctetString secret) Encrypts aSecretOctetStringvalue and returns the BER-encoded SEQUENCE that replaces the variable on the wire. The returned bytes form a complete BER object (tag + length + content) with three OCTET STRING children: the algorithm identifier, the ciphertext (with the cipher IV prefixed), and the random PBKDF2 salt.- Parameters:
secret- the value to encrypt. Must not be null.- Returns:
- a BER-encoded SEQUENCE replacing the
Variableportion of theVariableBinding. - Since:
- 3.8.0
-
decodeEncryptedSecretOctetString
protected org.snmp4j.smi.Variable decodeEncryptedSecretOctetString(org.snmp4j.asn1.BERInputStream inputStream) throws IOException Decodes a BER SEQUENCE that wraps an encryptedSecretOctetStringand returns the decrypted value asSecretOctetString. The input stream must be positioned at the SEQUENCE tag.If no master password is configured, behaviour depends on
isIgnoreEncryptedDataWithoutPassword(): whentrue, the raw BER octet stream of the sequence (including header) is returned wrapped in aSecretOctetStringso that the data can be passed through unchanged. Whenfalse, a fatal log message is emitted and aRuntimeExceptionis thrown to abort the load.- Parameters:
inputStream- aBERInputStreampositioned at the SEQUENCE tag of an encrypted secret.- Returns:
- the decrypted
SecretOctetString, or the opaque raw bytes if no password is set and the ignore-flag has been activated. - Throws:
IOException- if the input stream is malformed or decryption fails.- Since:
- 3.8.0
-
deriveKey
protected SecretKey deriveKey(char[] password, byte[] salt, MOXodusPersistence.EncryptionSpec spec) throws GeneralSecurityException Derives an AESSecretKeyfrompasswordandsaltusing the KDF named inspec. The returned key is wrapped in aSecretKeySpecthat uses the cipher algorithm (the part before the first "/" in the transformation string) so that it can be passed toCipher.init(int, java.security.Key, java.security.spec.AlgorithmParameterSpec).- Parameters:
password- the master password (defensively cleared inside the PBE key spec).salt- the per-value random salt.spec- the parsed encryption algorithm specification.- Returns:
- a
SecretKeyusable with the configured cipher. - Throws:
GeneralSecurityException- if the JCE provider does not support the requested KDF or key size.- Since:
- 3.8.0
-
parseEncryptionAlgorithm
Parses aMOXodusPersistenceencryption algorithm identifier into a structuredMOXodusPersistence.EncryptionSpec. The expected format is<KDF>:<iterations>:<cipherTransformation>:<keyBits>, e.g.PBKDF2WithHmacSHA256:600000:AES/GCM/NoPadding:256.- Parameters:
id- the algorithm identifier.- Returns:
- the parsed
MOXodusPersistence.EncryptionSpec. - Throws:
IllegalArgumentException- ifiddoes not have the expected format or contains invalid values.- Since:
- 3.8.0
-