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

Jean-Noel Rouvignac
08.06.2015 b8c6b80da1cb6118167a934daa480eb381c59e0e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions Copyright 2013-2015 ForgeRock AS
 */
package org.opends.server.protocols.jmx;
 
import static org.testng.Assert.*;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.security.KeyStore;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
 
import javax.management.Attribute;
import javax.management.AttributeNotFoundException;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.net.ssl.TrustManagerFactory;
 
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.server.AdminTestCaseUtils;
import org.opends.server.admin.std.meta.JMXConnectionHandlerCfgDefn;
import org.opends.server.admin.std.server.JMXConnectionHandlerCfg;
import org.opends.server.config.JMXMBean;
import org.opends.server.core.AddOperationBasis;
import org.opends.server.core.DeleteOperation;
import org.opends.server.core.DeleteOperationBasis;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.forgerock.opendj.config.server.ConfigChangeResult;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.forgerock.opendj.ldap.ResultCode;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
 
/**
 * A simple test for : - JMX connection establishment without using SSL -
 * JMX get and set - configuration change
 */
@SuppressWarnings("javadoc")
public class JmxConnectTest extends JmxTestCase {
 
  /**
   * Set up the environment for performing the tests in this suite.
   *
   * @throws Exception
   *           If the environment could not be set up.
   */
  @Override
  @BeforeClass
  public void setUp() throws Exception
  {
    super.setUp();
 
    TestCaseUtils.addEntries(
        "dn: cn=Privileged User,o=test",
        "objectClass: top",
        "objectClass: person",
        "objectClass: organizationalPerson",
        "objectClass: inetOrgPerson",
        "cn: Privileged User",
        "givenName: Privileged",
        "sn: User",
        "uid: privileged.user",
        "userPassword: password",
        "ds-privilege-name: config-read",
        "ds-privilege-name: config-write",
        "ds-privilege-name: password-reset",
        "ds-privilege-name: update-schema",
        "ds-privilege-name: ldif-import",
        "ds-privilege-name: ldif-export",
        "ds-privilege-name: backend-backup",
        "ds-privilege-name: backend-restore",
        "ds-privilege-name: proxied-auth",
        "ds-privilege-name: bypass-acl",
        "ds-privilege-name: unindexed-search",
        "ds-privilege-name: jmx-read",
        "ds-privilege-name: jmx-write",
        "ds-pwp-password-policy-dn: cn=Clear UserPassword Policy," +
             "cn=Password Policies,cn=config",
        "",
        "dn: cn=Unprivileged JMX User,o=test",
        "objectClass: top",
        "objectClass: person",
        "objectClass: organizationalPerson",
        "objectClass: inetOrgPerson",
        "cn: Privileged User",
        "givenName: Privileged",
        "sn: User",
        "uid: privileged.user",
        "userPassword: password",
        "ds-privilege-name: config-read",
        "ds-privilege-name: config-write",
        "ds-privilege-name: password-reset",
        "ds-privilege-name: update-schema",
        "ds-privilege-name: ldif-import",
        "ds-privilege-name: ldif-export",
        "ds-privilege-name: backend-backup",
        "ds-privilege-name: backend-restore",
        "ds-privilege-name: proxied-auth",
        "ds-privilege-name: bypass-acl",
        "ds-privilege-name: unindexed-search",
        "ds-pwp-password-policy-dn: cn=Clear UserPassword Policy," +
             "cn=Password Policies,cn=config");
  }
 
 
  /**
   * Clean up the environment after performing the tests in this suite.
   *
   * @throws Exception
   *           If the environment could not be set up.
   */
  @AfterClass
  public void afterClass() throws Exception
  {
    InternalClientConnection conn = InternalClientConnection
        .getRootConnection();
 
    DeleteOperation deleteOperation = conn.processDelete(DN
        .valueOf("cn=Privileged User,o=test"));
    assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
 
    deleteOperation = conn.processDelete(DN
        .valueOf("cn=Unprivileged JMX User,o=test"));
    assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
  }
 
 
 
