001/* 002 * Copyright 2007-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2007-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) 2007-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; 037 038 039 040import com.unboundid.asn1.ASN1Integer; 041import com.unboundid.util.Extensible; 042import com.unboundid.util.NotNull; 043import com.unboundid.util.Nullable; 044import com.unboundid.util.ThreadSafety; 045import com.unboundid.util.ThreadSafetyLevel; 046 047 048 049/** 050 * This class provides an API that is used to represent an LDAP bind request. 051 * It should be extended by subclasses that provide the logic for processing 052 * specific types of bind operations (e.g., simple binds, and the various SASL 053 * mechanisms). 054 * <BR><BR> 055 * It is strongly recommended that all bind request types which implement the 056 * rebind capability be made immutable. If this is not done, then changes made 057 * to a bind request object may alter the authentication/authorization identity 058 * and/or credentials associated with that request so that a rebind request 059 * created from it will not match the original request used to authenticate on a 060 * connection. Note, however, that it is not threadsafe to use the same 061 * {@code BindRequest} object to attempt to bind concurrently over multiple 062 * connections. 063 * <BR><BR> 064 * Note that even though this class is marked with the @Extensible annotation 065 * type, it should not be directly subclassed by third-party code. Only the 066 * {@link SASLBindRequest} subclass is actually intended to be extended by 067 * third-party code. 068 */ 069@Extensible() 070@ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE) 071public abstract class BindRequest 072 extends LDAPRequest 073{ 074 /** 075 * The pre-encoded ASN.1 element used to represent the protocol version. 076 */ 077 @NotNull protected static final ASN1Integer VERSION_ELEMENT = 078 new ASN1Integer(3); 079 080 081 082 /** 083 * The serial version UID for this serializable class. 084 */ 085 private static final long serialVersionUID = -1509925217235385907L; 086 087 088 089 /** 090 * Creates a new bind request with the provided set of controls. 091 * 092 * @param controls The set of controls to include in this bind request. 093 */ 094 protected BindRequest(@Nullable final Control[] controls) 095 { 096 super(controls); 097 } 098 099 100 101 /** 102 * Sends this bind request to the target server over the provided connection 103 * and returns the corresponding response. 104 * 105 * @param connection The connection to use to send this bind request to the 106 * server and read the associated response. 107 * @param depth The current referral depth for this request. It should 108 * always be one for the initial request, and should only 109 * be incremented when following referrals. 110 * 111 * @return The bind response read from the server. 112 * 113 * @throws LDAPException If a problem occurs while sending the request or 114 * reading the response. 115 */ 116 @Override() 117 @NotNull() 118 protected abstract BindResult process(@NotNull LDAPConnection connection, 119 int depth) 120 throws LDAPException; 121 122 123 124 /** 125 * {@inheritDoc} 126 */ 127 @Override() 128 @NotNull() 129 public final OperationType getOperationType() 130 { 131 return OperationType.BIND; 132 } 133 134 135 136 /** 137 * Retrieves a human-readable string that describes the type of bind request. 138 * 139 * @return A human-readable string that describes the type of bind request. 140 */ 141 @NotNull() 142 public abstract String getBindType(); 143 144 145 146 /** 147 * {@inheritDoc} 148 */ 149 @Override() 150 @NotNull() 151 public abstract BindRequest duplicate(); 152 153 154 155 /** 156 * {@inheritDoc} 157 */ 158 @Override() 159 @NotNull() 160 public abstract BindRequest duplicate(@Nullable Control[] controls); 161 162 163 164 /** 165 * Retrieves a bind request that may be used to re-bind using the same 166 * credentials authentication type and credentials as previously used to 167 * perform the initial bind. This may be used in an attempt to automatically 168 * re-establish a connection that is lost, or potentially when following a 169 * referral to another directory instance. 170 * <BR><BR> 171 * It is recommended that all bind request types which implement this 172 * capability be implemented so that the elements needed to create a new 173 * request are immutable. If this is not done, then changes made to a bind 174 * request object may alter the authentication/authorization identity and/or 175 * credentials associated with that request so that a rebind request created 176 * from it will not match the original request used to authenticate on a 177 * connection. 178 * 179 * @param host The address of the directory server to which the connection 180 * is established. 181 * @param port The port of the directory server to which the connection is 182 * established. 183 * 184 * @return A bind request that may be used to re-bind using the same 185 * authentication type and credentials as previously used to perform 186 * the initial bind, or {@code null} to indicate that automatic 187 * re-binding is not supported for this type of bind request. 188 */ 189 @Nullable() 190 public BindRequest getRebindRequest(@NotNull final String host, 191 final int port) 192 { 193 return null; 194 } 195}