String userName,
SnmpAuthentication auth,
SnmpPrivacy privacy)
throws SnmpException {
SnmpContextv3Pool pool;
String type;
int protocol;
try {
pool = new SnmpContextv3Pool(host, port);
pool.setContextName(contextName);
pool.setContextEngineId(contextEngine.getBytes());
pool.setUserName(userName);
pool.setUseAuthentication(auth != null);
pool.setUsePrivacy(auth != null && privacy != null);
if (auth != null) {
type = auth.getType();
if (type.equals(SnmpAuthentication.MD5_TYPE)) {
protocol = SnmpContextv3Face.MD5_PROTOCOL;
pool.setAuthenticationProtocol(protocol);
} else if (type.equals(SnmpAuthentication.SHA1_TYPE)) {
protocol = SnmpContextv3Face.SHA1_PROTOCOL;
pool.setAuthenticationProtocol(protocol);
} else {
throw new SnmpException("Unsupported authentication " +
"protocol: " + type);
}
pool.setUserAuthenticationPassword(auth.getPassword());
}
if (auth != null && privacy != null) {
type = privacy.getType();
if (!type.equals(SnmpPrivacy.CBC_DES_TYPE)) {
throw new SnmpException("Unsupported privacy " +
"protocol: " + type);
}
pool.setUserPrivacyPassword(privacy.getPassword());
}
return new SnmpManager(pool);
} catch (IOException e) {
throw new SnmpException("SNMP communication error: " +
e.getMessage());