Пример #1
0
 /**
  * Add the default SecurityProtocols.
  *
  * <p>The names of the SecurityProtocols to add are read from a properties file.
  *
  * @throws InternalError if the properties file cannot be opened/read.
  */
 public synchronized void addDefaultProtocols() {
   if (SNMP4JSettings.isExtensibilityEnabled()) {
     String secProtocols =
         System.getProperty(SECURITY_PROTOCOLS_PROPERTIES, SECURITY_PROTOCOLS_PROPERTIES_DEFAULT);
     InputStream is = SecurityProtocols.class.getResourceAsStream(secProtocols);
     if (is == null) {
       throw new InternalError("Could not read '" + secProtocols + "' from classpath!");
     }
     Properties props = new Properties();
     try {
       props.load(is);
       for (Enumeration en = props.propertyNames(); en.hasMoreElements(); ) {
         String className = en.nextElement().toString();
         try {
           Class c = Class.forName(className);
           Object proto = c.newInstance();
           if (proto instanceof AuthenticationProtocol) {
             addAuthenticationProtocol((AuthenticationProtocol) proto);
           } else if (proto instanceof PrivacyProtocol) {
             addPrivacyProtocol((PrivacyProtocol) proto);
           } else {
             logger.error(
                 "Failed to register security protocol because it does "
                     + "not implement required interfaces: "
                     + className);
           }
         } catch (Exception cnfe) {
           logger.error(cnfe);
           throw new InternalError(cnfe.toString());
         }
       }
     } catch (IOException iox) {
       String txt = "Could not read '" + secProtocols + "': " + iox.getMessage();
       logger.error(txt);
       throw new InternalError(txt);
     } finally {
       try {
         is.close();
       } catch (IOException ex) {
         // ignore
         logger.warn(ex);
       }
     }
   } else {
     addAuthenticationProtocol(new AuthMD5());
     addAuthenticationProtocol(new AuthSHA());
     addPrivacyProtocol(new PrivDES());
     addPrivacyProtocol(new PrivAES128());
     addPrivacyProtocol(new PrivAES192());
     addPrivacyProtocol(new PrivAES256());
   }
 }