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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2013-2015 ForgeRock AS
026 */
027package org.opends.server.core;
028
029import static org.opends.messages.CoreMessages.*;
030import static org.opends.server.core.DirectoryServer.*;
031import static org.opends.server.loggers.AccessLogger.*;
032
033import java.util.List;
034
035import org.forgerock.i18n.slf4j.LocalizedLogger;
036import org.forgerock.opendj.ldap.ResultCode;
037import org.opends.server.api.ClientConnection;
038import org.opends.server.types.*;
039import org.opends.server.types.operation.PostOperationUnbindOperation;
040import org.opends.server.types.operation.PreParseUnbindOperation;
041
042/**
043 * This class defines an operation that may be used to close the connection
044 * between the client and the Directory Server.
045 */
046public class UnbindOperationBasis
047       extends AbstractOperation
048       implements UnbindOperation,
049                  PreParseUnbindOperation,
050                  PostOperationUnbindOperation
051{
052  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
053
054  /**
055   * Creates a new unbind operation with the provided information.
056   *
057   * @param  clientConnection  The client connection with which this operation
058   *                           is associated.
059   * @param  operationID       The operation ID for this operation.
060   * @param  messageID         The message ID of the request with which this
061   *                           operation is associated.
062   * @param  requestControls   The set of controls included in the request.
063   */
064  public UnbindOperationBasis(ClientConnection clientConnection,
065                         long operationID,
066                         int messageID, List<Control> requestControls)
067  {
068    super(clientConnection, operationID, messageID, requestControls);
069
070    cancelResult = new CancelResult(ResultCode.CANNOT_CANCEL,
071        ERR_CANNOT_CANCEL_UNBIND.get());
072  }
073
074  /** {@inheritDoc} */
075  @Override
076  public final OperationType getOperationType()
077  {
078    // Note that no debugging will be done in this method because it is a likely
079    // candidate for being called by the logging subsystem.
080    return OperationType.UNBIND;
081  }
082
083  /** {@inheritDoc} */
084  @Override
085  public DN getProxiedAuthorizationDN()
086  {
087    return null;
088  }
089
090  /** {@inheritDoc} */
091  @Override
092  public void setProxiedAuthorizationDN(DN proxiedAuthorizationDN)
093  {
094  }
095
096  /** {@inheritDoc} */
097  @Override
098  public final List<Control> getResponseControls()
099  {
100    // An unbind operation can never have a response, so just return an empty
101    // list.
102    return NO_RESPONSE_CONTROLS;
103  }
104
105  /** {@inheritDoc} */
106  @Override
107  public final void addResponseControl(Control control)
108  {
109    // An unbind operation can never have a response, so just ignore this.
110  }
111
112  /** {@inheritDoc} */
113  @Override
114  public final void removeResponseControl(Control control)
115  {
116    // An unbind operation can never have a response, so just ignore this.
117  }
118
119  /**
120   * Performs the work of actually processing this operation.  This
121   * should include all processing for the operation, including
122   * invoking plugins, logging messages, performing access control,
123   * managing synchronization, and any other work that might need to
124   * be done in the course of processing.
125   */
126  @Override
127  public final void run()
128  {
129    setProcessingStartTime();
130
131    // Invoke the pre-parse unbind plugins.  We don't care about the result
132    // since we're going to close the connection anyway.
133    getPluginConfigManager().invokePreParseUnbindPlugins(this);
134
135    logUnbind(this);
136
137
138    // Check the set of controls included in the request.  If there are any,
139    // see if any special processing is needed.
140    // NYI
141
142
143    // Disconnect the client.
144    getClientConnection().disconnect(DisconnectReason.UNBIND, false, null);
145
146
147    // Invoke the post-operation unbind plugins.
148    getPluginConfigManager().invokePostOperationUnbindPlugins(this);
149
150    setProcessingStopTime();
151  }
152
153  /** {@inheritDoc} */
154  @Override
155  public final void toString(StringBuilder buffer)
156  {
157    buffer.append("UnbindOperation(connID=");
158    buffer.append(clientConnection.getConnectionID());
159    buffer.append(", opID=");
160    buffer.append(operationID);
161    buffer.append(")");
162  }
163
164}
165