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