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

Valery Kharseko
06.12.2025 d7e652c1013c88be63967d2c849bd066f38cdd0c
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
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2009 Sun Microsystems, Inc.
 * Portions Copyright 2013-2016 ForgeRock AS.
 */
package org.opends.server.api;
 
import java.util.Collections;
import java.util.List;
import java.util.Set;
 
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.server.config.server.ExtendedOperationHandlerCfg;
import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ExtendedOperation;
import org.opends.server.types.InitializationException;
 
/**
 * This class defines the set of methods and structures that must be
 * implemented by a Directory Server module that implements the
 * functionality required for one or more types of extended
 * operations.
 *
 * @param <T> The configuration class that will be provided to
 *            initialize the handler.
 */
@org.opends.server.types.PublicAPI(
     stability=org.opends.server.types.StabilityLevel.VOLATILE,
     mayInstantiate=false,
     mayExtend=true,
     mayInvoke=false)
public abstract class
     ExtendedOperationHandler<T extends ExtendedOperationHandlerCfg>
{
 
  /** The default set of supported control OIDs for this extended op. */
  private final Set<String> supportedControlOIDs;
 
  /** The default set of supported feature OIDs for this extended op. */
  private final Set<String> supportedFeatureOIDs = Collections.emptySet();
 
  /**
   * Builds an extended operation.
   */
  public ExtendedOperationHandler()
  {
    this.supportedControlOIDs = Collections.<String> emptySet();
  }
 
  /**
   * Builds an extended operation.
   *
   * @param supportedControlOIDs
   *          the default set of supported control OIDs for this extended op
   */
  public ExtendedOperationHandler(Set<String> supportedControlOIDs)
  {
    this.supportedControlOIDs = supportedControlOIDs != null ?
        Collections.unmodifiableSet(supportedControlOIDs)
        : Collections.<String> emptySet();
  }
 
  /**
   * Initializes this extended operation handler based on the
   * information in the provided configuration entry.  It should also
   * register itself with the Directory Server for the particular
   * kinds of extended operations that it will process.
   *
   * @param  config  The extended operation handler configuration that
   *                 contains the information to use to initialize
   *                 this extended operation handler.
   *
   * @throws  ConfigException  If an unrecoverable problem arises in
   *                           the process of performing the
   *                           initialization.
   *
   * @throws  InitializationException  If a problem occurs
   *                                   during initialization that is
   *                                   not related to the server
   *                                   configuration.
   */
  public void initializeExtendedOperationHandler(T config)
      throws ConfigException, InitializationException
  {
    DirectoryServer.registerSupportedExtension(getExtendedOperationOID(), this);
    registerControlsAndFeatures();
  }
 
 
 
  /**
   * Indicates whether the provided configuration is acceptable for
   * this extended operation handler.  It should be possible to call
   * this method on an uninitialized extended operation handler
   * instance in order to determine whether the extended operation
   * handler would be able to use the provided configuration.
   * <BR><BR>
   * Note that implementations which use a subclass of the provided
   * configuration class will likely need to cast the configuration
   * to the appropriate subclass type.
   *
   * @param  configuration        The extended operation handler
   *                              configuration for which to make the
   *                              determination.
   * @param  unacceptableReasons  A list that may be used to hold the
   *                              reasons that the provided
   *                              configuration is not acceptable.
   *
   * @return  {@code true} if the provided configuration is acceptable
   *          for this extended operation handler, or {@code false} if
   *          not.
   */
  public boolean isConfigurationAcceptable(
                      ExtendedOperationHandlerCfg configuration,
                      List<LocalizableMessage> unacceptableReasons)
  {
    // This default implementation does not perform any special
    // validation.  It should be overridden by extended operation
    // handler implementations that wish to perform more detailed
    // validation.
    return true;
  }
 
 
 
  /**
   * Performs any finalization that may be necessary for this extended
   * operation handler.  By default, no finalization is performed.
   */
  public void finalizeExtendedOperationHandler()
  {
    DirectoryServer.deregisterSupportedExtension(getExtendedOperationOID());
    deregisterControlsAndFeatures();
  }
 
 
 
  /**
   * Processes the provided extended operation.
   *
   * @param  operation  The extended operation to be processed.
   */
  public abstract void processExtendedOperation(ExtendedOperation
                                                     operation);
 
 
 
  /**
   * Retrieves the OIDs of the controls that may be supported by this
   * extended operation handler.  It should be overridden by any
   * extended operation handler which provides special support for one
   * or more controls.
   *
   * @return  The OIDs of the controls that may be supported by this
   *          extended operation handler.
   */
  public Set<String> getSupportedControls()
  {
    return supportedControlOIDs;
  }
 
 
 
  /**
   * Indicates whether this extended operation handler supports the
   * specified control.
   *
   * @param  controlOID  The OID of the control for which to make the
   *                     determination.
   *
   * @return  {@code true} if this extended operation handler does
   *          support the requested control, or {@code false} if not.
   */
  public final boolean supportsControl(String controlOID)
  {
    return getSupportedControls().contains(controlOID);
  }
 
 
 
  /**
   * Retrieves the OIDs of the features that may be supported by this
   * extended operation handler.
   *
   * @return  The OIDs of the features that may be supported by this
   *          extended operation handler.
   */
  public Set<String> getSupportedFeatures()
  {
    return supportedFeatureOIDs;
  }
 
 
 
  /**
   * Indicates whether this extended operation handler supports the
   * specified feature.
   *
   * @param  featureOID  The OID of the feature for which to make the
   *                     determination.
   *
   * @return  {@code true} if this extended operation handler does
   *          support the requested feature, or {@code false} if not.
   */
  public final boolean supportsFeature(String featureOID)
  {
    return getSupportedFeatures().contains(featureOID);
  }
 
 
 
  /**
   * If the extended operation handler defines any supported controls
   * and/or features, then register them with the server.
   */
  private void registerControlsAndFeatures()
  {
    Set<String> controlOIDs = getSupportedControls();
    if (controlOIDs != null)
    {
      for (String oid : controlOIDs)
      {
        DirectoryServer.registerSupportedControl(oid);
      }
    }
 
    Set<String> featureOIDs = getSupportedFeatures();
    if (featureOIDs != null)
    {
      for (String oid : featureOIDs)
      {
        DirectoryServer.registerSupportedFeature(oid);
      }
    }
  }
 
 
 
  /**
   * If the extended operation handler defines any supported controls
   * and/or features, then deregister them with the server.
   */
  private void deregisterControlsAndFeatures()
  {
    Set<String> controlOIDs = getSupportedControls();
    if (controlOIDs != null)
    {
      for (String oid : controlOIDs)
      {
        DirectoryServer.deregisterSupportedControl(oid);
      }
    }
 
    Set<String> featureOIDs = getSupportedFeatures();
    if (featureOIDs != null)
    {
      for (String oid : featureOIDs)
      {
        DirectoryServer.deregisterSupportedFeature(oid);
      }
    }
  }
 
  /**
   * Retrieves the name associated with this extended operation.
   *
   * @return  The name associated with this extended operation,
   *          if any, or <CODE>null</CODE> if there is none.
   */
  public String getExtendedOperationName()
  {
    return null;
  }
 
  /**
   * Retrieves the object OID associated with this extended operation.
   *
   * @return the oid associated with this extended operation, if any, or
   *         <CODE>null</CODE> if there is none.
   */
  public String getExtendedOperationOID()
  {
    return null;
  }
}