/** {@inheritDoc} */
    @Override
    public void addCancelRequestListener(final CancelRequestListener listener) {
      Reject.ifNull(listener);

      boolean invokeImmediately = false;
      synchronized (stateLock) {
        switch (state) {
          case PENDING:
            if (cancelRequestListeners == null) {
              cancelRequestListeners = new LinkedList<>();
            }
            cancelRequestListeners.add(listener);
            break;
          case CANCEL_REQUESTED:
            // Signal immediately outside lock.
            invokeImmediately = true;
            break;
          case TOO_LATE:
          case RESULT_SENT:
          case CANCELLED:
            /*
             * No point in registering the callback since the request
             * can never be cancelled now.
             */
            break;
        }
      }

      if (invokeImmediately) {
        listener.handleCancelRequest(cancelRequestReason);
      }
    }
  /**
   * Creates a new entry with the provided information.
   *
   * @param dn The distinguished name for this entry. It must not be <CODE>null</CODE>.
   * @param modifications The modifications for this change record. It must not be <CODE>null</CODE>
   *     .
   */
  public ModifyChangeRecordEntry(DN dn, Collection<RawModification> modifications) {
    super(dn);

    ifNull(modifications);

    this.modifications = new ArrayList<>(modifications);
  }
  /**
   * Creates a new virtual static group instance with the provided information.
   *
   * @param groupEntryDN The DN of the entry that holds the definition for this group. It must not
   *     be {@code null}.
   * @param targetGroupDN The DN of the target group that will provide membership information. It
   *     must not be {@code null}.
   */
  public VirtualStaticGroup(DN groupEntryDN, DN targetGroupDN) {
    super();

    ifNull(groupEntryDN, targetGroupDN);

    this.groupEntryDN = groupEntryDN;
    this.targetGroupDN = targetGroupDN;
  }
  /**
   * Sets the value for an "extra" property for this schema element. If a property already exists
   * with the specified name, then it will be overwritten. If the value is {@code null}, then any
   * existing property with the given name will be removed.
   *
   * @param elem The element where to set the extra property
   * @param name The name for the "extra" property. It must not be {@code null}.
   * @param value The value for the "extra" property. If it is {@code null}, then any existing
   *     definition will be removed.
   */
  public static void setExtraProperty(SchemaFileElement elem, String name, String value) {
    ifNull(name);

    if (value == null) {
      elem.getExtraProperties().remove(name);
    } else {
      elem.getExtraProperties().put(name, newLinkedList(value));
    }
  }
  /** {@inheritDoc} */
  @Override
  public boolean isGroupDefinition(Entry entry) {
    ifNull(entry);

    // FIXME -- This needs to exclude enhanced groups once we have support for
    // them.
    ObjectClass virtualStaticGroupClass =
        DirectoryServer.getObjectClass(OC_VIRTUAL_STATIC_GROUP, true);
    return entry.hasObjectClass(virtualStaticGroupClass);
  }
    /** {@inheritDoc} */
    @Override
    public void removeCancelRequestListener(final CancelRequestListener listener) {
      Reject.ifNull(listener);

      synchronized (stateLock) {
        if (cancelRequestListeners != null) {
          cancelRequestListeners.remove(listener);
        }
      }
    }
  /**
   * Attempts to convert the given field name, operator and value into an appropriate SearchFilter
   * instance. The conversion used depends on the {@link QueryAttribute} configured for this field
   * in the queryAttributes map.
   *
   * @param field Non null, The name of a queryable Application attribute.
   * @param operator Non null, The query operator to use when comparing the field value to the
   *     valueAssertion.
   * @param valueAssertion Non null, The value with which the Application field's value should be
   *     compared.
   */
  protected SearchFilter comparison(
      String field, SearchFilter.Operator operator, Object valueAssertion) {
    Reject.ifNull(field, operator, valueAssertion);

    QueryAttribute attribute = queryAttributes.get(field);
    if (attribute == null) {
      throw new UnsupportedOperationException("Unknown query field '" + field + "'");
    }

    return attribute.getFilter(operator, valueAssertion);
  }
 /**
  * Constructs a script object with the given name, script body, language and variable bindings.
  *
  * @param name the name of the script.
  * @param script the script itself.
  * @param language the language that the script is written in.
  * @param bindings the bindings used for the script.
  */
 public ScriptObject(
     final String name,
     final String script,
     final ScriptingLanguage language,
     final Bindings bindings) {
   Reject.ifNull(name, script, language);
   this.name = name;
   this.script = script;
   this.language = language;
   this.bindings = bindings;
 }
  /**
   * Sets the values for an "extra" property for this schema element. If a property already exists
   * with the specified name, then it will be overwritten. If the set of values is {@code null} or
   * empty, then any existing property with the given name will be removed.
   *
   * @param name The name for the "extra" property. It must not be {@code null}.
   * @param values The set of values for the "extra" property. If it is {@code null} or empty, then
   *     any existing definition will be removed.
   */
  public final void setExtraProperty(String name, List<String> values) {

    ifNull(name);

    if (values == null || values.isEmpty()) {
      extraProperties.remove(name);
    } else {
      LinkedList<String> valuesCopy = new LinkedList<>(values);
      extraProperties.put(name, valuesCopy);
    }
  }