  /**
   * Build data for the simpleConnect test.
   *
   * @return the data.
   */
  @DataProvider(name = "simpleConnect")
  Object[][] createCredentials() {
    return new Object[][] {
        { "cn=directory manager", "password", false }, // no JMX_READ privilege
        { "cn=Privileged User,o=test", "password", true },
        { "cn=Privileged User,o=test", "wrongPassword", false },
        { "cn=wrong user", "password", false },
        { "invalid DN", "password", false },
        { "cn=Privileged User,o=test", null, false },
        { null, "password", false }, { null, null, false }, };
  }
 
 
 
  /**
   * Check that simple (no SSL) connections to the JMX service are
   * accepted when the given credentials are OK and refused when the
   * credentials are invalid.
   */
  @Test(enabled = false, dataProvider = "simpleConnect")
  public void simpleConnect(String user, String password,
      boolean expectedResult) throws Exception {
    OpendsJmxConnector connector = connect(user, password,
        TestCaseUtils.getServerJmxPort());
    assertEquals((connector != null), expectedResult);
    if (connector != null) {
      connector.close();
    }
  }
 
  /**
   * Build some data for the simpleGet test.
   */
  @DataProvider(name = "simpleGet")
  Object[][] createNames() {
    return new Object[][] {
        {
            "cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
            "ds-cfg-listen-port", TestCaseUtils.getServerJmxPort() },
        {
            "cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
            "objectclass", null },
        {
            "cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
            "ds-cfg-ssl-cert-nickname", "server-cert" },
    // not working at the moment see issue 655
    // {"cn=JE
    // Database,ds-cfg-backend-id=userRoot,cn=Backends,cn=config",
    // "ds-cfg-db-cache-percent", 10},
    };
  }
 
 
 
  /**
   * Test simple JMX get.
   */
  @Test(enabled = false, dataProvider = "simpleGet")
  public void simpleGet(String dn, String attributeName, Object value)
      throws Exception {
 
    OpendsJmxConnector connector = connect("cn=Privileged User,o=test",
        "password", TestCaseUtils.getServerJmxPort());
    MBeanServerConnection jmxc = connector.getMBeanServerConnection();
    assertNotNull(jmxc);
 
    Object val = jmxGet(dn, attributeName, jmxc);
 
    if (value != null) {
      assertEquals(val, value);
    } else {
      assertTrue(val == null);
    }
    connector.close();
  }
 
 
 
  /**
   * Test setting some config attribute through jmx.
   */
  // NOTE:  This test is disabled because JMX interaction is not allowed with
  //        the admin framework, and the cn=config entry is now governed by it.
  @Test(enabled = false)
  public void simpleSet() throws Exception {
    OpendsJmxConnector connector = connect("cn=Privileged User,o=test",
        "password", TestCaseUtils.getServerJmxPort());
    MBeanServerConnection jmxc = connector.getMBeanServerConnection();
    assertNotNull(jmxc);
 
    jmxc.queryNames(null, null).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(newVal, val + 1);
 
    jmxSet(dn, attribute, val + 1, jmxc);
 
    connector.close();
  }
 
 
 
