/** * Builds target resource. * @param context Process context */ private void buildTargetResource(ProcessContext context) { if((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) { try { this.transportMapping = new DefaultUdpTransportMapping(); this.snmp = new Snmp(this.transportMapping); if("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) { USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); } this.transportMapping.listen(); } catch (Exception e) { throw new IllegalStateException("Failed to initialize UDP transport mapping", e); } } if (this.snmpTarget == null) { this.snmpTarget = this.createSnmpTarget(context); } if (this.targetResource == null) { this.targetResource = this.finishBuildingTargetResource(context); } }
/** * Gets the security model for the supplied ID. * @param id * a security model ID. * @return * a {@link SecurityModel} instance if the supplied ID * is supported, otherwise {@code null} is returned. */ public SecurityModel getSecurityModel(int id) { return securityModels.getSecurityModel(new Integer32(id)); }
/** * Gets the SecurityModels collection instance that contains the supplied * {@link SecurityModel}s. * @param models * an array of {@link SecurityModel} instances. * @return * a new instance of SecurityModels that contains the supplied models. * @since 1.10 */ public static final SecurityModels getCollection(SecurityModel[] models) { SecurityModels smc = new SecurityModels(); for (int i=0; i<models.length; i++) { smc.addSecurityModel(models[i]); } return smc; }
public boolean isValidIndex(OID index) { boolean ok = super.isValidIndex(index); if (ok) { SecurityModels secModels = SecurityModels.getInstance(); if (secModels.getSecurityModel(new Integer32(index.get(0))) == null) { return false; } } return ok; } };
/** * Creates a MPv3 with a supplied local engine ID and {@link PDUFactory} * for incoming messages. * @param localEngineID * the local engine ID. Its length must be >= 5 and <= 32. * @param incomingPDUFactory * a {@link PDUFactory}. If <code>null</code> the default factory will be * used which creates {@link ScopedPDU} instances. * @since 1.9.1 */ public MPv3(byte[] localEngineID, PDUFactory incomingPDUFactory) { this(localEngineID, incomingPDUFactory, SecurityProtocols.getInstance(), SecurityModels.getInstance(), CounterSupport.getInstance()); }
@Override protected void doStop() throws Exception { super.doStop(); try { SecurityModels.getInstance().removeSecurityModel(new Integer32(this.usm.getID())); } finally { this.targetAddress = null; this.usm = null; this.target = null; this.pdu = null; } }
/** * Gets the security singleton instance. * @return * the <code>SecurityModels</code> instance. */ public synchronized static SecurityModels getInstance() { if (instance == null) { instance = new SecurityModels(); } return instance; }
/** * This is a convenience constructor which can be used to create a MPv3 which * is bound to a specific USM instance. A dedicated USM instance per * MPv3 is necessary if multiple {@link Snmp} instances are used within a VM. * @param usm * an USM instance. * @since 1.10 */ public MPv3(USM usm) { this(usm.getLocalEngineID().getValue(), null, SecurityProtocols.getInstance(), SecurityModels.getCollection(new SecurityModel[]{usm}), CounterSupport.getInstance()); }
public boolean isValidIndex(OID index) { boolean ok = super.isValidIndex(index); int securityModel = index.get(0); if (ok && (securityModel > SecurityModel.SECURITY_MODEL_SNMPv2c)) { SecurityModels secModels = SecurityModels.getInstance(); if (secModels.getSecurityModel(new Integer32(securityModel)) == null) { return false; } } return ok; } };
/** * Creates a MPv3 with a supplied local engine ID and {@link PDUFactory} * for incoming messages. * @param localEngineID * the local engine ID. Its length must be greater or equal than 5 and less or equal than 32. * @param incomingPDUFactory * a {@link PDUFactory}. If {@code null} the default factory will be * used which creates {@link ScopedPDU} instances. * @since 1.9.1 */ public MPv3(byte[] localEngineID, PDUFactory incomingPDUFactory) { this(localEngineID, incomingPDUFactory, SecurityProtocols.getInstance(), SecurityModels.getInstance(), CounterSupport.getInstance()); }
@Override protected void doStop() throws Exception { super.doStop(); try { SecurityModels.getInstance().removeSecurityModel(new Integer32(this.usm.getID())); } finally { this.targetAddress = null; this.usm = null; this.target = null; } }
/** * Gets the security singleton instance. * * @return the <code>SecurityModels</code> instance. */ public synchronized static SecurityModels getInstance() { if (instance == null) { instance = new SecurityModels(); } return instance; }
/** * This is a convenience constructor which can be used to create a MPv3 which * is bound to a specific USM instance. A dedicated USM instance per * MPv3 is necessary if multiple {@link Snmp} instances are used within a VM. * @param usm * an USM instance. * @since 1.10 */ public MPv3(USM usm) { this(usm.getLocalEngineID().getValue(), null, SecurityProtocols.getInstance(), SecurityModels.getCollection(new SecurityModel[] { usm }), CounterSupport.getInstance()); }
private void addSecurityModels() { SecurityModels.getInstance().addSecurityModel( new SecurityModel() { SecurityModels.getInstance().addSecurityModel( new SecurityModel() {
public void validate(MOValueValidationEvent validationEvent) { //--AgentGen BEGIN=snmpTargetParamsSecurityModel::validate Variable newValue = validationEvent.getNewValue(); switch (((Integer32)newValue).getValue()) { case SecurityModel.SECURITY_MODEL_USM: { if (SecurityModels.getInstance(). getSecurityModel((Integer32) newValue) == null) { validationEvent.setValidationStatus(SnmpConstants. SNMP_ERROR_WRONG_VALUE); return; } break; } default: break; } //--AgentGen END } }
/** * Gets the SecurityModels collection instance that contains the supplied * {@link SecurityModel}s. * @param models * an array of {@link SecurityModel} instances. * @return * a new instance of SecurityModels that contains the supplied models. * @since 1.10 */ public static SecurityModels getCollection(SecurityModel[] models) { SecurityModels smc = new SecurityModels(); for (SecurityModel model : models) { smc.addSecurityModel(model); } return smc; }
/** * Creates a MPv3 with a supplied local engine ID and {@link PDUFactory} * for incoming messages. * @param localEngineID * the local engine ID. Its length must be greater or equal than 5 and less or equal than 32. * @param incomingPDUFactory * a {@link PDUFactory}. If {@code null} the default factory will be * used which creates {@link ScopedPDU} instances. * @since 1.9.1 */ public MPv3(byte[] localEngineID, PDUFactory incomingPDUFactory) { this(localEngineID, incomingPDUFactory, SecurityProtocols.getInstance(), SecurityModels.getInstance(), CounterSupport.getInstance()); }
/** * Gets the security model for the supplied ID. * @param id * a security model ID. * @return * a <code>SecurityModel</code> instance if the supplied ID * is supported, otherwise <code>null</code> is returned. */ public SecurityModel getSecurityModel(int id) { return securityModels.getSecurityModel(new Integer32(id)); }
/** * Gets the security singleton instance. * @return * the <code>SecurityModels</code> instance. */ public synchronized static SecurityModels getInstance() { if (instance == null) { instance = new SecurityModels(); } return instance; }
/** * This is a convenience constructor which can be used to create a MPv3 which * is bound to a specific USM instance. A dedicated USM instance per * MPv3 is necessary if multiple {@link Snmp} instances are used within a VM. * @param usm * an USM instance. * @since 1.10 */ public MPv3(USM usm) { this(usm.getLocalEngineID().getValue(), null, SecurityProtocols.getInstance(), SecurityModels.getCollection(new SecurityModel[]{usm}), CounterSupport.getInstance()); }