本文整理汇总了Java中org.snmp4j.security.AuthMD5类的典型用法代码示例。如果您正苦于以下问题:Java AuthMD5类的具体用法?Java AuthMD5怎么用?Java AuthMD5使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthMD5类属于org.snmp4j.security包,在下文中一共展示了AuthMD5类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTargetV3
import org.snmp4j.security.AuthMD5; //导入依赖的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: convertAuthProtocol
import org.snmp4j.security.AuthMD5; //导入依赖的package包/类
private OID convertAuthProtocol(String authProtocol) {
/*
* Returning null here is okay because the SNMP4J library supports
* this value as null when creating the SNMP session.
*/
if (StringUtils.isBlank(authProtocol)) {
return null;
}
if (authProtocol.equals("MD5")) {
return AuthMD5.ID;
} else if (authProtocol.equals("SHA")) {
return AuthSHA.ID;
} else {
throw new IllegalArgumentException("Authentication protocol unsupported: " + authProtocol);
}
}
示例3: start
import org.snmp4j.security.AuthMD5; //导入依赖的package包/类
/**
* Start the Snmp session. If you forget the listen() method you will not get any answers because the communication is asynchronous and the
* listen() method listens for answers.
*
* @throws IOException
*/
public void start() throws IOException {
TransportMapping transport = new DefaultUdpTransportMapping();
if (SNMPversion == 3) {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
}
snmp = new Snmp(transport);
if (SNMPversion == 3)
snmp.getUSM().addUser(new OctetString(ver3Username),
new UsmUser(new OctetString(ver3Username), AuthMD5.ID, new OctetString(ver3AuthPasscode), null, null));
// Do not forget this line!
transport.listen();
}
示例4: testTrapReceiverWithoutOpenNMS
import org.snmp4j.security.AuthMD5; //导入依赖的package包/类
public void testTrapReceiverWithoutOpenNMS() throws Exception {
System.out.println("SNMP4J: Register for Traps");
trapCount = 0;
Snmp snmp = new Snmp(new DefaultUdpTransportMapping(new UdpAddress(9162)));
snmp.addCommandResponder(this);
snmp.getUSM().addUser(
new OctetString("opennmsUser"),
new UsmUser(new OctetString("opennmsUser"), AuthMD5.ID, new OctetString("0p3nNMSv3"), PrivDES.ID, new OctetString("0p3nNMSv3")));
snmp.listen();
sendTraps();
System.out.println("SNMP4J: Unregister for Traps");
snmp.close();
System.out.println("SNMP4J: Checking Trap status");
assertEquals(2, trapCount);
}
示例5: convertAuthProtocol
import org.snmp4j.security.AuthMD5; //导入依赖的package包/类
private OID convertAuthProtocol(String authProtocol) {
/*
* Returning null here is okay because the SNMP4J library supports
* this value as null when creating the SNMP session.
*/
if (authProtocol == null) {
return null;
}
if (authProtocol.equals("MD5")) {
return AuthMD5.ID;
} else if (authProtocol.equals("SHA")) {
return AuthSHA.ID;
} else {
throw new IllegalArgumentException("Authentication protocol unsupported: " + authProtocol);
}
}
示例6: convertAuthenticationProtocol
import org.snmp4j.security.AuthMD5; //导入依赖的package包/类
private OID convertAuthenticationProtocol(String authenticationProtocol) {
if (authenticationProtocol == null) {
return null;
}
if ("MD5".equals(authenticationProtocol)) {
return AuthMD5.ID;
} else if ("SHA1".equals(authenticationProtocol)) {
return AuthSHA.ID;
} else {
throw new IllegalArgumentException("Unknown authentication protocol: " + authenticationProtocol);
}
}
示例7: authType
import org.snmp4j.security.AuthMD5; //导入依赖的package包/类
private OID authType(SnmpV3Target v3Target) {
switch (v3Target.getAuthType()) {
case SHA:
return AuthSHA.ID;
case MD5:
return AuthMD5.ID;
default:
throw new IllegalArgumentException("unrecognized auth type");
}
}
示例8: authProtocol
import org.snmp4j.security.AuthMD5; //导入依赖的package包/类
private OID authProtocol() {
AuthProtocol ap = AuthProtocol.valueOf(conf("authProtocol", AuthProtocol.NONE));
switch (ap) {
case MD5: return AuthMD5.ID;
case SHA: return AuthSHA.ID;
default: return null;
}
}
示例9: setUpTarget
import org.snmp4j.security.AuthMD5; //导入依赖的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;
}
示例10: sendTrapV3Auth
import org.snmp4j.security.AuthMD5; //导入依赖的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());
}
}
示例11: sendTrapV3AuthPriv
import org.snmp4j.security.AuthMD5; //导入依赖的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());
}
}
示例12: SnmpClient
import org.snmp4j.security.AuthMD5; //导入依赖的package包/类
/**
* Create a new SnmpClient for the passed NetworkDevice.
*
* @param targetDevice
* NetworkDevice that will be used for SNMP message exchange.
*/
public SnmpClient(NetworkDevice targetDevice) {
this.targetDevice = targetDevice;
// Create a new logger with name jnetman.snmp.device_name
logger = Logger.getLogger("snmp.snmpClient." + targetDevice.getName());
// If activated SNMP4J will show a huge amount of low level debug info
if (SnmpPref.isSnmp4jLogEnabled())
LogFactory.setLogFactory(new Log4jLogFactory());
try {
DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
// Creates Snmp istance for that transport channel
snmpInstance = new Snmp(transport);
logger.debug("New SNMP Client crated");
// Creates v3 SNMP USM
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
// Adds 'jnetman' usm using MD5 authentication and DES encryption
UsmUser jnetmanUser = new UsmUser(
new OctetString(SnmpPref.getUser()), AuthMD5.ID,
new OctetString(SnmpPref.getPassword()), PrivDES.ID,
new OctetString(SnmpPref.getPassword()));
snmpInstance.getUSM().addUser(new OctetString(SnmpPref.getUser()),
jnetmanUser);
logger.debug("New USM User added >> " + jnetmanUser.getSecurityName());
// Enables listening for incoming SNMP packet
transport.listen();
} catch (IOException e) {
logger.fatal(
"IOException while creating a new DefaultUdpTransportMapping()",
e);
System.exit(-1);
}
}