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