mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

lutoff
25.30.2008 df50105cb59f505200cb363b7a1ac76201dec6ec
Add SNMP source code in checkstyle list
12 files modified
575 ■■■■■ changed files
opends/build.xml 6 ●●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/DIRECTORY_SERVER_MIBImpl.java 18 ●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java 33 ●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/DsEntry.java 6 ●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/DsMIBImpl.java 104 ●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/DsTableEntryImpl.java 14 ●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/SNMPClassLoaderProvider.java 130 ●●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandler.java 54 ●●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandlerDefinitions.java 93 ●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/SNMPInetAddressAcl.java 32 ●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/SNMPMonitor.java 65 ●●●● patch | view | raw | blame | history
opends/src/snmp/src/org/opends/server/snmp/SNMPUserAcl.java 20 ●●●●● patch | view | raw | blame | history
opends/build.xml
@@ -496,6 +496,12 @@
    <checkstyle config="${checkstyle.dir}/opends-checkstyle.xml"
         failOnViolation="true">
      <fileset dir="${snmp.src.dir}" includes="**/*.java" />
      <formatter type="plain" />
    </checkstyle>
    <checkstyle config="${checkstyle.dir}/opends-checkstyle.xml"
         failOnViolation="true">
      <fileset dir="${quicksetup.src.dir}" includes="**/*.java" />
      <formatter type="plain" />
    </checkstyle>