  /**
   * Test that disabling JMX connection handler does its job by -
   * opening a JMX connection - changing the JMX connection handler
   * state to disable - trying to open a new JMX connection and check
   * that it fails.
   *
   * @throws Exception
   */
  @Test(enabled = false)
  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.
    ServerSocket serverJmxSocket = new ServerSocket();
    serverJmxSocket.setReuseAddress(true);
    serverJmxSocket.bind(new InetSocketAddress("127.0.0.1", 0));
    int serverJmxPort = serverJmxSocket.getLocalPort();
    serverJmxSocket.close();
    Entry newJmxConnectionJmx = TestCaseUtils
        .makeEntry(
            "dn: cn= New JMX Connection Handler,cn=Connection Handlers,cn=config",
            "objectClass: top",
            "objectClass: ds-cfg-connection-handler",
            "objectClass: ds-cfg-jmx-connection-handler",
            "ds-cfg-ssl-cert-nickname: server-cert",
            "ds-cfg-java-class: org.opends.server.protocols.jmx.JmxConnectionHandler",
            "ds-cfg-enabled: true",
            "ds-cfg-use-ssl: false", "ds-cfg-listen-port: "
                + serverJmxPort, "cn: JMX Connection Handler");
    InternalClientConnection connection =
      InternalClientConnection.getRootConnection();
    AddOperationBasis addOp = new AddOperationBasis(connection,
        InternalClientConnection.nextOperationID(),
        InternalClientConnection.nextMessageID(), null,
        newJmxConnectionJmx.getName(), newJmxConnectionJmx
            .getObjectClasses(), newJmxConnectionJmx
            .getUserAttributes(), newJmxConnectionJmx
            .getOperationalAttributes());
    addOp.run();
    Thread.sleep(200);
    OpendsJmxConnector newJmxConnector = connect(
        "cn=Privileged User,o=test", "password", serverJmxPort);
    assertNotNull(newJmxConnector);
    newJmxConnector.close();
 
    // Get the "old" connector
    OpendsJmxConnector connector = connect("cn=Privileged User,o=test",
        "password", TestCaseUtils.getServerJmxPort());
    MBeanServerConnection jmxc = connector.getMBeanServerConnection();
    assertNotNull(jmxc);
 
    // Disable the "new" connector
    toggleEnableJmxConnector(connector, newJmxConnectionJmx.getName(), false);
    Thread.sleep(100);
    OpendsJmxConnector jmxcDisabled = connect("cn=Privileged User,o=test",
        "password", serverJmxPort);
    assertNull(jmxcDisabled);
 
    toggleEnableJmxConnector(connector, newJmxConnectionJmx.getName(), true);
    Thread.sleep(100);
    jmxcDisabled = connect("cn=Privileged User,o=test", "password", serverJmxPort);
    assertNotNull(jmxcDisabled);
 
