Ejemplo n.º 1
0
  /**
   * Get admin port of the OpenDJ server
   *
   * @param username The username of the directory admin
   * @param password The password of the directory admin
   * @param hostname The hostname of the directory server
   * @param port The port of the directory server
   * @return The admin port
   */
  public static String getAdminPort(
      String username, String password, String hostname, String port) {
    final String adminConnectorDN = "cn=Administration Connector,cn=config";
    final String[] attrs = {"ds-cfg-listen-port"};
    String adminPort = null;
    LDAPConnection ld = null;

    try {
      LDAPConnection lc = getLDAPConnection(hostname, port, username, password);

      if (lc != null) {
        LDAPEntry le = lc.read(adminConnectorDN, attrs);

        if (le != null) {
          LDAPAttribute la = le.getAttribute(attrs[0]);

          if (la != null) {
            Enumeration en = la.getStringValues();

            if (en != null && en.hasMoreElements()) {
              adminPort = (String) en.nextElement();
            }
          }
        }
      }
    } catch (Exception ex) {
      Debug.getInstance(SetupConstants.DEBUG_NAME)
          .error("EmbeddedOpenDS.getAdminPort(). Error getting admin port:", ex);
    } finally {
      disconnectDServer(ld);
    }

    return adminPort;
  }
Ejemplo n.º 2
0
  /**
   * Get replication port
   *
   * @param username
   * @param password
   * @param hostname
   * @param port
   * @return port number if replication is setup, null if not or on error.
   */
  public static String getReplicationPort(
      String username, String password, String hostname, String port) {
    final String replDN =
        "cn=replication server,cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config";
    final String[] attrs = {"ds-cfg-replication-port"};
    String replPort = null;
    LDAPConnection ld = null;
    try {
      // We'll use Directory Manager
      username = "******";
      LDAPConnection lc = getLDAPConnection(hostname, port, username, password);
      if (lc != null) {
        LDAPEntry le = lc.read(replDN, attrs);
        if (le != null) {
          LDAPAttribute la = le.getAttribute(attrs[0]);
          if (la != null) {
            Enumeration en = la.getStringValues();
            if (en != null && en.hasMoreElements()) {
              replPort = (String) en.nextElement();
            }
          }
        }
      }
    } catch (Exception ex) {
      Debug.getInstance(SetupConstants.DEBUG_NAME)
          .error("EmbeddedOpenDS.getReplicationPort(). Error getting replication port:", ex);

    } finally {
      disconnectDServer(ld);
    }
    return replPort;
  }
Ejemplo n.º 3
0
 /** Gets list of replicated servers from local OpenDJ directory. */
 public static Set getServerSet(LDAPConnection lc) {
   final String[] attrs = {"uniqueMember"};
   Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
   try {
     if (lc != null) {
       LDAPEntry le = lc.read(replDN, attrs);
       if (le != null) {
         Set hostSet = new HashSet();
         LDAPAttribute la = le.getAttribute(attrs[0]);
         if (la != null) {
           Enumeration en = la.getStringValues();
           while (en != null && en.hasMoreElements()) {
             String val = (String) en.nextElement();
             // strip "cn="
             hostSet.add(val.substring(3, val.length()));
           }
         }
         return hostSet;
       } else {
         debug.error(
             "EmbeddedOpenDS:syncOpenDSServer():" + "Could not find trustkey for:" + replDN);
       }
     } else {
       debug.error(
           "EmbeddedOpenDS:syncOpenDSServer():" + "Could not connect to local opends instance.");
     }
   } catch (Exception ex) {
     debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting replication key:", ex);
   }
   return null;
 }
