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     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
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     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  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 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.core;
028    
029    
030    import java.util.ArrayList;
031    import java.util.List;
032    
033    import org.opends.server.api.ClientConnection;
034    import org.opends.server.loggers.debug.DebugLogger;
035    import org.opends.server.loggers.debug.DebugTracer;
036    import org.opends.server.types.*;
037    import org.opends.server.types.operation.PostOperationUnbindOperation;
038    import org.opends.server.types.operation.PreParseUnbindOperation;
039    
040    import static org.opends.server.loggers.AccessLogger.*;
041    import static org.opends.messages.CoreMessages.*;
042    /**
043     * This class defines an operation that may be used to close the connection
044     * between the client and the Directory Server.
045     */
046    public class UnbindOperationBasis
047           extends AbstractOperation
048           implements UnbindOperation,
049                      PreParseUnbindOperation,
050                      PostOperationUnbindOperation
051    {
052    
053      /**
054       * The tracer object for the debug logger.
055       */
056      private static final DebugTracer TRACER = DebugLogger.getTracer();
057    
058      /**
059       * Creates a new unbind operation with the provided information.
060       *
061       * @param  clientConnection  The client connection with which this operation
062       *                           is associated.
063       * @param  operationID       The operation ID for this operation.
064       * @param  messageID         The message ID of the request with which this
065       *                           operation is associated.
066       * @param  requestControls   The set of controls included in the request.
067       */
068      public UnbindOperationBasis(ClientConnection clientConnection,
069                             long operationID,
070                             int messageID, ArrayList<Control> requestControls)
071      {
072        super(clientConnection, operationID, messageID, requestControls);
073    
074        cancelResult = new CancelResult(ResultCode.CANNOT_CANCEL,
075            ERR_CANNOT_CANCEL_UNBIND.get());
076      }
077    
078    
079    
080      /**
081       * {@inheritDoc}
082       */
083      @Override()
084      public final OperationType getOperationType()
085      {
086        // Note that no debugging will be done in this method because it is a likely
087        // candidate for being called by the logging subsystem.
088    
089        return OperationType.UNBIND;
090      }
091    
092    
093    
094      /**
095       * {@inheritDoc}
096       */
097      @Override()
098      public final String[][] getRequestLogElements()
099      {
100        // Note that no debugging will be done in this method because it is a likely
101        // candidate for being called by the logging subsystem.
102    
103        // There are no special elements that should be logged for an unbind
104        // request.
105        return new String[0][];
106      }
107    
108    
109    
110      /**
111       * {@inheritDoc}
112       */
113      @Override()
114      public final String[][] getResponseLogElements()
115      {
116        // Note that no debugging will be done in this method because it is a likely
117        // candidate for being called by the logging subsystem.
118    
119        // There is no unbind response, nor are there any special elements that
120        // should be logged when an unbind occurs.
121        return new String[0][];
122      }
123    
124    
125    
126      /**
127       * {@inheritDoc}
128       */
129      @Override()
130      public final List<Control> getResponseControls()
131      {
132        // An unbind operation can never have a response, so just return an empty
133        // list.
134        return NO_RESPONSE_CONTROLS;
135      }
136    
137    
138    
139      /**
140       * {@inheritDoc}
141       */
142      @Override()
143      public final void addResponseControl(Control control)
144      {
145        // An unbind operation can never have a response, so just ignore this.
146      }
147    
148    
149    
150      /**
151       * {@inheritDoc}
152       */
153      @Override()
154      public final void removeResponseControl(Control control)
155      {
156        // An unbind operation can never have a response, so just ignore this.
157      }
158    
159      /**
160       * Performs the work of actually processing this operation.  This
161       * should include all processing for the operation, including
162       * invoking plugins, logging messages, performing access control,
163       * managing synchronization, and any other work that might need to
164       * be done in the course of processing.
165       */
166      public final void run()
167      {
168        // Get the plugin config manager that will be used for invoking plugins.
169        PluginConfigManager pluginConfigManager =
170             DirectoryServer.getPluginConfigManager();
171    
172        setProcessingStartTime();
173    
174    
175        // Invoke the pre-parse unbind plugins.  We don't care about the result
176        // since we're going to close the connection anyway.
177        pluginConfigManager.invokePreParseUnbindPlugins(this);
178    
179    
180        // Log the unbind request.
181        logUnbind(this);
182    
183    
184        // Check the set of controls included in the request.  If there are any,
185        // see if any special processing is needed.
186        // NYI
187    
188    
189        // Disconnect the client.
190        getClientConnection().disconnect(DisconnectReason.UNBIND, false, null);
191    
192    
193        // Invoke the post-operation unbind plugins.
194        pluginConfigManager.invokePostOperationUnbindPlugins(this);
195    
196        setProcessingStopTime();
197      }
198    
199    
200    
201      /**
202       * {@inheritDoc}
203       */
204      @Override()
205      public final void toString(StringBuilder buffer)
206      {
207        buffer.append("UnbindOperation(connID=");
208        buffer.append(clientConnection.getConnectionID());
209        buffer.append(", opID=");
210        buffer.append(operationID);
211        buffer.append(")");
212      }
213    
214    }
215