    // cleanup client connection
    connector.close();
    jmxcDisabled.close();
    DeleteOperationBasis delOp = new DeleteOperationBasis(connection,
        InternalClientConnection.nextOperationID(),
        InternalClientConnection.nextMessageID(), null,
        newJmxConnectionJmx.getName());
    delOp.run();
  }
 
 
 
  /**
   * Test changing JMX port through LDAP.
   */
  @Test(enabled = false)
  public void changePort() throws Exception {
    // Connect to the JMX service and get the current port
    final String dn = "cn=JMX Connection Handler,cn=Connection Handlers,cn=config";
    final String attribute = "ds-cfg-listen-port";
 
    OpendsJmxConnector connector = connect("cn=Privileged User,o=test",
        "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 a free port
    int serverJmxPort = TestCaseUtils.findFreePort();
 
    Entry entry = TestCaseUtils
            .makeEntry(
                "dn: cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
                "objectClass: top",
                "objectClass: ds-cfg-connection-handler",
                "objectClass: ds-cfg-jmx-connection-handler",
                "ds-cfg-ssl-cert-nickname: server-cert",
                "ds-cfg-java-class: org.opends.server.protocols.jmx.JmxConnectionHandler",
                "ds-cfg-enabled: true",
                "ds-cfg-use-ssl: false", "ds-cfg-listen-port: "
                    + serverJmxPort, "cn: JMX Connection Handler");
    configureJmx(entry);
 
    // connect the the JMX service using the new port
    connector = connect("cn=Privileged User,o=test", "password", serverJmxPort);
    jmxc = connector.getMBeanServerConnection();
    assertNotNull(jmxc);
    long val = (Long) jmxGet(dn, attribute, jmxc);
    assertEquals(val, serverJmxPort);
    connector.close();
 
    // re-establish the initial configuration of the JMX service
    entry = TestCaseUtils
            .makeEntry(
                "dn: cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
                "objectClass: top",
                "objectClass: ds-cfg-connection-handler",
                "objectClass: ds-cfg-jmx-connection-handler",
                "ds-cfg-ssl-cert-nickname: server-cert",
                "ds-cfg-java-class: org.opends.server.protocols.jmx.JmxConnectionHandler",
                "ds-cfg-enabled: true",
                "ds-cfg-use-ssl: false", "ds-cfg-listen-port: "
                    + initJmxPort, "cn: JMX Connection Handler");
 
    configureJmx(entry);
 
    // Check that the old port is ok
    connector = connect("cn=Privileged User,o=test", "password",
        TestCaseUtils.getServerJmxPort());
    jmxc = connector.getMBeanServerConnection();
    assertNotNull(jmxc);
  }
 
 
 
  /**
   * Check that simple (no SSL) connections to the JMX service are
   * accepted when the given credentials are OK and refused when the
   * credentials are invalid.
   */
  @Test(enabled = false) // this fails a lot especially due to the in core restarts
  public void sslConnect() throws Exception {
    // Enable SSL by setting ds-cfg-use-ssl boolean and the
    // certificate alias using ds-cfg-ssl-cert-nickname attribute.
    int initJmxPort = TestCaseUtils.getServerJmxPort();
 
    Entry entry = TestCaseUtils
        .makeEntry(
            "dn: cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
            "objectClass: top",
            "objectClass: ds-cfg-connection-handler",
            "objectClass: ds-cfg-jmx-connection-handler",
            "ds-cfg-ssl-cert-nickname: server-cert",
            "ds-cfg-java-class: org.opends.server.protocols.jmx.JmxConnectionHandler",
            "ds-cfg-enabled: true",
            "ds-cfg-use-ssl: true",
            "ds-cfg-listen-port: " + initJmxPort,
            "ds-cfg-key-manager-provider: cn=JKS,cn=Key Manager Providers,cn=config",
            "cn: JMX Connection Handler");
 
    configureJmx(entry);
 
    OpendsJmxConnector jmxc = sslConnect("cn=Privileged User,o=test",
        "password", initJmxPort);
    assertNotNull(jmxc,"OpendsJmxConnector shouldn't be null");
    jmxc.getMBeanServerConnection();
    jmxc.close();
 
    // Before returning the result,
    // disable SSL by setting ds-cfg-use-ssl boolean
    entry = TestCaseUtils
            .makeEntry(
                "dn: cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
                "objectClass: top",
                "objectClass: ds-cfg-connection-handler",
                "objectClass: ds-cfg-jmx-connection-handler",
                "ds-cfg-ssl-cert-nickname: server-cert",
                "ds-cfg-java-class: org.opends.server.protocols.jmx.JmxConnectionHandler",
                "ds-cfg-enabled: true",
                "ds-cfg-use-ssl: false", "ds-cfg-listen-port: "
                    + initJmxPort, "cn: JMX Connection Handler");
    try {
      configureJmx(entry);
    } catch (RuntimeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
 
    jmxc = connect("cn=Privileged User,o=test", "password", initJmxPort);
    jmxc.close();
    assertNotNull(jmxc);
  }
 
 
 
  private void configureJmx(Entry entry) throws Exception {
    ArrayList<LocalizableMessage> reasons = new ArrayList<>();
 
    // Get the Jmx connection handler from the core server
    JmxConnectionHandler jmxConnectionHandler = getJmxConnectionHandler();
    assertNotNull(jmxConnectionHandler);
 
    JMXConnectionHandlerCfg config = AdminTestCaseUtils
        .getConfiguration(JMXConnectionHandlerCfgDefn
            .getInstance(), entry);
 
    if (!jmxConnectionHandler.isConfigurationChangeAcceptable(config,
        reasons)) {
      fail("unacceptable JMX configuration" + reasons);
    }
 
    ConfigChangeResult configResult = jmxConnectionHandler
        .applyConfigurationChange(config);
 
    assertEquals(configResult.getResultCode(), ResultCode.SUCCESS);
  }
 
  /**
   * Connect to the JMX service.
   */
  private OpendsJmxConnector connect(String user, String password, int jmxPort)
        throws MalformedURLException, IOException {
    Map<String, Object> env = new HashMap<>();
 
    // Provide the credentials required by the server to successfully
    // perform user authentication
    String[] credentials;
    if ((user == null) && (password == null)) {
      credentials = null;
    }
    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
    OpendsJmxConnector opendsConnector;
    try {
      opendsConnector = new OpendsJmxConnector("localhost", jmxPort, env);
      opendsConnector.connect();
      return opendsConnector;
    } catch (SecurityException e) {
      return null;
    } catch (IOException e) {
      return null;
    }
  }
 
 
 
  /**
   * Connect to the JMX service using SSL.
   */
  private OpendsJmxConnector sslConnect(String user, String password,
      long jmxPort) throws Exception {
    Map<String, Object> env = new HashMap<>();
 
    // Provide the credentials required by the server to successfully
    // perform user authentication
    String[] credentials;
    if ((user == null) && (password == null)) {
      credentials = null;
    }
    else
    {
      credentials = new String[] { user, password };
    }
    env.put("jmx.remote.credentials", credentials);
 
    // Provide the Trust manager.
    KeyStore ks = KeyStore.getInstance("JKS");
    FileInputStream keyStoreFile = new FileInputStream(getJmxKeystorePath());
    ks.load(keyStoreFile, "password".toCharArray());
    keyStoreFile.close();
 
    TrustManagerFactory tmf = TrustManagerFactory
        .getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(ks);
    env.put(JmxConnectionHandler.TRUST_MANAGER_ARRAY_KEY, tmf.getTrustManagers());
 
    // Create an RMI connector client and
    // connect it to the RMI connector server
    OpendsJmxConnector opendsConnector;
    try {
      opendsConnector = new OpendsJmxConnector("localhost",
          (int) jmxPort, env);
      opendsConnector.connect();
      return opendsConnector;
    } catch (Exception e) {
      return null;
    }
  }
 
 
 
  private String getJmxKeystorePath() {
    return DirectoryServer.getInstanceRoot() + File.separator + "config"
        + File.separator + "server.keystore";
  }
 
 
 
  /**
   * Set the enabled config attribute for a JMX connector thorugh JMX
   * operation.
   *
   * @param jmxc
   *          connector to use for the interaction
   * @param testedConnector
   *          The DN of the connector the test
   * @param enabled
   *          the value of the enabled config attribute
   */
  private void toggleEnableJmxConnector(OpendsJmxConnector jmxc,
      DN testedConnector, boolean enabled) throws Exception {
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
 
    // Get status of the JMX connection handler
    String jmxName = JMXMBean.getJmxName(testedConnector);
    ObjectName name = ObjectName.getInstance(jmxName);
    Attribute status = (Attribute) mbsc.getAttribute(name,
        "ds-cfg-enabled");
    if (status != null)
    {
      status.getValue();
    }
    Attribute attr = new Attribute(
        "ds-cfg-enabled", enabled);
    mbsc.setAttribute(name, attr);
    status = (Attribute) mbsc.getAttribute(name,
        "ds-cfg-enabled");
 
    status = null;
  }
 
 
 
  /**
   * Get an attribute value through JMX.
   */
  private Object jmxGet(String dn, String attributeName,
      MBeanServerConnection mbsc) throws Exception {
    String jmxName = JMXMBean.getJmxName(DN.valueOf(dn));
    ObjectName name = ObjectName.getInstance(jmxName);
 
    try
    {
      Attribute status = (Attribute) mbsc.getAttribute(name, attributeName);
      if (status != null)
      {
        return status.getValue();
      }
      return null;
    }
    catch (AttributeNotFoundException anfe)
    {
      return null;
    }
  }
 
 
 
  /**
   * Set an attribute value through JMX.
   */
  private void jmxSet(String dn, String attributeName, Object value,
      MBeanServerConnection mbsc) throws Exception {
    String jmxName = JMXMBean.getJmxName(DN.valueOf(dn));
    ObjectName name = ObjectName.getInstance(jmxName);
    Attribute attr = new Attribute(attributeName, value);
 
    mbsc.setAttribute(name, attr);
  }
 
}