001/* 002 * Copyright 2015-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2015-2024 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-2024 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.NotNull; 049import com.unboundid.util.ThreadSafety; 050import com.unboundid.util.ThreadSafetyLevel; 051 052 053 054/** 055 * This class provides an implementation of a post-connect processor that can be 056 * used to start an administrative session on a connection that is meant to be 057 * part of a connection pool. If this is to be used in conjunction with other 058 * post-connect processors (via the 059 * {@link com.unboundid.ldap.sdk.AggregatePostConnectProcessor}), then the 060 * start administrative session processor should generally be invoked first 061 * (even before the 062 * {@link com.unboundid.ldap.sdk.StartTLSPostConnectProcessor}) to ensure that 063 * any interaction with the server will be able to make use of the dedicated 064 * worker thread pool the server sets aside for operations using an 065 * administrative session. 066 * <BR> 067 * <BLOCKQUOTE> 068 * <B>NOTE:</B> This class, and other classes within the 069 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 070 * supported for use against Ping Identity, UnboundID, and 071 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 072 * for proprietary functionality or for external specifications that are not 073 * considered stable or mature enough to be guaranteed to work in an 074 * interoperable way with other types of LDAP servers. 075 * </BLOCKQUOTE> 076 */ 077@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 078public final class StartAdministrativeSessionPostConnectProcessor 079 implements PostConnectProcessor, Serializable 080{ 081 /** 082 * The serial version UID for this serializable class. 083 */ 084 private static final long serialVersionUID = 3327980552475726214L; 085 086 087 088 // The start administrative session extended request to be invoked for 089 // newly-established connections. 090 @NotNull private final StartAdministrativeSessionExtendedRequest request; 091 092 093 094 /** 095 * Creates a new start administrative session post-connect processor that will 096 * issue the provided extended request over a newly-established connection. 097 * 098 * @param request The start administrative session extended request to be 099 * invoked for newly-established connections. 100 */ 101 public StartAdministrativeSessionPostConnectProcessor( 102 @NotNull final StartAdministrativeSessionExtendedRequest request) 103 { 104 this.request = request; 105 } 106 107 108 109 /** 110 * {@inheritDoc} 111 */ 112 @Override() 113 public void processPreAuthenticatedConnection( 114 @NotNull final LDAPConnection connection) 115 throws LDAPException 116 { 117 final ExtendedResult result = 118 connection.processExtendedOperation(request.duplicate()); 119 if (result.getResultCode() != ResultCode.SUCCESS) 120 { 121 throw new LDAPExtendedOperationException(result); 122 } 123 } 124 125 126 127 /** 128 * {@inheritDoc} 129 */ 130 @Override() 131 public void processPostAuthenticatedConnection( 132 @NotNull final LDAPConnection connection) 133 throws LDAPException 134 { 135 // No implementation is required. 136 } 137}