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

neil_a_wilson
06.22.2007 1bff31ca61c88343ba66592675b8b4d93fd7680a
Update the InternalClientConnection object to make the default constructor
private so that all attempts to get a root-authenticated connection should use
the InternalClientConnection.getRootConnection() method, which will be more
efficient.

OpenDS Issue Number: 1206
13 files modified
148 ■■■■ changed files
opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/ChangelogBroker.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java 3 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java 3 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java 97 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java 2 ●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java 6 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SynchronizationTestCase.java 2 ●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java 2 ●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/changelog/UpdateComparatorTest.java 5 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ModifyConflictTest.java 7 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SynchronizationMsgTest.java 14 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
@@ -144,7 +144,7 @@
   * authenticated as a root user for which access control will not be
   * enforced.
   */
  public InternalClientConnection()
  private InternalClientConnection()
  {
    super();
opends/src/server/org/opends/server/synchronization/plugin/ChangelogBroker.java
@@ -276,7 +276,8 @@
               * Get all the changes that have not been seen by this changelog
               * server and update it
               */
              InternalClientConnection conn = new InternalClientConnection();
              InternalClientConnection conn =
                  InternalClientConnection.getRootConnection();
              LDAPFilter filter = LDAPFilter.decode(
                  "("+ Historical.HISTORICALATTRIBUTENAME +
                  ">=dummy:" + changelogMaxChangeNumber + ")");
opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java
@@ -71,7 +71,7 @@
   private DN baseDn;
   private boolean savedStatus = true;
   private InternalClientConnection conn =
                                              new InternalClientConnection();
       InternalClientConnection.getRootConnection();
   private ASN1OctetString serverStateAsn1Dn;
   private DN serverStateDn;
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
@@ -154,7 +154,8 @@
  private DN configDn;
  private InternalClientConnection conn = new InternalClientConnection();
  private InternalClientConnection conn =
      InternalClientConnection.getRootConnection();
  static String CHANGELOG_SERVER_ATTR = "ds-cfg-changelog-server";
  static String BASE_DN_ATTR = "ds-cfg-synchronization-dn";
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006 Sun Microsystems, Inc.
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.protocols.internal;
@@ -110,7 +110,6 @@
  {
    return new Object[][]
    {
      new Object[] { new InternalClientConnection() },
      new Object[] { InternalClientConnection.getRootConnection() },
      new Object[] { new InternalClientConnection(new AuthenticationInfo()) },
      new Object[] { new InternalClientConnection(
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006 Sun Microsystems, Inc.
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.protocols.jmx;
@@ -88,7 +88,7 @@
  /**
   * Build data for the simpleConnect test.
   *
   *
   * @return the data.
   */
  @DataProvider(name="simpleConnect")
@@ -137,7 +137,7 @@
              "objectclass", null},
        {"cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
              "ds-cfg-ssl-cert-nickname", "adm-server-cert"},
      // not working at the moment see issue 655
      // not working at the moment see issue 655
      //  {"cn=JE Database,ds-cfg-backend-id=userRoot,cn=Backends,cn=config",
      //          "ds-cfg-database-cache-percent", 10},
    };
@@ -151,14 +151,14 @@
  public void simpleGet(String dn, String attributeName, Object value)
     throws Exception
  {
    OpendsJmxConnector connector = connect("cn=directory manager",
        "password", TestCaseUtils.getServerJmxPort());
    MBeanServerConnection jmxc = connector.getMBeanServerConnection();
    assertNotNull(jmxc);
    Object val = jmxGet(dn, attributeName, jmxc);
    if (value != null)
    {
      assertEquals(val, value);
@@ -183,20 +183,20 @@
    Set names = jmxc.queryNames(null, null);
    names.clear();
    final String dn = "cn=config";
    final String attribute = "ds-cfg-size-limit";
    Long val = (Long) jmxGet(dn, attribute, jmxc);
    jmxSet(dn, attribute, val + 1, jmxc);
    Long newVal = (Long) jmxGet(dn, attribute, jmxc);
    assertEquals((long)newVal, (long)val+1);
    jmxSet(dn, attribute, val + 1, jmxc);
    connector.close();
  }
@@ -211,7 +211,7 @@
  @Test(enabled = true)
  public void disable() throws Exception
  {
    // Create a new JMX connector for this test.
    // This will allow to use the old one if this test fails.
    //
@@ -232,7 +232,8 @@
        "ds-cfg-listen-port: " + serverJmxPort,
        "cn: JMX Connection Handler"
         );
    InternalClientConnection connection = new InternalClientConnection();
    InternalClientConnection connection =
        InternalClientConnection.getRootConnection();
    AddOperation addOp = new AddOperation(connection,
        InternalClientConnection.nextOperationID(), InternalClientConnection
            .nextMessageID(), null, newJmxConnectionJmx.getDN(),
@@ -245,7 +246,7 @@
        "password", serverJmxPort);
    assertNotNull(newJmxConnector);
    newJmxConnector.close() ;
    // Get the "old" connector
    OpendsJmxConnector connector = connect("cn=directory manager",
        "password", TestCaseUtils.getServerJmxPort());
@@ -258,7 +259,7 @@
    OpendsJmxConnector jmxcDisabled = connect("cn=directory manager",
        "password", serverJmxPort);
    assertNull(jmxcDisabled);
    toggleEnableJmxConnector(connector, newJmxConnectionJmx.getDN(), true);
    Thread.sleep(100) ;
    jmxcDisabled = connect("cn=directory manager","password", serverJmxPort);
@@ -272,7 +273,7 @@
            .nextMessageID(), null, newJmxConnectionJmx.getDN());
    delOp.run();
  }
  /**
   * Test changing JMX port through LDAP
   * @throws Exception
@@ -284,22 +285,22 @@
    final String dn =
      "cn=JMX Connection Handler,cn=Connection Handlers,cn=config";
    final String attribute = "ds-cfg-listen-port";
    OpendsJmxConnector connector = connect("cn=directory manager", "password",
        TestCaseUtils.getServerJmxPort());
    MBeanServerConnection jmxc = connector.getMBeanServerConnection();
    assertNotNull(jmxc);
    // use JMX to get the current value of the JMX port number
    Long initJmxPort = (Long) jmxGet(dn, attribute, jmxc);
    connector.close();
    assertNotNull(initJmxPort);
    // change the configuration of the connection handler to use
    // change the configuration of the connection handler to use
    // a free port
    ServerSocket serverJmxSocket = TestCaseUtils.bindFreePort();
    int serverJmxPort = serverJmxSocket.getLocalPort();
    ConfigEntry config = new ConfigEntry(TestCaseUtils.makeEntry(
        "dn: cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
        "objectClass: top",
@@ -314,7 +315,7 @@
         ), null);
    serverJmxSocket.close();
    configureJmx(config);
    // connect the the JMX service using the new port
    connector = connect("cn=directory manager", "password",serverJmxPort) ;
    jmxc = connector.getMBeanServerConnection();
@@ -322,8 +323,8 @@
    Long val = (Long) jmxGet(dn, attribute, jmxc);
    assertEquals((long) val, (long) serverJmxPort);
    connector.close();
    // re-establish the initial configuration of the JMX service
    // re-establish the initial configuration of the JMX service
    config = new ConfigEntry(TestCaseUtils.makeEntry(
        "dn: cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
        "objectClass: top",
@@ -336,9 +337,9 @@
        "ds-cfg-listen-port: " + initJmxPort,
        "cn: JMX Connection Handler"
         ), null);
    configureJmx(config);
    // Check that the old port is ok
    connector = connect("cn=directory manager", "password",
        TestCaseUtils.getServerJmxPort());
@@ -367,15 +368,15 @@
        "ds-cfg-key-store-type: JKS",
        "ds-cfg-key-store-pin: password"
         ), null);
    JmxConnectionHandler jmxConnectionHandler = getJmxConnectionHandler();
    assertNotNull(jmxConnectionHandler);
    StringBuilder reason = new StringBuilder();
    assertTrue(jmxConnectionHandler.configAddIsAcceptable(config, reason));
    assertTrue(jmxConnectionHandler.configAddIsAcceptable(config, reason));
    ConfigChangeResult result =
      jmxConnectionHandler.applyConfigurationAdd(config);
    assertEquals(ResultCode.SUCCESS, result.getResultCode());
    // Enable SSL by setting ds-cfg-use-ssl boolean and the
    // certificate alias using ds-cfg-ssl-cert-nickname attribute.
    int initJmxPort = (int) TestCaseUtils.getServerJmxPort();
@@ -391,16 +392,16 @@
        "ds-cfg-listen-port: " + initJmxPort ,
        "cn: JMX Connection Handler"
         ), null);
    configureJmx(config);
    OpendsJmxConnector jmxc = sslConnect("cn=directory manager", "password",
                                            initJmxPort);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    jmxc.close();
    // Before returning the result,
    // Before returning the result,
    // disable SSL by setting ds-cfg-use-ssl boolean
    config = new ConfigEntry(TestCaseUtils.makeEntry(
        "dn: cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
@@ -423,8 +424,8 @@
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    jmxc = connect("cn=directory manager", "password", initJmxPort);
    jmxc = connect("cn=directory manager", "password", initJmxPort);
    jmxc.close();
    assertNotNull(jmxc);
  }
@@ -435,7 +436,7 @@
  private void configureJmx(ConfigEntry config)
  {
    ArrayList<String> reasons = new ArrayList<String>();
    // Get the Jmx connection handler from the core server
    JmxConnectionHandler jmxConnectionHandler = getJmxConnectionHandler();
    assertNotNull(jmxConnectionHandler);
@@ -447,7 +448,7 @@
  }
  /**
   * Get a reference to the JMX connection handler.
   * Get a reference to the JMX connection handler.
   */
  private JmxConnectionHandler getJmxConnectionHandler()
  {
@@ -464,8 +465,8 @@
    }
    return jmxConnectionHandler;
  }
  /**
   * Connect to the JMX service.
   */
@@ -474,7 +475,7 @@
      throws MalformedURLException, IOException
  {
    HashMap<String, Object> env = new HashMap<String, Object>();
    // Provide the credentials required by the server to successfully
    // perform user authentication
    //
@@ -486,9 +487,9 @@
    else
      credentials = new String[] { user , password };
    env.put("jmx.remote.credentials", credentials);
    env.put("jmx.remote.x.client.connection.check.period",0);
    // Create an RMI connector client and
    // connect it to the RMI connector server
    //
@@ -527,7 +528,7 @@
    else
      credentials = new String[] { user , password };
    env.put("jmx.remote.credentials", credentials);
    // Provide the Trust manager.
    KeyStore ks = null ;
    ks = KeyStore.getInstance("JKS");
@@ -551,10 +552,10 @@
      return opendsConnector ;
    } catch (Exception e)
    {
      return null;
    }
  }
  /**
@@ -570,7 +571,7 @@
  /**
   * Set the enabled config attribute for a JMX connector thorugh JMX
   * operation.
   *
   *
   * @param jmxc
   *        connector to use for the interaction
   * @param testedConnector
@@ -626,7 +627,7 @@
    String jmxName = JMXMBean.getJmxName(DN.decode(dn));
    ObjectName name = ObjectName.getInstance(jmxName);
    Attribute attr = new Attribute(attributeName, value);
    mbsc.setAttribute(name, attr);
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java
@@ -245,7 +245,7 @@
    DirectoryServer.setCheckSchema(false);
    // Create an internal connection
    connection = new InternalClientConnection();
    connection = InternalClientConnection.getRootConnection();
    // Create backend top level entries
    String[] topEntries = new String[2];
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java
@@ -198,7 +198,7 @@
    TestCaseUtils.startServer();
    // Create an internal connection
    connection = new InternalClientConnection();
    connection = InternalClientConnection.getRootConnection();
    // Disable schema check
    schemaCheck = DirectoryServer.checkSchema();
@@ -365,7 +365,7 @@
        }
      } catch (Exception e)
      {}
      finally
      finally
      {
        synchronized (this)
        {
@@ -383,7 +383,7 @@
    {
      synchronized (this)
      {
          int i = 20;
        int i = 20;
        while ((finished != true) && (i-- >0))
        {
          try
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SynchronizationTestCase.java
@@ -104,7 +104,7 @@
    schemaCheck = DirectoryServer.checkSchema();
    // Create an internal connection
    connection = new InternalClientConnection();
    connection = InternalClientConnection.getRootConnection();
  }
  /**
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java
@@ -107,7 +107,7 @@
    DirectoryServer.setCheckSchema(false);
    // Create an internal connection
    connection = new InternalClientConnection();
    connection = InternalClientConnection.getRootConnection();
    // Create backend top level entries
    String[] topEntries = new String[2];
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/changelog/UpdateComparatorTest.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006 Sun Microsystems, Inc.
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.synchronization.changelog;
@@ -65,7 +65,8 @@
    //
    // Create the update messgae
    InternalClientConnection connection = new InternalClientConnection();
    InternalClientConnection connection =
        InternalClientConnection.getRootConnection();
    DeleteOperation op = null;
    try
    {
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/plugin/ModifyConflictTest.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006 Sun Microsystems, Inc.
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.synchronization.plugin;
@@ -343,7 +343,7 @@
        .getOperationalAttributes();
    operationalAttributes.put(Historical.entryuuidAttrType, uuidList);
    // load historical from the entry
    Historical hist = Historical.load(entry);
@@ -383,7 +383,8 @@
      ModificationType modType, String value,
      int date, boolean keepChangeResult)
  {
    InternalClientConnection connection = new InternalClientConnection();
    InternalClientConnection connection =
        InternalClientConnection.getRootConnection();
    ChangeNumber t = new ChangeNumber(date, (short) 0, (short) 0);
    /* create AttributeType description that will be usedfor this test */
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/SynchronizationMsgTest.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006 Sun Microsystems, Inc.
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.synchronization.protocol;
@@ -135,7 +135,8 @@
         throws Exception
  {
    DN dn = DN.decode(rawdn);
    InternalClientConnection connection = new InternalClientConnection();
    InternalClientConnection connection =
        InternalClientConnection.getRootConnection();
    ModifyMsg msg = new ModifyMsg(changeNumber, dn, mods, "fakeuniqueid");
    ModifyMsg generatedMsg = (ModifyMsg) SynchronizationMessage
        .generateMsg(msg.getBytes());
@@ -228,7 +229,8 @@
  public void deleteEncodeDecode(String rawDN)
         throws Exception
  {
    InternalClientConnection connection = new InternalClientConnection();
    InternalClientConnection connection =
        InternalClientConnection.getRootConnection();
    DeleteOperation op = new DeleteOperation(connection, 1, 1,null,
                                             DN.decode(rawDN));
    ChangeNumber cn = new ChangeNumber(TimeThread.getTime(),
@@ -273,7 +275,8 @@
                                   boolean deleteOldRdn, String newSuperior)
         throws Exception
  {
    InternalClientConnection connection = new InternalClientConnection();
    InternalClientConnection connection =
      InternalClientConnection.getRootConnection();
    ModifyDNOperation op =
      new ModifyDNOperation(connection, 1, 1, null,
                  DN.decode(rawDN), RDN.decode(newRdn), deleteOldRdn,
@@ -358,7 +361,8 @@
    // TODO : should test that generated attributes match original attributes.
    // Create an new Add Operation from the current addMsg
    InternalClientConnection connection = new InternalClientConnection();
    InternalClientConnection connection =
        InternalClientConnection.getRootConnection();
    AddOperation addOp = msg.createOperation(connection, rawDN) ;
    // TODO : should test that generated attributes match original attributes.
    // List<LDAPAttribute> rawAtt = addOp.getRawAttributes();