001/*
002 * Copyright 2015-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.extensions;
022
023
024
025import java.io.Serializable;
026
027import com.unboundid.ldap.sdk.ExtendedResult;
028import com.unboundid.ldap.sdk.LDAPConnection;
029import com.unboundid.ldap.sdk.LDAPException;
030import com.unboundid.ldap.sdk.LDAPExtendedOperationException;
031import com.unboundid.ldap.sdk.PostConnectProcessor;
032import com.unboundid.ldap.sdk.ResultCode;
033import com.unboundid.util.ThreadSafety;
034import com.unboundid.util.ThreadSafetyLevel;
035
036
037
038/**
039 * This class provides an implementation of a post-connect processor that can be
040 * used to start an administrative session on a connection that is meant to be
041 * part of a connection pool.  If this is to be used in conjunction with other
042 * post-connect processors (via the
043 * {@link com.unboundid.ldap.sdk.AggregatePostConnectProcessor}), then the
044 * start administrative session processor should generally be invoked first
045 * (even before the
046 * {@link com.unboundid.ldap.sdk.StartTLSPostConnectProcessor}) to ensure that
047 * any interaction with the server will be able to make use of the dedicated
048 * worker thread pool the server sets aside for operations using an
049 * administrative session.
050 * <BR>
051 * <BLOCKQUOTE>
052 *   <B>NOTE:</B>  This class, and other classes within the
053 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
054 *   supported for use against Ping Identity, UnboundID, and
055 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
056 *   for proprietary functionality or for external specifications that are not
057 *   considered stable or mature enough to be guaranteed to work in an
058 *   interoperable way with other types of LDAP servers.
059 * </BLOCKQUOTE>
060 */
061@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
062public final class StartAdministrativeSessionPostConnectProcessor
063       implements PostConnectProcessor, Serializable
064{
065  /**
066   * The serial version UID for this serializable class.
067   */
068  private static final long serialVersionUID = 3327980552475726214L;
069
070
071
072  // The start administrative session extended request to be invoked for
073  // newly-established connections.
074  private final StartAdministrativeSessionExtendedRequest request;
075
076
077
078  /**
079   * Creates a new start administrative session post-connect processor that will
080   * issue the provided extended request over a newly-established connection.
081   *
082   * @param  request  The start administrative session extended request to be
083   *                  invoked for newly-established connections.
084   */
085  public StartAdministrativeSessionPostConnectProcessor(
086              final StartAdministrativeSessionExtendedRequest request)
087  {
088    this.request = request;
089  }
090
091
092
093  /**
094   * {@inheritDoc}
095   */
096  @Override()
097  public void processPreAuthenticatedConnection(final LDAPConnection connection)
098         throws LDAPException
099  {
100    final ExtendedResult result =
101         connection.processExtendedOperation(request.duplicate());
102    if (result.getResultCode() != ResultCode.SUCCESS)
103    {
104      throw new LDAPExtendedOperationException(result);
105    }
106  }
107
108
109
110  /**
111   * {@inheritDoc}
112   */
113  @Override()
114  public void processPostAuthenticatedConnection(
115                   final LDAPConnection connection)
116         throws LDAPException
117  {
118    // No implementation is required.
119  }
120}