Example #1
0
  /**
   * Adds a new object to the organization.
   *
   * @param object object to be added to the organization
   * @exception AccessRightsException if an access rights exception occurs
   * @exception EntryAlreadyExistsException if the entry already exists
   * @exception UMSException Fail to add the object
   * @supported.api
   */
  public void addChild(PersistentObject object)
      throws AccessRightsException, EntryAlreadyExistsException, UMSException {
    Principal principal = getPrincipal();

    if (principal == null) {
      String msg = i18n.getString(IUMSConstants.BAD_PRINCIPAL_HDL);
      throw new IllegalArgumentException(msg);
    } else if (object == null) {
      String msg = i18n.getString(IUMSConstants.BAD_OBJ_TO_ADD);
      throw new IllegalArgumentException(msg);
    }

    if (object instanceof User) {
      String pcId = getPeopleContainer((User) object);
      if (pcId != null) {
        PeopleContainer pc = new PeopleContainer(getPrincipal(), new Guid(pcId));
        pc.addUser((User) object);
      } else {
        // no match and no default value found
        // For now, the user will be addedd to the organization.
        // May want to add to the default people
        // container(ou=People) instead.
        super.addChild(object);
      }

    } else {

      super.addChild(object);
    }
  }
Example #2
0
 /** get a handle to the Directory Server Configuration Manager sets the value */
 protected static void getConfigManager() throws EventException {
   try {
     cm = DSConfigMgr.getDSConfigMgr();
   } catch (LDAPServiceException lse) {
     debugger.error(
         "EventService.getConfigManager() - Failed to get " + "handle to Configuration Manager",
         lse);
     throw new EventException(i18n.getString(IUMSConstants.DSCFG_NOCFGMGR), lse);
   }
 }
Example #3
0
  /**
   * Adds a listener to the directory.
   *
   * @supported.api
   */
  protected synchronized String addListener(
      SSOToken token,
      IDSEventListener listener,
      String base,
      int scope,
      String filter,
      int operations)
      throws LDAPException, EventException {

    if (_shutdownCalled) {
      throw new EventException(i18n.getString(IUMSConstants.DSCFG_CONNECTFAIL));
    }

    LDAPConnection lc = null;
    try {
      // Check for SMS listener and use "sms" group if present
      if ((listener.getClass().getName().equals("com.sun.identity.sm.ldap.LDAPEventManager"))
          && (cm.getServerGroup("sms") != null)) {
        lc = cm.getNewConnection("sms", LDAPUser.Type.AUTH_ADMIN);

      } else {
        lc = cm.getNewAdminConnection();
      }
    } catch (LDAPServiceException le) {
      throw new EventException(i18n.getString(IUMSConstants.DSCFG_CONNECTFAIL), le);
    }

    LDAPSearchConstraints cons = lc.getSearchConstraints();

    // Create Persistent Search Control object
    LDAPPersistSearchControl psearchCtrl =
        new LDAPPersistSearchControl(operations, CHANGES_ONLY, RETURN_CONTROLS, IS_CRITICAL);

    // Add LDAPControl array to the search constraint object
    cons.setServerControls(psearchCtrl);
    cons.setBatchSize(1);

    // Listeners can not read attributes from the event.
    // Request only javaClassName to be able to determine object type
    String[] attrs = new String[] {"objectclass"};
    LDAPSearchListener searchListener = null;
    // Set (asynchronous) persistent search request in the DS
    try {
      if (debugger.messageEnabled()) {
        debugger.message(
            "EventService.addListener() - Submiting "
                + "Persistent Search on: "
                + base
                + " for listener: "
                + listener);
      }
      searchListener = lc.search(base, scope, filter, attrs, false, null, cons);
    } catch (LDAPException le) {
      if ((lc != null) && lc.isConnected()) {
        try {
          lc.disconnect();
        } catch (Exception ex) {
          // ignored
        }
      }
      debugger.error(
          "EventService.addListener() - Failed to set " + "Persistent Search" + le.getMessage());
      throw le;
    }

    int[] outstandingRequests = searchListener.getMessageIDs();
    int id = outstandingRequests[outstandingRequests.length - 1];

    String reqID = Integer.toString(id);
    long startTime = System.currentTimeMillis();
    Request request =
        new Request(
            id, reqID, token, base, scope, filter, attrs, operations, listener, lc, startTime);
    _requestList.put(reqID, request);

    // Add this search request to the m_msgQueue so it can be
    // processed by the monitor thread
    if (_msgQueue == null) {
      _msgQueue = searchListener;
    } else {
      _msgQueue.merge(searchListener);
    }

    if (!_isThreadStarted) {
      startMonitorThread();
    } else {
      if (_requestList.size() == 1) {
        notify();
      }
    }

    if (debugger.messageEnabled()) {
      outstandingRequests = _msgQueue.getMessageIDs();
      debugger.message(
          "EventService.addListener(): merged Listener: "
              + " requestID: "
              + reqID
              + " & Request: "
              + request
              + " on to message Queue. No. of current outstanding "
              + "requests = "
              + outstandingRequests.length);
    }

    // Create new (EventService) Thread, if one doesn't exist.
    return reqID;
  }