opends/src/snmp/src/org/opends/server/snmp/DIRECTORY_SERVER_MIBImpl.java
@@ -48,24 +48,24 @@
   */
  private static final DebugTracer TRACER = DebugLogger.getTracer();
  /**
   * Indicates if the SNMP Mbeans have to be registered or not
   * Indicates if the SNMP Mbeans have to be registered or not.
   */
  private boolean registeredSnmpMBean = false;
  /**
   * The Current Directory Server MIB
   * The Current Directory Server MIB.
   */
  private DsMIBImpl dsMib = null;
  /**
   * ObjectName of the Current Direcotry Server MIB
   * ObjectName of the Current Direcotry Server MIB.
   */
  private ObjectName mibObName;
  /**
   * ObjectName of the dsMIB group in the Directory Server MIB
   * ObjectName of the dsMIB group in the Directory Server MIB.
   */
  private ObjectName groupObjName;
  /**
   * Creates the Current Directory Server MIB
   * Creates the Current Directory Server MIB.
   * @param registeredMBean indicates if the SNMP MBean has to register
   * in the Direcotry Server MBeanServer
   * @param mibName of the Directory Server MIB
@@ -94,7 +94,7 @@
              SNMPConnectionHandlerDefinitions.SNMP_DOMAIN +
              "type=group,name=DsMib");
    }
    final DsMIBMeta meta = createDsMIBMetaNode("DsMIB", oid, groupObjName,
    final DsMIBMeta meta = createDsMIBMetaNode("DsMIB", oid, groupObjName,
            server);
    if (meta != null) {
      meta.registerTableNodes(this, server);
@@ -103,7 +103,7 @@
      // the returned object must implement the "DsMIBMBean"
      // interface.
      //
      final DsMIBMBean group = (DsMIBMBean) createDsMIBMBean("DsMIB", oid,
      final DsMIBMBean group = (DsMIBMBean) createDsMIBMBean("DsMIB", oid,
              groupObjName, server);
      meta.setInstance(group);
      registerGroupNode("DsMIB", oid, groupObjName, meta, group, server);
@@ -121,7 +121,7 @@
  }
  /**
   * Returns the created dsMIB group
   * Returns the created dsMIB group.
   * @return the DsMIBImpl
   */
  protected DsMIBImpl getMib() {
@@ -129,7 +129,7 @@
  }
  /**
   * Returns the ObjectName of the dsMIB group
   * Returns the ObjectName of the dsMIB group.
   * @return the ObjectName of the created dsMIB group
   */
  protected ObjectName getObjectName() {
opends/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
@@ -26,7 +26,6 @@
 */
package org.opends.server.snmp;
import com.sun.management.snmp.SnmpStatusException;
import com.sun.management.snmp.agent.SnmpMib;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -51,39 +50,39 @@
   */
  private static final DebugTracer TRACER = DebugLogger.getTracer();
  /**
   * ObjectName of the DsApplIfOpsEntry
   * ObjectName of the DsApplIfOpsEntry.
   */
  private ObjectName entryName;
  /**
   * MBeanServer where the cn=monitor Connection Handler MBean are registered
   * MBeanServer where the cn=monitor Connection Handler MBean are registered.
   */
  private MBeanServer server;
  /**
   * ObjectName of the cn=monitor Connection Handler MBean
   * ObjectName of the cn=monitor Connection Handler MBean.
   */
  private ObjectName connectionHandlerName;
  /**
   * SNMPMonitor representing the gateway beetween SNMP MBeans and cn=monitor
   * MBeans
   * MBeans.
   */
  private SNMPMonitor monitor;
  /**
   * ObjectName of the MBeans representing the Statistics of the cn=monitor
   * ConnectionHandler
   * ConnectionHandler.
   */
  private ObjectName stats;
  /**
   * Created a DsApplIfOpsEntry in the SnmpMib
   * Created a DsApplIfOpsEntry in the SnmpMib.
   * @param mib where the entry has to be created
   * @param server where the corresponding cn=monitor MBean are registered
   * @param connectionHandlerObjectName mapping ObjectName
   * @param applIndex key in the DsTable
   * @param connectionHandlerIndex key corresponding to this entry in the
   * @param connectionHandlerIndex key corresponding to this entry in the
   * DsApplIfOpsTable
   */
  public DsApplIfOpsEntryImpl(SnmpMib mib, MBeanServer server,
          ObjectName connectionHandlerObjectName, int applIndex,
          ObjectName connectionHandlerObjectName, int applIndex,
          int connectionHandlerIndex) {
    super(mib);
    this.server = server;
@@ -104,7 +103,7 @@
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(stats,
      long value = Long.parseLong((String) this.monitor.getAttribute(stats,
              "searchRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
@@ -214,11 +213,11 @@
   */
  @Override
  public Long getDsApplIfReadOps() {
    return this.getDsApplIfCompareOps() +
            this.getDsApplIfAddEntryOps() +
            this.getDsApplIfRemoveEntryOps() +
            this.getDsApplIfModifyEntryOps() +
            this.getDsApplIfModifyRDNOps() +
    return this.getDsApplIfCompareOps() +
            this.getDsApplIfAddEntryOps() +
            this.getDsApplIfRemoveEntryOps() +
            this.getDsApplIfModifyEntryOps() +
            this.getDsApplIfModifyRDNOps() +
            this.getDsApplIfSearchOps();
  }
@@ -271,7 +270,7 @@
  /**
   * {@inheritDoc}
   * @return ApplIndex index of the corresponding DsTable entry
   * @return ApplIndex index of the corresponding DsTable entry
   */
  @Override
  public Integer getApplIndex() {
@@ -279,7 +278,7 @@
  }
  /**
   * Returns the ObjectName of the SNMP entry MBean
   * Returns the ObjectName of the SNMP entry MBean.
   * @return ObjectName of the entry
   */
  public ObjectName getObjectName() {
opends/src/snmp/src/org/opends/server/snmp/DsEntry.java
@@ -30,12 +30,12 @@
/**
 * This interface should be implemented by all the DS:OID MBean and
 * allows to get the ObjectName of a SNMP OID MBean
 * allows to get the ObjectName of a SNMP OID MBean.
 */
public interface DsEntry {
  /**
   * Returns the ObjectName of the SNMP Entry
   * Returns the ObjectName of the SNMP Entry.
   * @return the ObjectName of the SNMP Entry
   */
  public ObjectName getObjectName();
opends/src/snmp/src/org/opends/server/snmp/DsMIBImpl.java
@@ -55,52 +55,52 @@
   * utility included with the Java SDK.
   */
  private static final long serialVersionUID = 6787374593664749374L;
  /**
   * The debug log tracer for this class.
   */
  private static final DebugTracer TRACER = DebugLogger.getTracer();
  /**
   * Directory Server MIB access
   * Directory Server MIB access.
   */
  private SnmpMib mib;
  /**
   * Register or not the SNMP MBean
  /**
   * Register or not the SNMP MBean.
   */
  private boolean registeredSnmpMBean = false;
  /**
   * List of DsTableEntries
   * List of DsTableEntries.
   */
  private Hashtable<ObjectName, DsEntry> dsTableEntries =
  private Hashtable<ObjectName, DsEntry> dsTableEntries =
          new Hashtable<ObjectName, DsEntry>();
  /**
   * List of DsIntTableEntries
   * List of DsIntTableEntries.
   */
  private Hashtable<ObjectName, DsEntry> dsApplIfOpsTableEntries =
  private Hashtable<ObjectName, DsEntry> dsApplIfOpsTableEntries =
          new Hashtable<ObjectName, DsEntry>();
   /**
   * List of DsIntTableEntries
   * List of DsIntTableEntries.
   */
  private Hashtable<ObjectName, DsEntry> dsIntTableEntries =
  private Hashtable<ObjectName, DsEntry> dsIntTableEntries =
          new Hashtable<ObjectName, DsEntry>();
  /**
   * Directory Server MBeanServer
   * Directory Server MBeanServer.
   */
  private MBeanServer server;
  /**
   * cn=monitor Mapping Class SNMP->MBean
   * cn=monitor Mapping Class SNMP->MBean.
   */
  private SNMPMonitor monitor;
  /**
   * Start Table indexes
  /**
   * Start Table indexes.
   */
  private int applIndex = 1;
  private int applIfOpsIndex = 1;
@@ -108,7 +108,7 @@
  /**
   * Constructor for the "DsMIB" group.
   * If the group contains a table, the entries created through an SNMP SET
   * If the group contains a table, the entries created through an SNMP SET
   * will not be registered in Java DMK.
   * @param myMib snmp mib
   * @param server where the MBeans are registered
@@ -128,15 +128,15 @@
    this.intIndex = 1;
    // Initialize the MIB
    initDsTables();
    if (DebugLogger.debugEnabled()) {
      TRACER.debugVerbose("DsMIB Group Created");
    }
  }
  /**
   * Returns the Set of ObjectName of all the created entries in all the Table
   * @return Set<ObjectName>
   * Returns the Set of ObjectName of all the created entries in all the Table.
   * @return The Set of ObjectName
   */
  @SuppressWarnings("unchecked")
  public Set<ObjectName> getEntriesObjectNames() {
@@ -146,10 +146,10 @@
    results.addAll(this.dsIntTableEntries.keySet());
    return results;
  }
  /**
   * Returns the list of Created Entries
   * @return Set<ObjectName> of created entries
   * Returns the list of Created Entries.
   * @return Set of created entries
   */
  @SuppressWarnings("unchecked")
  public Set<ObjectName> getEntries() {
@@ -159,12 +159,12 @@
    results.addAll(this.dsIntTableEntries.values());
    return results;
  }
  /**
   * handleNotification callback called when an MBeansServer Notification is
   * received
   * received.
   * @param notification received
   * @param handback
   * @param handback The handback
   */
  public void handleNotification(Notification notification, Object handback) {
    if (notification instanceof MBeanServerNotification) {
@@ -177,7 +177,7 @@
                (isAConnectionHandler(name))) {
          addRowInDsApplIfOpsTable(name);
        }
      }
      }
      // Process the ConnectionHandler unregistration
      else if (notif.getType().equals(
              MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
@@ -191,16 +191,16 @@
  }
  /**
   * initDsTables in the dsMib Group
   * initDsTables in the dsMib Group.
   */
  private void initDsTables() {
    // Initialize the DSTable with one Entry : Current Directory Server
    initializeDsTable();
    // Initialize the DsApplIfOpsTable with one entry per Connection Handler
    // Initialize the DsApplIfOpsTable with one entry per Connection Handler.
    initializeDsApplIfOpsTable();
    // Register as listener of the MBeanServer Notification to process
    // new Connection Handler MBeans
    try {
@@ -215,40 +215,40 @@
  }
  /**
   * initializeDsTable with the current Direcotry server instance
   * initializeDsTable with the current Directory server instance.
   * Only one entry is created in this table
   **/
  private void initializeDsTable() {
    // Add the Current Directory Server Instance in the DsTable
    addRowInDsTable();
  }
  /**
   * initializeDsApplIfOpsTable with the already registered Connection
   * Handlers
   * Handlers.
   **/
  private void initializeDsApplIfOpsTable() {
    // Get the list of ConnectionHandlers MBeans
    Set connectionHandlers = this.monitor.getConnectionHandlers();
    for (Iterator iter=connectionHandlers.iterator();iter.hasNext();) {
      ObjectName name = (ObjectName)iter.next();
      // Add the ConnectionHandler in the DsApplIfOpsTable
      // Add the ConnectionHandler in the DsApplIfOpsTable
      addRowInDsApplIfOpsTable(name);
    }
  }
 /**
  * addRowInDsTable
  * addRowInDsTable.
  * @return true if the entry has been added else false
  */
  private boolean addRowInDsTable() {
    try {
      // Create the entry
      DsTableEntryImpl entry = new DsTableEntryImpl(
              this.mib, this.server, this.applIndex);
      // if the entry alreday exists nothing to do
      if ((this.dsTableEntries.containsKey(entry.getObjectName())) ||
              (entry == null)) {
@@ -272,7 +272,7 @@
  }
  /**
   * addRowInDsIntTable Not Supported
   * addRowInDsIntTable Not Supported.
   * @return false (Not Supported for this current delivery)
   */
  private boolean addRowInDsIntTable() {
@@ -280,7 +280,7 @@
  }
  /**
   * addRowInDsApplIfOpsTable
   * addRowInDsApplIfOpsTable.
   * @param connectionHandlerName to add
   * @return true if the entry has been added else false
   */
@@ -315,7 +315,7 @@
  }
  /**
   * removeRowInDsApplIfOpsTable
   * removeRowInDsApplIfOpsTable.
   * @param connectionHandlerName
   * @return true if the entry has been removed else false
   */
@@ -325,7 +325,7 @@
      if (!this.dsApplIfOpsTableEntries.containsKey(connectionHandlerName)) {
        return false;
      }
      DsApplIfOpsEntryImpl entry = (DsApplIfOpsEntryImpl)
      DsApplIfOpsEntryImpl entry = (DsApplIfOpsEntryImpl)
              this.dsApplIfOpsTableEntries.get(connectionHandlerName);
      this.DsApplIfOpsTable.removeEntry((DsApplIfOpsEntryMBean) entry);
@@ -337,9 +337,9 @@
    }
  }
/**
 * isAConnectionHandler allows to check if the Mbean is a Connection Handler
 * isAConnectionHandler allows to check if the Mbean is a Connection Handler.
 * @param name of the MBean
 * @return true if the MBean is a Connection Handler else false
 */
opends/src/snmp/src/org/opends/server/snmp/DsTableEntryImpl.java
@@ -53,24 +53,24 @@
   */
  private static final DebugTracer TRACER = DebugLogger.getTracer();
  /**
   * Directory Server MBeanServer
   * Directory Server MBeanServer.
   */
  private MBeanServer server;
  /**
   * Mapping Class
   * Mapping Class.
   */
  private SNMPMonitor monitor;
  /**
   * ObjectName of the entry
   * ObjectName of the entry.
   */
  private ObjectName entryName;
  /**
   * Index of the Directory Server Instance (applIndex)
   * Index of the Directory Server Instance (applIndex).
   */
  private Integer applIndex;
  /**
   * Creates a DsTableEntry
   * Creates a DsTableEntry.
   * @param mib the SNMP Mib where the entry will be created
   * @param server where the mapping objects will be found
   * @param index of the entry in the DsTable
@@ -134,7 +134,7 @@
      monitorBackends = this.server.queryNames(SNMPMonitor.pattern, null);
      for (Iterator iter = monitorBackends.iterator(); iter.hasNext();) {
        ObjectName name = (ObjectName) iter.next();
        Object value = this.monitor.getAttribute(name,
        Object value = this.monitor.getAttribute(name,
                "ds-backend-entry-count");
        if (value != null) {
          result = result + new Long((String) value);
@@ -169,7 +169,7 @@
  }
  /**
   * Gets the object of the entry
   * Gets the object of the entry.
   * @return ObjectName of the entry
   */
  public ObjectName getObjectName() {
opends/src/snmp/src/org/opends/server/snmp/SNMPClassLoaderProvider.java
@@ -27,17 +27,11 @@
package org.opends.server.snmp;
import java.io.File;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import org.opends.server.loggers.debug.DebugLogger;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.types.DebugLogLevel;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import com.sun.management.comm.SnmpV3AdaptorServer;
@@ -58,82 +52,94 @@
import org.opends.server.util.Validator;
/**
 * The SNMPClassLoaderProvider.
 */
public class SNMPClassLoaderProvider {
    /**
     * The debug log tracer for this class.
     */
    private static final DebugTracer TRACER = DebugLogger.getTracer();
    /**
     * The current configuration state.
     */
    private SNMPConnectionHandlerCfg currentConfig;
    /**
     * MBeanServer of OpenDS
     * MBeanServer of OpenDS.
     */
    private MBeanServer server;
    /**
     * MIB to manage
     * MIB to manage.
     */
    private DIRECTORY_SERVER_MIBImpl dsMib;
    /**
     * ObjectName of the MIB2605
     * ObjectName of the MIB2605.
     */
    private ObjectName mibObjName;
    /**
     * ObjectName of the SnmpAdaptor
     * ObjectName of the SnmpAdaptor.
     */
    private ObjectName snmpObjName;
    /**
     * SNMP Port Number for SNMP requests
     * SNMP Port Number for SNMP requests.
     */
    private int snmpPort = 161;
    /**
     * Default SNMP trap port Number for SNMP Traps
    /**
     * Default SNMP trap port Number for SNMP Traps.
     */
    private int snmpTrapPort = 162;
    /**
     * Default SNMP Version
     */
    private String snmpVersion = SNMPConnectionHandlerDefinitions.SNMP_VERSION_V3;
    /**
     * Registration of the SNMP MBeans
     * Default SNMP Version.
     */
    private String snmpVersion =
      SNMPConnectionHandlerDefinitions.SNMP_VERSION_V3;
    /**
     * Registration of the SNMP MBeans.
     */
    private boolean registeredSNMPMBeans = false;
    /**
     * The unique name for this connection handler
     * The unique name for this connection handler.
     */
    private String connectionHandlerName;
    /**
     * ObjectName of the UsmMIB
     * ObjectName of the UsmMIB.
     */
    private ObjectName UsmObjName;
    private SnmpV3AdaptorServer snmpAdaptor;
    /**
     * Default constructor.
     */
    public SNMPClassLoaderProvider() {
      // No implementation required
    }
    /**
     * Initialization.
     * @param configuration The configuration
     */
    public void initializeConnectionHandler(
            SNMPConnectionHandlerCfg configuration) {
        // Keep the connection handler configuration
        this.currentConfig = configuration;
        // Get the Directory Server JMX MBeanServer
        // Get the Directory Server JMX MBeanServer
        this.server = DirectoryServer.getJMXMBeanServer();
        // Initialize he Connection Handler with the givewn configuration
@@ -141,6 +147,14 @@
    }
    /**
     * Applies the configuration changes to this change listener.
     *
     * @param configuration
     *          The new configuration containing the changes.
     * @return Returns information about the result of changing the
     *         configuration.
     */
    public ConfigChangeResult applyConfigurationChange(
            SNMPConnectionHandlerCfg configuration) {
@@ -168,11 +182,12 @@
                // Creates and starts the SNMP Adaptor
                this.snmpObjName = new ObjectName(
                        SNMPConnectionHandlerDefinitions.SNMP_DOMAIN +
                        "class=SnmpAdaptorServer,protocol=snmp,port=" + snmpPort);
                        "class=SnmpAdaptorServer,protocol=snmp," +
                        "port=" + snmpPort);
                this.server.registerMBean(this.snmpAdaptor, this.snmpObjName);
                this.snmpAdaptor.start();
                // Send a coldStart SNMP Trap on the new trap port if required
                // Send a coldStart SNMP Trap on the new trap port if required
                if (this.snmpTrapPort != configuration.getTrapPort()) {
                    this.snmpTrapPort = configuration.getTrapPort();
                    this.snmpAdaptor.setTrapPort(snmpTrapPort);
@@ -187,19 +202,19 @@
        // Check if the security file
        // If security file have changed, changeConfiguration not
        // Supported
        // Supported.
        return new ConfigChangeResult(ResultCode.SUCCESS, false);
    }
    /**
     * Gets the ObjectName of the crated USM MIB MBean
     * @return
     * Gets the ObjectName of the crated USM MIB MBean.
     * @return The UsmMIB ObjectName
     */
    public ObjectName getUsmMIBName() {
        return this.UsmObjName;
    }
     // private methods
    private void initializeConnectionHandler() {
@@ -247,7 +262,7 @@
            this.snmpAdaptor.start();
            // Send a coldStart SNMP Trap.
            // Send a coldStart SNMP Trap.
            this.snmpAdaptor.setTrapPort(snmpTrapPort);
            this.snmpAdaptor.snmpV1Trap(0, 0, null);
@@ -262,7 +277,7 @@
            this.server.registerMBean(this.snmpAdaptor, snmpObjName);
            this.server.registerMBean(this.dsMib, this.mibObjName);
        } catch (Exception ex) {
            if (debugEnabled()) {
                TRACER.debugCaught(DebugLogLevel.ERROR, ex);
@@ -270,6 +285,10 @@
        }
    }
    /**
     * Finalize.
     */
    public void finalizeConnectionHandler() {
        try {
@@ -278,10 +297,10 @@
            this.snmpAdaptor.snmpV1Trap(0, 0, null);
            String[] names = this.snmpAdaptor.getMibs();
            // Stop the SNMP Adaptor
            this.snmpAdaptor.stop();
            this.server.unregisterMBean(this.snmpObjName);
            this.server.unregisterMBean(this.mibObjName );
            this.server.unregisterMBean(new ObjectName(
@@ -291,7 +310,7 @@
            // Unregister the created SNMP MBeans
            if (this.registeredSNMPMBeans) {
                this.unregisterSnmpMBeans();
                if (this.snmpVersion.equals(
                        SNMPConnectionHandlerDefinitions.SNMP_VERSION_V3)) {
                    this.server.unregisterMBean(this.UsmObjName);
@@ -315,8 +334,9 @@
        }
    }
    private SnmpV3AdaptorServer getSnmpAdaptor(SNMPConnectionHandlerCfg configuration) {
    private SnmpV3AdaptorServer getSnmpAdaptor(
        SNMPConnectionHandlerCfg configuration) {
        Validator.ensureNotNull(configuration);
        SnmpV3AdaptorServer adaptor = null;
@@ -328,7 +348,8 @@
            if (configuration.getVersion().toLowerCase().equals(
                    SNMPConnectionHandlerDefinitions.SNMP_VERSION_V3)) {
                System.setProperty("jdmk.security.file", file.getAbsolutePath());
                System.setProperty("jdmk.security.file",
                    file.getAbsolutePath());
            }
            // Create the Security Parameters for the engine
@@ -342,7 +363,8 @@
            engineParameters.setUserAcl(uacls);
            // V1/V2 Security parameters
            InetAddressAcl acls = (InetAddressAcl)new SNMPInetAddressAcl(configuration);
            InetAddressAcl acls =
              (InetAddressAcl)new SNMPInetAddressAcl(configuration);
            adaptor = new SnmpV3AdaptorServer(engineParameters, null, acls,
                    configuration.getListenPort(), InetAddress.getLocalHost());
opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandler.java
@@ -49,7 +49,6 @@
import org.opends.server.core.DirectoryServer;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
/**
 * This class defines an SNMP connection handler, which can be used to answer
@@ -65,19 +64,19 @@
    // Current configuration
    SNMPConnectionHandlerCfg currentConfig;
    /**
     * The list of active client connection
     * The list of active client connection.
     */
    private LinkedList<ClientConnection> connectionList;
    /**
     * The set of listeners for this connection handler
     * The set of listeners for this connection handler.
     */
    private LinkedList<HostPort> listeners = new LinkedList<HostPort>();
    /**
     * SNMP Connection Handler delegation class
    /**
     * SNMP Connection Handler delegation class.
     */
    private SNMPClassLoaderProvider provider;
    /**
     * Is the SNMP Connection Handler Operational
     * Is the SNMP Connection Handler Operational.
     */
    private boolean isOperational = false;
@@ -112,7 +111,7 @@
            logError(message);
            return;
        }
        // Get the jarFile Location and test if exists to be able to
        // start the SNMP Connection Handler as requested
        File jarFile = new File(jarLocation);
@@ -249,7 +248,8 @@
     * {@inheritDoc}
     */
    public LinkedHashMap<String, String> getAlerts() {
        LinkedHashMap<String, String> alerts = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> alerts =
          new LinkedHashMap<String, String>();
        return alerts;
    }
@@ -258,22 +258,28 @@
        try {
            URL u = new URL("jar:file://"+ file.toString()+"!/");
            Class[] parameters = new Class[]{URL.class};
            URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
        Class sysclass = URLClassLoader.class;
        Method method = sysclass.getDeclaredMethod("addURL",new Class[]{URL.class});
            URLClassLoader sysloader =
              (URLClassLoader)ClassLoader.getSystemClassLoader();
            Class sysclass = URLClassLoader.class;
            Method method =
              sysclass.getDeclaredMethod("addURL",new Class[]{URL.class});
            method.setAccessible(true);
        method.invoke(sysloader,new Object[]{ u });
        }
            method.invoke(sysloader,new Object[]{ u });
        }
        catch (Throwable t) {
        }
    }//end method
    private void initSnmpClasses() {
        try {
            URLClassLoader opendsLoader = (URLClassLoader)DirectoryServer.getClassLoader();
            Class.forName("com.sun.management.comm.SnmpV3AdaptorServer", true, opendsLoader);
            Class.forName("com.sun.management.snmp.InetAddressAcl",true, opendsLoader);
            Class.forName("com.sun.management.snmp.SnmpEngineParameters",true, opendsLoader);
            URLClassLoader opendsLoader =
              (URLClassLoader)DirectoryServer.getClassLoader();
            Class.forName("com.sun.management.comm.SnmpV3AdaptorServer",
                true, opendsLoader);
            Class.forName("com.sun.management.snmp.InetAddressAcl",
                true, opendsLoader);
            Class.forName("com.sun.management.snmp.SnmpEngineParameters",
                true, opendsLoader);
            Class.forName("com.sun.management.snmp.UserAcl",true, opendsLoader);
            this.isOperational = true;
        } catch (ClassNotFoundException ex) {
@@ -281,16 +287,24 @@
        }
    }
    /**
     * Indicate if operational.
     * @param file The file
     * @return true is operational
     */
    public boolean isOperational(File file) {
        this.addFile(file);
        this.initSnmpClasses();
        return this.isOperational;
    }
    /**
     * Indicate if operational.
     * @return true is operational
     */
    public boolean isOperational() {
        return this.isOperational;
    }
}
opends/src/snmp/src/org/opends/server/snmp/SNMPConnectionHandlerDefinitions.java
@@ -34,13 +34,23 @@
 */
public class SNMPConnectionHandlerDefinitions {
  // SNMP Version supported
  public static String SNMP_VERSION_V1 = "v1";
  public static String SNMP_VERSION_V2 = "v2";
  public static String SNMP_VERSION_V3 = "v3";
  /**
   * List of Supported SNMP Version
  * SNMP V1 supported.
  */
  public static String SNMP_VERSION_V1 = "v1";
  /**
   * SNMP V2 supported.
   */
  public static String SNMP_VERSION_V2 = "v2";
  /**
   * SNMP V3 supported.
   */
  public static String SNMP_VERSION_V3 = "v3";
  /**
   * List of Supported SNMP Version.
   */
  public static Set<String> SUPPORTED_SNMP_VERSION=new HashSet<String>();
  static {
@@ -48,43 +58,104 @@
    SUPPORTED_SNMP_VERSION.add(SNMP_VERSION_V2);
    SUPPORTED_SNMP_VERSION.add(SNMP_VERSION_V3);
  }
  // Domain for SNMP MBeans
  /**
   * Domain for SNMP MBeans.
   */
  public static final String SNMP_DOMAIN =
          "org.opends.server.snmp:";
  // Domain for Monitor MBeans
  /**
   * Domain for Monitor MBeans.
   */
  public static final String JMX_DOMAIN =
          "org.opends.server:";
  // Name of monitor Mbeans
  /**
   * Name of MONITOR_CLIENT_CONNECTIONS_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_CLIENT_CONNECTIONS_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-Client_Connections";
  /**
   * Name of MONITOR_ENTRY_CACHES_OBJECTNANE monitor Mbean.
   */
  public static final String MONITOR_ENTRY_CACHES_OBJECTNANE =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-Entry_Caches";
  /**
   * Name of MONITOR_JVM_MEMORY_USAGE_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_JVM_MEMORY_USAGE_OBJECTNAME =
          "RootDSE,Rdn1=cn-monitor,Rdn2=cn-JVM_Memory_Usage";
  /**
   * Name of MONITOR_JVM_STACK_TRACE_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_JVM_STACK_TRACE_OBJECTNAME = "" +
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-JVM_Stack_Trace";
  /**
   * Name of MONITOR_SYSTEM_INFORMATION_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_SYSTEM_INFORMATION_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-System_Information";
  /**
   * Name of MONITOR_VERSION_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_VERSION_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-Version";
  /**
   * Name of MONITOR_WORK_QUEUE_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_WORK_QUEUE_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-Work_Queue";
  /**
   * Name of MONITOR_ADMIN_ROOT_BACKEND_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_ADMIN_ROOT_BACKEND_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-adminRoot_Backend";
  /**
   * Name of MONITOR_ADSTRUSTSTORE_BACKEND_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_ADSTRUSTSTORE_BACKEND_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-adstruststore_Backend";
  /**
   * Name of MONITOR_BACKUP_BACKEND_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_BACKUP_BACKEND_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-backup_Backend";
  /**
   * Name of MONITOR_MONITOR_BACKEND_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_MONITOR_BACKEND_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-monitor_Backend";
  /**
   * Name of MONITOR_SCHEMA_BACKEND_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_SCHEMA_BACKEND_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-schema_Backend";
  /**
   * Name of MONITOR_TASKS_BACKEND_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_TASKS_BACKEND_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-tasks_Backend";
  /**
   * Name of MONITOR_USERROOT_BACKEND_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_USERROOT_BACKEND_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-userRoot_Backend";
  /**
   * Name of MONITOR_USERROOT_DATABASE_ENVIRONMENT_OBJECTNAME monitor Mbean.
   */
  public static final String MONITOR_USERROOT_DATABASE_ENVIRONMENT_OBJECTNAME =
          "rootDSE,Rdn1=cn-monitor,Rdn2=cn-userRoot_Database_Environment";
}
opends/src/snmp/src/org/opends/server/snmp/SNMPInetAddressAcl.java
@@ -52,31 +52,31 @@
     * Current Security Configuration for the SNMP Connection Handler.
     */
    private SNMPConnectionHandlerCfg currentConfig;
    private TreeSet<InetAddress> hostsList;
    private boolean allManagers = false;
    private SortedSet<String> trapsDestinations;
    private String trapsCommunity;
    private SortedSet<String> communitiesList;
    /**
     * Creates an IP-Based ACL controller
     * @param configuration of the Configuration
     * Creates an IP-Based ACL controller.
     * @param configuration of the Configuration
     */
    public SNMPInetAddressAcl(SNMPConnectionHandlerCfg configuration) {
        super();
        this.currentConfig = configuration;
        // hostsList
        SortedSet tmp = this.currentConfig.getAllowedManager();
        if (tmp.isEmpty()) {
            this.allManagers=true;
        }
        this.hostsList = new TreeSet<InetAddress>();
        // Transform the String list into InetAddress List
        // Transform the String list into InetAddress List
        for (Iterator iter = tmp.iterator(); iter.hasNext();) {
            try {
                String dest = (String) iter.next();
@@ -84,15 +84,15 @@
            } catch (UnknownHostException ex) {
            }
        }
        this.trapsDestinations = this.currentConfig.getTrapsDestination();
        this.communitiesList = this.currentConfig.getCommunity();
        this.trapsCommunity = this.currentConfig.getTrapsCommunity();
    }
    /**
     * Gets the name of the acl
     * Gets the name of the acl.
     * @return the name of the acl as a String
     */
    public String getName() {
@@ -107,7 +107,7 @@
        if (this.allManagers) {
            return true;
        }
        if ((this.hostsList==null) || (this.hostsList.isEmpty())) {
            return false;
        }
@@ -161,11 +161,11 @@
    /**
     * {@inheritDoc}
     * @return the list<InetAddress> of traps destinations
     * @return the list of traps destinations
     */
    public Enumeration getTrapDestinations() {
        Vector<InetAddress> tempDests = new Vector<InetAddress>();
        for (Iterator iter = this.trapsDestinations.iterator(); iter.hasNext();)
        for (Iterator iter = this.trapsDestinations.iterator(); iter.hasNext();)
        {
            try {
                String dest = (String) iter.next();
@@ -180,7 +180,7 @@
    /**
     * {@inheritDoc}
     * @param address
     * @return
     * @return the list of communities
     */
    public Enumeration getTrapCommunities(InetAddress address) {
        Vector<String> trapCommunities = new Vector<String>();
@@ -206,5 +206,5 @@
        Vector<String> informCommunities = new Vector<String>();
        return informCommunities.elements();
    }
}
opends/src/snmp/src/org/opends/server/snmp/SNMPMonitor.java
@@ -33,7 +33,6 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Set;
import javax.management.Attribute;
import javax.management.MBeanServer;
@@ -53,23 +52,23 @@
public class SNMPMonitor {
  /**
   * Debug Tracer for this class
   * Debug Tracer for this class.
   */
  private static final DebugTracer TRACER = DebugLogger.getTracer();
  /**
   * Singleton SNMPMonitor object
   * Singleton SNMPMonitor object.
   */
  private static SNMPMonitor monitor = null;
  /**
   * Monitor MBeanServer server
  /**
   * Monitor MBeanServer server.
   */
  private MBeanServer server;
  /**
   * Subject Auth to use to access the JMX Mbeans cn=monitor
   * Subject Auth to use to access the JMX Mbeans cn=monitor.
   */
  private Subject subject = null;
  /**
   * Pattern to use to query the cn=monitor MBeans
   * Pattern to use to query the cn=monitor MBeans.
   */
  public static ObjectName pattern;
@@ -86,7 +85,7 @@
  }
  /**
   * Creates an SNMPMonitor object mapping
   * Creates an SNMPMonitor object mapping.
   * @param server to use to the mapping
   */
  private SNMPMonitor(MBeanServer server) {
@@ -99,9 +98,9 @@
  }
  /**
   * Gets the singleton SNMPMonitor object
   * @param server
   * @return the SNMPMonitor mapping object
   * Gets the singleton SNMPMonitor object.
   * @param server The server
   * @return the SNMPMonitor mapping object.
   */
  public static SNMPMonitor getMonitor(MBeanServer server) {
    if (monitor == null) {
@@ -111,8 +110,8 @@
  }
  /**
   * Gets the Connection Handlers Statistics MBean
   * @return the Set<ObjectName> of Connection Handlers Statistics.
   * Gets the Connection Handlers Statistics MBean.
   * @return the Set of Connection Handlers Statistics.
   *     If Statistics do not exixist then an empty Set is returned
   */
  public Set<ObjectName> getConnectionHandlersStatistics() {
@@ -136,7 +135,7 @@
  /**
   * Return the ObjectName of the Connection Handler corresponding to
   * the statistics name
   * the statistics name.
   * @param statistics ObjectName
   * @return the Connection Handler ObjectName, null otherwise
   */
@@ -170,7 +169,7 @@
  }
  /**
   * Return a Set of Connection Handler ObjectNames
   * Return a Set of Connection Handler ObjectNames.
   * @return the Set of ObjectNames, an empty Set if no connection handlers
   */
  public Set<ObjectName> getConnectionHandlers() {
@@ -195,9 +194,9 @@
  }
  /**
   * Returns the ObjectName of the Statistics Connection Handler name
   * Returns the ObjectName of the Statistics Connection Handler name.
   * corresponding to the Connection Handler name
   * @param connectionHandlerName
   * @param connectionHandlerName The connection handler name
   * @return the ObjectName of the statistics ObjectName, null if the statistics
   * could not be found
   */
@@ -208,7 +207,7 @@
      return null;
    }
    try {
      String value =
      String value =
              connectionHandlerName.getCanonicalName().concat("_Statistics");
      ObjectName statistics = new ObjectName(value);
      // Check if the MBean exists
@@ -225,7 +224,7 @@
  }
  /**
   * Get the value of the attribute
   * Get the value of the attribute.
   * @param name of Mbean as a String
   * @param attribute to look for
   * @return the value of the attribute, null if the attribute could not
@@ -246,10 +245,10 @@
  }
  /**
   * Gets the value of an attribute
   * Gets the value of an attribute.
   * @param name of the Mbean
   * @param attribute to look for
   * @return the value of the attribute, null if the attribute value could not
   * @return the value of the attribute, null if the attribute value could not
   * be found
   */
  @SuppressWarnings("unchecked")
@@ -272,8 +271,8 @@
      });
  }
  /**
   * Wrapper for SNMP Counter32
  /**
   * Wrapper for SNMP Counter32.
   * @param v value
   * @return a counter32
   */
@@ -285,9 +284,9 @@
    }
  }
  /**
   * Wrapper for SNMP Counter32
   * @param V Value
  /**
   * Wrapper for SNMP Counter32.
   * @param V Value
   * @return a Counter32
   */
  public static Long counter32Value(Long V) {
@@ -299,8 +298,8 @@
    }
  }
  /**
   * Latcher for SNMP Gauge32
  /**
   * Latcher for SNMP Gauge32.
   * @param v value
   * @return a gauge32
   */
@@ -312,8 +311,8 @@
    }
  }
  /**
   * Latcher for SNMP Gauge32
  /**
   * Latcher for SNMP Gauge32.
   * @param V value
   * @return a gauge32
   */
@@ -327,10 +326,10 @@
  }
  /**
   * Checker for SNMP INTEGER
   * Checker for SNMP INTEGER.
   * @param V value
   * @return an Integer
   * @throws com.sun.management.snmp.SnmpStatusException
   * @throws com.sun.management.snmp.SnmpStatusException If an error occurs
   */
  public static Integer integerValue(Long V) throws SnmpStatusException {
    long v = V.longValue();
@@ -342,7 +341,7 @@
  }
  /**
   * pow x^y
   * pow x^y.
   */
  private static long pow(long x, long y) {
    int j = 1;
opends/src/snmp/src/org/opends/server/snmp/SNMPUserAcl.java
@@ -33,6 +33,10 @@
import org.opends.server.loggers.debug.DebugLogger;
import org.opends.server.loggers.debug.DebugTracer;
/**
 * The SNMP User ACL.
 *
 */
public class SNMPUserAcl implements UserAcl {
    /**
@@ -40,7 +44,7 @@
     */
    private static final DebugTracer TRACER = DebugLogger.getTracer();
    /**
     * If * then all the users are allowed to access in read
     * If * then all the users are allowed to access in read.
     */
    private static final String ALL_USERS_ALLOWED = "*";
    /**
@@ -48,19 +52,19 @@
     */
    private SNMPConnectionHandlerCfg currentConfig;
    /**
     * Configured hosts list
     * Configured hosts list.
     */
    private SortedSet usersList;
    /**
     * Configured traps destinations
     * Configured traps destinations.
     */
    private SortedSet trapDestinations;
    /**
     * Configured communities string
     * Configured communities string.
     */
    private SortedSet communityList;
    /**
     * Configured Security level
     * Configured Security level.
     */
    private SecurityLevel securityLevel;
    /**
@@ -76,7 +80,7 @@
    public SNMPUserAcl(SNMPConnectionHandlerCfg configuration) {
        // Keep the configuration
        this.currentConfig = configuration;
        // Get the community/context string to accept
        // Get the community/context string to accept
        this.communityList = this.currentConfig.getCommunity();
        // Get the list of allowed users (SNMPV3)
        this.usersList = this.currentConfig.getAllowedUser();
@@ -114,7 +118,9 @@
            int securityLevel) {
        // Special check for the defaultUser
        if ((user.equals(this.templateUsername)) && (contextName.equals("null")) && ((this.securityLevel.ordinal() + 1) >= securityLevel)) {
        if ((user.equals(this.templateUsername))
            && (contextName.equals("null"))
            && ((this.securityLevel.ordinal() + 1) >= securityLevel)) {
            return true;
        }