001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * docs/licenses/cddl.txt
011 * or http://www.opensource.org/licenses/cddl1.php.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * docs/licenses/cddl.txt.  If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 *      Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 *      Copyright 2013-2021 Ping Identity Corporation
026 */
027package com.unboundid.directory.sdk.ds.api;
028
029
030
031import java.util.Collections;
032import java.util.List;
033import java.util.Map;
034
035import com.unboundid.directory.sdk.broker.internal.BrokerExtension;
036import com.unboundid.directory.sdk.common.internal.ExampleUsageProvider;
037import com.unboundid.directory.sdk.common.internal.Reconfigurable;
038import com.unboundid.directory.sdk.common.internal.UnboundIDExtension;
039import com.unboundid.directory.sdk.common.types.Entry;
040import com.unboundid.directory.sdk.common.types.OperationContext;
041import com.unboundid.directory.sdk.ds.config.SearchEntryCriteriaConfig;
042import com.unboundid.directory.sdk.ds.types.DirectoryServerContext;
043import com.unboundid.directory.sdk.ds.internal.DirectoryServerExtension;
044import com.unboundid.directory.sdk.metrics.internal.MetricsEngineExtension;
045import com.unboundid.directory.sdk.proxy.internal.DirectoryProxyServerExtension;
046import com.unboundid.directory.sdk.sync.internal.SynchronizationServerExtension;
047import com.unboundid.ldap.sdk.Control;
048import com.unboundid.ldap.sdk.LDAPException;
049import com.unboundid.ldap.sdk.ResultCode;
050import com.unboundid.util.Extensible;
051import com.unboundid.util.ThreadSafety;
052import com.unboundid.util.ThreadSafetyLevel;
053import com.unboundid.util.args.ArgumentException;
054import com.unboundid.util.args.ArgumentParser;
055
056
057
058/**
059 * This class defines an API that must be implemented by extensions which can
060 * be used to classify client search result entries.
061 * <BR>
062 * <H2>Configuring Search Entry Criteria</H2>
063 * In order to configure a search entry criteria object created using this API,
064 * use a command like:
065 * <PRE>
066 *      dsconfig create-search-entry-criteria \
067 *           --criteria-name "<I>{criteria-name}</I>" \
068 *           --type third-party \
069 *           --set enabled:true \
070 *           --set "extension-class:<I>{class-name}</I>" \
071 *           --set "extension-argument:<I>{name=value}</I>"
072 * </PRE>
073 * where "<I>{criteria-name}</I>" is the name to use for the search entry
074 * criteria instance, "<I>{class-name}</I>" is the fully-qualified name of the
075 * Java class that extends
076 * {@code com.unboundid.directory.sdk.ds.api.SearchEntryCriteria}, and
077 * "<I>{name=value}</I>" represents name-value pairs for any arguments to
078 * provide to the search entry criteria.  If multiple arguments should be
079 * provided to the search entry criteria instance, then the
080 * "<CODE>--set extension-argument:<I>{name=value}</I></CODE>" option should be
081 * provided multiple times.
082 */
083@Extensible()
084@DirectoryServerExtension()
085@DirectoryProxyServerExtension(appliesToLocalContent=true,
086     appliesToRemoteContent=true)
087@SynchronizationServerExtension(appliesToLocalContent=true,
088     appliesToSynchronizedContent=false)
089@MetricsEngineExtension()
090@BrokerExtension()
091@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE)
092public abstract class SearchEntryCriteria
093       implements UnboundIDExtension,
094                  Reconfigurable<SearchEntryCriteriaConfig>,
095                  ExampleUsageProvider
096{
097  /**
098   * Creates a new instance of this search entry criteria.  All search entry
099   * criteria implementations must include a default constructor, but any
100   * initialization should generally be done in the
101   * {@code initializeSearchEntryCriteria} method.
102   */
103  public SearchEntryCriteria()
104  {
105    // No implementation is required.
106  }
107
108
109
110  /**
111   * {@inheritDoc}
112   */
113  public abstract String getExtensionName();
114
115
116
117  /**
118   * {@inheritDoc}
119   */
120  public abstract String[] getExtensionDescription();
121
122
123
124  /**
125   * {@inheritDoc}
126   */
127  public void defineConfigArguments(final ArgumentParser parser)
128         throws ArgumentException
129  {
130    // No arguments will be allowed by default.
131  }
132
133
134
135  /**
136   * Initializes this search entry criteria.
137   *
138   * @param  serverContext  A handle to the server context for the server in
139   *                        which this extension is running.
140   * @param  config         The general configuration for this search entry
141   *                        criteria.
142   * @param  parser         The argument parser which has been initialized from
143   *                        the configuration for this search entry criteria.
144   *
145   * @throws  LDAPException  If a problem occurs while initializing this search
146   *                         entry criteria.
147   */
148  public void initializeSearchEntryCriteria(
149                   final DirectoryServerContext serverContext,
150                   final SearchEntryCriteriaConfig config,
151                   final ArgumentParser parser)
152         throws LDAPException
153  {
154    // No initialization will be performed by default.
155  }
156
157
158
159  /**
160   * {@inheritDoc}
161   */
162  public boolean isConfigurationAcceptable(
163                      final SearchEntryCriteriaConfig config,
164                      final ArgumentParser parser,
165                      final List<String> unacceptableReasons)
166  {
167    // No extended validation will be performed by default.
168    return true;
169  }
170
171
172
173  /**
174   * {@inheritDoc}
175   */
176  public ResultCode applyConfiguration(final SearchEntryCriteriaConfig config,
177                                       final ArgumentParser parser,
178                                       final List<String> adminActionsRequired,
179                                       final List<String> messages)
180  {
181    // By default, no configuration changes will be applied.  If there are any
182    // arguments, then add an admin action message indicating that the extension
183    // needs to be restarted for any changes to take effect.
184    if (! parser.getNamedArguments().isEmpty())
185    {
186      adminActionsRequired.add(
187           "No configuration change has actually been applied.  The new " +
188                "configuration will not take effect until this search entry " +
189                "criteria is disabled and re-enabled or until the server is " +
190                "restarted.");
191    }
192
193    return ResultCode.SUCCESS;
194  }
195
196
197
198  /**
199   * Performs any cleanup which may be necessary when this search entry criteria
200   * is to be taken out of service.
201   */
202  public void finalizeSearchEntryCriteria()
203  {
204    // No implementation is required.
205  }
206
207
208
209  /**
210   * Indicates whether the provided operation matches the criteria for this
211   * search entry criteria object.
212   *
213   * @param  o         The context for the associated search operation.
214   * @param  entry     The entry for which to make the determination.
215   * @param  controls  The controls included with the search result entry.
216   *
217   * @return  {@code true} if the provided operation matches the criteria for
218   *          this search entry criteria object, or {@code false} if not.
219   */
220  public abstract boolean matches(final OperationContext o, final Entry entry,
221                                  final List<Control> controls);
222
223
224
225  /**
226   * {@inheritDoc}
227   */
228  public Map<List<String>,String> getExamplesArgumentSets()
229  {
230    return Collections.emptyMap();
231  }
232}