Exemple #10
0
 /**
  * Open a log with the provided log path, record parser and maximum size per log file.
  *
  * <p>If no log exists for the provided path, a new one is created.
  *
  * @param <K> Type of the key of a record, which must be comparable.
  * @param <V> Type of the value of a record.
  * @param replicationEnv The replication environment used to create this log.
  * @param logPath Path of the log.
  * @param parser Parser for encoding/decoding of records.
  * @param rotationParameters Parameters for the log files rotation.
  * @return a log
  * @throws ChangelogException If a problem occurs during initialization.
  */
 static synchronized <K extends Comparable<K>, V> Log<K, V> openLog(
     final ReplicationEnvironment replicationEnv,
     final File logPath,
     final RecordParser<K, V> parser,
     final LogRotationParameters rotationParameters)
     throws ChangelogException {
   Reject.ifNull(logPath, parser);
   @SuppressWarnings("unchecked")
   Log<K, V> log = (Log<K, V>) logsCache.get(logPath);
   if (log == null) {
     log = new Log<>(replicationEnv, logPath, parser, rotationParameters);
     logsCache.put(logPath, log);
   } else {
     // TODO : check that parser and size limit are compatible with the existing one,
     // and issue a warning if it is not the case
     log.referenceCount++;
   }
   return log;
 }
  /** {@inheritDoc} */
  @Override
  public VirtualStaticGroup newInstance(ServerContext serverContext, Entry groupEntry)
      throws DirectoryException {
    ifNull(groupEntry);

    // Get the target group DN attribute from the entry, if there is one.
    DN targetDN = null;
    AttributeType targetType = DirectoryServer.getAttributeType(ATTR_TARGET_GROUP_DN, true);
    List<Attribute> attrList = groupEntry.getAttribute(targetType);
    if (attrList != null) {
      for (Attribute a : attrList) {
        for (ByteString v : a) {
          if (targetDN != null) {
            LocalizableMessage message =
                ERR_VIRTUAL_STATIC_GROUP_MULTIPLE_TARGETS.get(groupEntry.getName());
            throw new DirectoryException(ResultCode.OBJECTCLASS_VIOLATION, message);
          }

          try {
            targetDN = DN.decode(v);
          } catch (DirectoryException de) {
            logger.traceException(de);

            LocalizableMessage message =
                ERR_VIRTUAL_STATIC_GROUP_CANNOT_DECODE_TARGET.get(
                    v, groupEntry.getName(), de.getMessageObject());
            throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, message, de);
          }
        }
      }
    }

    if (targetDN == null) {
      LocalizableMessage message = ERR_VIRTUAL_STATIC_GROUP_NO_TARGET.get(groupEntry.getName());
      throw new DirectoryException(ResultCode.OBJECTCLASS_VIOLATION, message);
    }

    return new VirtualStaticGroup(groupEntry.getName(), targetDN);
  }
    private <R extends ExtendedResult> void cancel(
        final LocalizableMessage reason,
        final ExtendedRequest<R> cancelRequest,
        final LdapResultHandler<R> cancelResultHandler,
        final boolean sendResult) {
      Reject.ifNull(reason);

      if (!isCancelSupported) {
        if (cancelResultHandler != null) {
          final Result result = Responses.newGenericExtendedResult(ResultCode.CANNOT_CANCEL);
          cancelResultHandler.handleException(newLdapException(result));
        }
        return;
      }

      List<CancelRequestListener> tmpListeners = null;
      boolean invokeResultHandler = false;
      boolean resultHandlerIsSuccess = false;

      synchronized (stateLock) {
        switch (state) {
          case PENDING:
            /* Switch to CANCEL_REQUESTED state. */
            cancelRequestReason = reason;
            if (cancelResultHandler != null) {
              cancelResultHandlers = new LinkedList<>();
              cancelResultHandlers.add(
                  new ExtendedResultHandlerHolder<R>(cancelRequest, cancelResultHandler));
            }
            tmpListeners = cancelRequestListeners;
            cancelRequestListeners = null;
            state = RequestState.CANCEL_REQUESTED;
            this.sendResult &= sendResult;
            break;
          case CANCEL_REQUESTED:
            /*
             * Cancel already request so listeners already invoked.
             */
            if (cancelResultHandler != null) {
              if (cancelResultHandlers == null) {
                cancelResultHandlers = new LinkedList<>();
              }
              cancelResultHandlers.add(
                  new ExtendedResultHandlerHolder<R>(cancelRequest, cancelResultHandler));
            }
            break;
          case TOO_LATE:
          case RESULT_SENT:
            /*
             * Cannot cancel, so invoke result handler immediately
             * outside of lock.
             */
            if (cancelResultHandler != null) {
              invokeResultHandler = true;
              resultHandlerIsSuccess = false;
            }
            break;
          case CANCELLED:
            /*
             * Multiple cancellation attempts. Clients should not do
             * this, but the cancel will effectively succeed
             * immediately, so invoke result handler immediately outside
             * of lock.
             */
            if (cancelResultHandler != null) {
              invokeResultHandler = true;
              resultHandlerIsSuccess = true;
            }
            break;
        }
      }

      /* Invoke listeners outside of lock. */
      if (tmpListeners != null) {
        for (final CancelRequestListener listener : tmpListeners) {
          listener.handleCancelRequest(reason);
        }
      }

      if (invokeResultHandler) {
        if (resultHandlerIsSuccess) {
          final R result =
              cancelRequest.getResultDecoder().newExtendedErrorResult(ResultCode.SUCCESS, "", "");
          cancelResultHandler.handleResult(result);
        } else {
          final Result result = Responses.newGenericExtendedResult(ResultCode.TOO_LATE);
          cancelResultHandler.handleException(newLdapException(result));
        }
      }
    }
 /**
  * Constructs the compiled script with the given script engine and compiled Rhino script object.
  *
  * @param engine the script engine to use to run the compiled script. Must not be null.
  * @param compiledScript the compiled script itself. Must not be null.
  */
 RhinoCompiledScript(final RhinoScriptEngine engine, final Script compiledScript) {
   Reject.ifNull(engine, compiledScript);
   this.engine = engine;
   this.compiledScript = compiledScript;
 }
 /**
  * Creates a new {@code FallbackAuthContext} managing the provided {@code AsyncServerAuthModule}s.
  *
  * @param logger The {@link Logger} instance.
  * @param authModules The {@code List} of {@code AsyncServerAuthModule}s.
  */
 public FallbackAuthContext(Logger logger, List<AsyncServerAuthModule> authModules) {
   Reject.ifNull(logger, authModules);
   this.logger = logger;
   this.authModules = withValidation(withAuditing(withLogging(logger, authModules)));
 }
