本文整理汇总了Java中org.snmp4j.security.SecurityLevel类的典型用法代码示例。如果您正苦于以下问题:Java SecurityLevel类的具体用法?Java SecurityLevel怎么用?Java SecurityLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SecurityLevel类属于org.snmp4j.security包,在下文中一共展示了SecurityLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTargetV3
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
private Target getTargetV3() {
//logger.info("Use SNMP v3, "+this.privacyprotocol +"="+this.password+", "+this.privacyprotocol+"="+this.privacypassphrase);
OID authOID = AuthMD5.ID;
if("SHA".equals(this.authprotocol))
authOID = AuthSHA.ID;
OID privOID = PrivDES.ID;
if(this.privacyprotocol == null || this.privacyprotocol.isEmpty())
privOID = null;
UsmUser user = new UsmUser(new OctetString(this.username),
authOID, new OctetString(this.password), //auth
privOID, this.privacypassphrase!=null?new OctetString(this.privacypassphrase):null); //enc
snmp.getUSM().addUser(new OctetString(this.username), user);
Address targetAddress = GenericAddress.parse(address);
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(this.getVersionInt());
if(privOID != null)
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
else
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
target.setSecurityName(new OctetString(this.username));
return target;
}
示例2: addNotificationTargets
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB) {
targetMIB.addDefaultTDomains();
targetMIB.addTargetAddress(new OctetString("notification"),
TransportDomains.transportDomainUdpIpv4,
new OctetString(new UdpAddress("127.0.0.1/162").getValue()),
200, 1,
new OctetString("notify"),
new OctetString("v2c"),
StorageType.permanent);
targetMIB.addTargetParams(new OctetString("v2c"),
MessageProcessingModel.MPv2c,
SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString("public"),
SecurityLevel.NOAUTH_NOPRIV,
StorageType.permanent);
notificationMIB.addNotifyEntry(new OctetString("default"),
new OctetString("notify"),
SnmpNotificationMIB.SnmpNotifyTypeEnum.trap,
StorageType.permanent);
}
示例3: sendTest
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
public void sendTest(String agentAddress, int port, String community, PDU pdu) {
for (RegistrationInfo info : s_registrations.values()) {
if (port == info.getPort()) {
Snmp snmp = info.getSession();
MessageDispatcher dispatcher = snmp.getMessageDispatcher();
TransportMapping transport = info.getTransportMapping();
int securityModel = (pdu instanceof PDUv1 ? SecurityModel.SECURITY_MODEL_SNMPv1 :SecurityModel.SECURITY_MODEL_SNMPv2c);
int messageModel = (pdu instanceof PDUv1 ? MessageProcessingModel.MPv1 : MessageProcessingModel.MPv2c);
CommandResponderEvent e = new CommandResponderEvent(dispatcher, transport, new IpAddress(agentAddress), messageModel,
securityModel, community.getBytes(),
SecurityLevel.NOAUTH_NOPRIV, new PduHandle(), pdu, 1000, null);
info.getHandler().processPdu(e);
}
}
}
示例4: convertSecurityLevel
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
/**
* This method adapts the OpenNMS SNMPv3 security level constants
* to SNMP4J defined constants.
*
* @param securityLevel
* @return
*/
private int convertSecurityLevel(int securityLevel) {
switch (securityLevel) {
case SnmpAgentConfig.AUTH_NOPRIV :
securityLevel = SecurityLevel.AUTH_NOPRIV;
break;
case SnmpAgentConfig.AUTH_PRIV :
securityLevel = SecurityLevel.AUTH_PRIV;
break;
case SnmpAgentConfig.NOAUTH_NOPRIV :
securityLevel = SecurityLevel.NOAUTH_NOPRIV;
break;
default :
securityLevel = SecurityLevel.NOAUTH_NOPRIV;
}
return securityLevel;
}
示例5: getSNMPv3Target
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
/**
* This method returns a Target, which contains information about where the data should be fetched and how.
*
* @return
*/
private Target getSNMPv3Target() {
Address targetAddress = GenericAddress.parse(address);
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setVersion(SnmpConstants.version3); // SnmpConstants.version3
target.setRetries(2);
target.setTimeout(2500);
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV); // SecurityLevel.AUTH_NOPRIV
target.setSecurityName(new OctetString(ver3Username));
return target;
}
示例6: newTarget
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
@Override
public Target newTarget(SnmpTarget target) {
if (!(target instanceof SnmpV3Target)) return null;
SnmpV3Target v3Target = (SnmpV3Target) target;
Assert.notNull(v3Target.getSecurityName(), "securityName is required");
if (v3Target.getAuthPassphrase() != null) {
Assert.notNull(v3Target.getAuthType(), "authType is required");
}
if (v3Target.getPrivPassphrase() != null){
Assert.notNull(v3Target.getPrivType(), "privType is required");
}
OctetString securityName = new OctetString(v3Target.getSecurityName());
SecurityModels.getInstance().addSecurityModel(usm);
usm.addUser(new UsmUser(securityName,
authType(v3Target), new OctetString(v3Target.getAuthPassphrase()),
privType(v3Target), new OctetString(v3Target.getPrivPassphrase())));
SecurityModels.getInstance().addSecurityModel(new TSM(localEngineId, false));
UserTarget userTarget = new UserTarget();
userTarget.setSecurityName(securityName);
userTarget.setVersion(SnmpConstants.version3);
if (v3Target.getAuthType() == null && v3Target.getPrivType() == null) {
userTarget.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
}
else if (v3Target.getPrivType() == null) {
userTarget.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
}
else if (v3Target.getAuthType() != null) {
userTarget.setSecurityLevel(SecurityLevel.AUTH_PRIV);
}
else {
throw new IllegalStateException(
"cannot support privacy without authentication");
}
return userTarget;
}
示例7: sendTrapV3
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
public static void sendTrapV3(String port) {
try {
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/" + port);
TransportMapping<?> transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();
snmp.getUSM().addUser(new OctetString("MD5DES"),
new UsmUser(new OctetString("MD5DES"), null, null, null, null));
// Create Target
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(1);
target.setTimeout(11500);
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
target.setSecurityName(new OctetString("MD5DES"));
// Create PDU for V3
ScopedPDU pdu = new ScopedPDU();
pdu.setType(ScopedPDU.NOTIFICATION);
pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkDown));
pdu.add(new VariableBinding(new OID("1.2.3.4.5"), new OctetString("Major")));
// Send the PDU
snmp.send(pdu, target);
transport.close();
snmp.close();
} catch (Exception e) {
System.err.println("Error in Sending Trap to (IP:Port)=> " + "127.0.0.1" + ":" + port);
System.err.println("Exception Message = " + e.getMessage());
}
}
示例8: addViews
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
@Override
protected void addViews(final VacmMIB vacmMIB) {
log.trace("adding views in the vacm MIB {} for agent \"{}\"", vacmMIB.toString(), configuration.getName());
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1, new OctetString(configuration.getCommunity()), new OctetString("v1v2group"), StorageType.nonVolatile);
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c, new OctetString(configuration.getCommunity()), new OctetString("v1v2group"), StorageType.nonVolatile);
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_USM, new OctetString("SHADES"), new OctetString("v3group"), StorageType.nonVolatile);
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_USM, new OctetString("TEST"), new OctetString("v3test"), StorageType.nonVolatile);
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_USM, new OctetString("SHA"), new OctetString("v3restricted"), StorageType.nonVolatile);
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_USM, new OctetString("v3notify"), new OctetString("v3restricted"), StorageType.nonVolatile);
// configure community index contexts
for (final Long vlan : configuration.getDevice().getVlans()) {
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1, new OctetString(configuration.getCommunity() + "@" + vlan), new OctetString("v1v2group"), StorageType.nonVolatile);
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c, new OctetString(configuration.getCommunity() + "@" + vlan), new OctetString("v1v2group"), StorageType.nonVolatile);
vacmMIB.addAccess(new OctetString("v1v2group"), new OctetString(String.valueOf(vlan)), SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.NOAUTH_NOPRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadView"), new OctetString("fullWriteView"), new OctetString("fullNotifyView"), StorageType.nonVolatile);
}
vacmMIB.addAccess(new OctetString("v1v2group"), new OctetString(), SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.NOAUTH_NOPRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadView"), new OctetString("fullWriteView"), new OctetString("fullNotifyView"), StorageType.nonVolatile);
vacmMIB.addAccess(new OctetString("v3group"), new OctetString(), SecurityModel.SECURITY_MODEL_USM, SecurityLevel.AUTH_PRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadView"), new OctetString("fullWriteView"), new OctetString("fullNotifyView"), StorageType.nonVolatile);
vacmMIB.addAccess(new OctetString("v3restricted"), new OctetString(), SecurityModel.SECURITY_MODEL_USM, SecurityLevel.NOAUTH_NOPRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("restrictedReadView"), new OctetString("restrictedWriteView"), new OctetString("restrictedNotifyView"), StorageType.nonVolatile);
vacmMIB.addAccess(new OctetString("v3test"), new OctetString(), SecurityModel.SECURITY_MODEL_USM, SecurityLevel.AUTH_PRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("testReadView"), new OctetString("testWriteView"), new OctetString("testNotifyView"), StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("fullReadView"), new OID("1"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("fullNotifyView"), new OID("1"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("restrictedReadView"), new OID("1.3.6.1.2"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("restrictedWriteView"), new OID("1.3.6.1.2.1"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("restrictedNotifyView"), new OID("1.3.6.1.2"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("restrictedNotifyView"), new OID("1.3.6.1.6.3.1"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("testReadView"), new OID("1.3.6.1.2"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("testReadView"), new OID("1.3.6.1.2.1.1"), new OctetString(), VacmMIB.vacmViewExcluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("testWriteView"), new OID("1.3.6.1.2.1"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacmMIB.addViewTreeFamily(new OctetString("testNotifyView"), new OID("1.3.6.1.2"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
}
示例9: processMessage
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
public void processMessage(Packet packet) {
UdpPacket udpPacket = packet.get(UdpPacket.class);
byte[] snmpMessage = udpPacket.getPayload().getRawData();
InetAddress srcAddr;
IpV4Packet ipV4Packet = packet.get(IpV4Packet.class);
if (ipV4Packet != null) {
srcAddr = ipV4Packet.getHeader().getSrcAddr();
}
else {
srcAddr = packet.get(IpV6Packet.class).getHeader().getSrcAddr();
}
int srcPort = udpPacket.getHeader().getSrcPort().value() & 0xFFFF;
ByteBuffer bis;
if (isAsyncMsgProcessingSupported()) {
byte[] rawData = new byte[snmpMessage.length];
System.arraycopy(snmpMessage, 0, rawData, 0, rawData.length);
bis = ByteBuffer.wrap(rawData);
}
else {
bis = ByteBuffer.wrap(snmpMessage);
}
TransportStateReference stateReference
= new TransportStateReference(
this,
getAddress(),
null,
SecurityLevel.undefined,
SecurityLevel.undefined,
false,
null
);
fireProcessMessage(
new UdpAddress(srcAddr, srcPort),
bis,
stateReference
);
}
示例10: setUpTarget
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
/**
* Helper method that initializes the snmp target to listening mode. This
* method is explicitly for V3 messages. This method will create and set up
* the TransportMapping and target for SNMP V3. It creates a
* TransportMapping and puts it in the listening mode. Also Creates
* CommunityTarget object and sets SNMP target properties.
*
* @param targetIP
* IP address of Target machine
* @param portNumber
* Port number
* @param userName
* The security name of the user
* @param authenticatePassword
* The authentication password
* @param privacyPassword
* The privacy password
* @return The created UserTarget
* @throws IOException
* IOException
*/
private UserTarget setUpTarget( final String targetIP, final int portNumber, final String userName,
final String authenticatePassword, final String privacyPassword ) throws IOException
{
// Creates a TransportMapping and puts the transport mapping in to
// listen mode
final TransportMapping transportMapping = new DefaultUdpTransportMapping();
snmp = new Snmp( transportMapping );
transportMapping.listen();
// Creating a USM with the support for the supplied security protocols
final SecurityProtocols securityProtocols = SecurityProtocols.getInstance();
securityProtocols.addDefaultProtocols();
final OctetString engineId = new OctetString( MPv3.createLocalEngineID() );
final USM usm = new USM( securityProtocols, engineId, DEFAULT_ENGINE_REBOOTS );
SecurityModels.getInstance().addSecurityModel( usm );
final OctetString username = new OctetString( userName );
final OctetString authenticationPassphrase = new OctetString( authenticatePassword );
final OctetString privacyPassphrase = new OctetString( privacyPassword );
// Creating UsmUser and adds the UsmUser to the internal user name table
// TODO Need to confirm, whether AuthMD5 and PrivDES needs to be changed
final UsmUser usmuser = new UsmUser( username, AuthMD5.ID, authenticationPassphrase, PrivDES.ID,
privacyPassphrase );
snmp.getUSM().addUser( username, usmuser );
// Create a target for a user based security model target and setting
// its properties
final UserTarget userTarget = new UserTarget();
final InetAddress inetAddress = InetAddress.getByName( targetIP );
final Address address = new UdpAddress( inetAddress, portNumber );
userTarget.setAddress( address );
// TODO Need to confirm, whether this value needs to be configures
userTarget.setRetries( SnmpManager.DEFAULT_RETRIES );
// TODO Need to confirm, whether this value needs to be configures
userTarget.setTimeout( SnmpManager.DEFAULT_TIMEOUT );
userTarget.setVersion( SnmpConstants.version3 );
// TODO Need to confirm, whether this value needs to be configures
userTarget.setSecurityLevel( SecurityLevel.AUTH_PRIV );
userTarget.setSecurityName( username );
return userTarget;
}
示例11: sendTrapV3Auth
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
public static void sendTrapV3Auth(String port) throws IOException {
try {
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/" + port);
TransportMapping<?> transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();
snmp.getUSM().addUser(
new OctetString("user"),
new UsmUser(new OctetString("user"), AuthMD5.ID, new OctetString("12345678"),
null, null));
// Create Target
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(1);
target.setTimeout(11500);
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
target.setSecurityName(new OctetString("user"));
// Create PDU for V3
ScopedPDU pdu = new ScopedPDU();
pdu.setType(ScopedPDU.NOTIFICATION);
pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkDown));
pdu.add(new VariableBinding(new OID("1.2.3.4.5"), new OctetString("Major")));
// Send the PDU
snmp.send(pdu, target);
transport.close();
snmp.close();
} catch (Exception e) {
System.err.println("Error in Sending Trap to (IP:Port)=> " + "127.0.0.1" + ":" + port);
System.err.println("Exception Message = " + e.getMessage());
}
}
示例12: sendTrapV3AuthPriv
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
public static void sendTrapV3AuthPriv(String port) throws IOException {
try {
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/" + port);
TransportMapping<?> transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();
snmp.getUSM().addUser(
new OctetString("user"),
new UsmUser(new OctetString("user"), AuthMD5.ID, new OctetString("12345678"),
PrivDES.ID, new OctetString("passphrase")));
// Create Target
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(1);
target.setTimeout(11500);
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
target.setSecurityName(new OctetString("user"));
// Create PDU for V3
ScopedPDU pdu = new ScopedPDU();
pdu.setType(ScopedPDU.NOTIFICATION);
pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkDown));
pdu.add(new VariableBinding(new OID("1.2.3.4.5"), new OctetString("Major")));
// Send the PDU
snmp.send(pdu, target);
transport.close();
snmp.close();
} catch (Exception e) {
System.err.println("Error in Sending Trap to (IP:Port)=> " + "127.0.0.1" + ":" + port);
System.err.println("Exception Message = " + e.getMessage());
}
}
示例13: addViews
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
@Override
protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1,
new OctetString("cpublic"),
new OctetString("v1v2group"),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString("cpublic"),
new OctetString("v1v2group"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v1v2group"), new OctetString(community),
SecurityModel.SECURITY_MODEL_ANY,
SecurityLevel.NOAUTH_NOPRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullReadView"),
new OctetString("fullWriteView"),
new OctetString("fullNotifyView"),
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullNotifyView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("restrictedReadView"),
new OID("1.3.6.1.2"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("restrictedWriteView"),
new OID("1.3.6.1.2.1"),
new OctetString(),
VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("restrictedNotifyView"),
new OID("1.3.6.1.2"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("restrictedNotifyView"),
new OID("1.3.6.1.6.3.1"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
}
示例14: addViews
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
/**
* Adds initial VACM configuration.
*
* @param vacm
* the VacmMIB holding the agent's view configuration.
*/
@Override
protected void addViews(VacmMIB vacm) {
super.addViews(vacm);
if (communityStringIndexes == null || communityStringIndexes.size() == 0) {
logger.info("No community string index. Add no view to VACM-MIB.");
return;
}
if (getCommunityName() == null) {
return;
}
for (String communityStringIndex: communityStringIndexes) {
String communityName
= getContextNameForCommunityStringIndex(communityStringIndex);
vacm.addGroup(
SecurityModel.SECURITY_MODEL_SNMPv1,
new OctetString("com" + communityName),
new OctetString("v1v2group"),
StorageType.nonVolatile
);
vacm.addGroup(
SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString("com" + communityName),
new OctetString("v1v2group"),
StorageType.nonVolatile
);
vacm.addAccess(
new OctetString("v1v2group"),
new OctetString(communityName),
SecurityModel.SECURITY_MODEL_SNMPv1,
SecurityLevel.NOAUTH_NOPRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullView"),
new OctetString("fullView"),
new OctetString("fullView"),
StorageType.nonVolatile
);
vacm.addAccess(
new OctetString("v1v2group"),
new OctetString(communityName),
SecurityModel.SECURITY_MODEL_SNMPv2c,
SecurityLevel.NOAUTH_NOPRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullView"),
new OctetString("fullView"),
new OctetString("fullView"),
StorageType.nonVolatile
);
}
}
示例15: getV3AuthPrivTarget
import org.snmp4j.security.SecurityLevel; //导入依赖的package包/类
/**
* Returns a destination target to be used for a new SNMP message. The
* target returned will use SNMP v3 protocol with authentication and privacy
* enabled.
*
* @return v3 authPriv Target
* @throws AddressException
*/
private Target getV3AuthPrivTarget() {
String hostAddress = null;
try {
hostAddress = targetDevice.getAddress().getHostAddress();
} catch (AddressException e) {
logger.fatal("Unable to get the IP address from the NetworkDevice",
e);
System.exit(-1);
}
// set the address using the format 'udp:192.168.1.1/161'
String address = String.format("udp:%s/%d", hostAddress,
SnmpPref.getPort());
Address targetAddress = GenericAddress.parse(address);
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(SnmpPref.getMaxRetries());
target.setTimeout(SnmpPref.getTimeout());
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(new OctetString(SnmpPref.getUser()));
return target;
}