Ejemplo n.º 4
0
  /** Create naming event from a change control */
  private DSEvent createDSEvent(LDAPEntry entry, LDAPEntryChangeControl changeCtrl, Request req)
      throws Exception {
    DSEvent dsEvent = new DSEvent();

    if (debugger.messageEnabled()) {
      debugger.message(
          "EventService.createDSEvent() - Notifying event " + "to: " + req.getListener());
    }

    // Get the dn from the entry
    String dn = entry.getDN();
    dsEvent.setID(dn);

    // Get information on the type of change made
    int changeType = changeCtrl.getChangeType();
    dsEvent.setEventType(changeType);

    // Pass the search ID as the event's change info
    dsEvent.setSearchID(req.getRequestID());

    // set the object class name
    String className = entry.getAttribute("objectclass").toString();
    dsEvent.setClassName(className);

    return dsEvent;
  }
Ejemplo n.º 5
0
  /** Process change notification attached as the change control to the message */
  protected void processSearchResultMessage(LDAPSearchResult res, Request req) {
    LDAPEntry modEntry = res.getEntry();

    if (debugger.messageEnabled()) {
      debugger.message(
          "EventService.processSearchResultMessage() - " + "Changed " + modEntry.getDN());
    }

    /* Get any entry change controls. */
    LDAPControl[] ctrls = res.getControls();

    // Can not create event without change control
    if (ctrls == null) {
      Exception ex =
          new Exception("EventService - Cannot create " + "NamingEvent, no change control info");
      dispatchException(ex, req);
    } else {
      // Multiple controls might be in the message
      for (int i = 0; i < ctrls.length; i++) {
        LDAPEntryChangeControl changeCtrl = null;

        if (ctrls[i].getType() == LDAPControl.LDAP_ENTRY_CHANGE_CONTROL) {
          changeCtrl = (LDAPEntryChangeControl) ctrls[i];
          if (debugger.messageEnabled()) {
            debugger.message(
                "EventService."
                    + "processSearchResultMessage() changeCtrl = "
                    + changeCtrl.toString());
          }

          // Can not create event without change control
          if (changeCtrl.getChangeType() == -1) {
            Exception ex =
                new Exception(
                    "EventService - Cannot " + "create NamingEvent, no change control info");
            dispatchException(ex, req);
          }

          // Convert control into a DSEvent and dispatch to listeners
          try {
            DSEvent event = createDSEvent(modEntry, changeCtrl, req);
            dispatchEvent(event, req);
          } catch (Exception ex) {
            dispatchException(ex, req);
          }
        }
      }
    }
  }
Ejemplo n.º 6
0
 /** Removes host:port from OpenDJ replication */
 public static void delOpenDSServer(LDAPConnection lc, String delServer) {
   String replServerDN = "cn=" + delServer + ",cn=Servers,cn=admin data";
   final String[] attrs = {"ds-cfg-key-id"};
   Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
   if (lc == null) {
     debug.error(
         "EmbeddedOpenDS:syncOpenDSServer():"
             + "Could not connect to local OpenDJ instance."
             + replServerDN);
     return;
   }
   String trustKey = null;
   try {
     LDAPEntry le = lc.read(replServerDN, attrs);
     if (le != null) {
       LDAPAttribute la = le.getAttribute(attrs[0]);
       if (la != null) {
         Enumeration en = la.getStringValues();
         if (en != null && en.hasMoreElements()) {
           trustKey = (String) en.nextElement();
         }
       }
       String keyDN = "ds-cfg-key-id=" + trustKey + ",cn=instance keys,cn=admin data";
       lc.delete(keyDN);
     } else {
       debug.error(
           "EmbeddedOpenDS:syncOpenDSServer():" + "Could not find trustkey for:" + replServerDN);
     }
   } catch (Exception ex) {
     debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting replication key:", ex);
   }
   try {
     lc.delete(replServerDN);
   } catch (Exception ex) {
     debug.error(
         "EmbeddedOpenDS.syncOpenDSServer()."
             + " Error getting deleting server entry:"
             + replServerDN,
         ex);
   }
   try {
     LDAPAttribute attr = new LDAPAttribute("uniqueMember", "cn=" + delServer);
     LDAPModification mod = new LDAPModification(LDAPModification.DELETE, attr);
     lc.modify(replDN, mod);
   } catch (Exception ex) {
     debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting removing :" + replDN, ex);
   }
 }