Exemple #15
0
 /**
  * Creates a new Root DSE instance backed by the provided entry. Modifications made to {@code
  * entry} will be reflected in the returned Root DSE. The returned Root DSE instance is
  * unmodifiable and attempts to use modify any of the returned collections will result in a {@code
  * UnsupportedOperationException}.
  *
  * @param entry The Root DSE entry.
  * @return A Root DSE instance backed by the provided entry.
  * @throws NullPointerException If {@code entry} was {@code null} .
  */
 public static RootDSE valueOf(Entry entry) {
   Reject.ifNull(entry);
   return new RootDSE(entry);
 }
 /**
  * Sets the decoding options which will be used to control how requests and responses are decoded.
  *
  * @param decodeOptions The decoding options which will be used to control how requests and
  *     responses are decoded (never {@code null}).
  * @return A reference to this set of options.
  * @throws NullPointerException If {@code decodeOptions} was {@code null}.
  */
 public T setDecodeOptions(final DecodeOptions decodeOptions) {
   Reject.ifNull(decodeOptions);
   this.decodeOptions = decodeOptions;
   return getThis();
 }
 /**
  * Creates a new contains value condition.
  *
  * @param propertyName The property name.
  * @param stringValue The string representation of the required property value.
  */
 public ContainsCondition(String propertyName, String stringValue) {
   Reject.ifNull(propertyName, stringValue);
   this.propertyName = propertyName;
   this.propertyStringValue = stringValue;
 }
Exemple #18
0
 public void put(WriteableTransaction txn, EntryID entryID, ByteSequence encodedEntry)
     throws StorageRuntimeException, DirectoryException {
   Reject.ifNull(txn, "txn must not be null.");
   txn.put(getName(), entryID.toByteString(), encodedEntry);
 }