001/* 002 * Copyright 2014-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2014-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) 2014-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.controls; 037 038 039 040import com.unboundid.ldap.sdk.Control; 041import com.unboundid.ldap.sdk.JSONControlDecodeHelper; 042import com.unboundid.ldap.sdk.LDAPException; 043import com.unboundid.ldap.sdk.ResultCode; 044import com.unboundid.util.NotMutable; 045import com.unboundid.util.NotNull; 046import com.unboundid.util.ThreadSafety; 047import com.unboundid.util.ThreadSafetyLevel; 048import com.unboundid.util.json.JSONField; 049import com.unboundid.util.json.JSONObject; 050 051import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 052 053 054 055/** 056 * This class provides a request control which may be used to request that the 057 * Directory Proxy Server return the backend set IDs for the entry-balancing 058 * backend set(s) in which an operation was processed successfully. It may be 059 * used in conjunction with the route to backend set request control in order 060 * to specify which backend set(s) should be used to process an operation. 061 * <BR> 062 * <BLOCKQUOTE> 063 * <B>NOTE:</B> This class, and other classes within the 064 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 065 * supported for use against Ping Identity, UnboundID, and 066 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 067 * for proprietary functionality or for external specifications that are not 068 * considered stable or mature enough to be guaranteed to work in an 069 * interoperable way with other types of LDAP servers. 070 * </BLOCKQUOTE> 071 * <BR> 072 * This control may be used for a number of different kinds of requests, 073 * including: 074 * <UL> 075 * <LI>If an add request includes a get backend set ID request control, the 076 * add response will include a get backend set ID response control if the 077 * entry was successfully added to an entry-balanced data set.</LI> 078 * <LI>If a simple bind request includes a get backend set ID request control, 079 * the bind response will include a get backend set ID response control if 080 * the authentication was successful and the entry for the authenticated 081 * user exists in an entry-balanced data set. This control is currently 082 * not supported for use with SASL bind operations.</LI> 083 * <LI>If a compare request includes a get backend set ID request control, the 084 * compare response will include a get backend set ID response control if 085 * the result code is either COMPARE_TRUE or COMPARE_FALSE and the target 086 * entry exists in an entry-balanced data set.</LI> 087 * <LI>If a delete request includes a get backend set ID request control, the 088 * delete response will include a get backend set ID response control if 089 * the entry was successfully removed from an entry-balanced data 090 * set.</LI> 091 * <LI>If an atomic multi-update extended request includes a get backend set 092 * ID request control and the request is successfully processed through an 093 * entry-balancing request processor, then the extended response will 094 * include a get backend set ID response control. A non-atomic 095 * multi-update extended request should not include the get backend set ID 096 * request control in the extended operation itself, but may be attached 097 * to any or all of the requests inside the multi-update operation, in 098 * which case the server will return a multi-update response control 099 * attached to the corresponding successful responses.</LI> 100 * <LI>If an extended request includes a get backend set ID request control 101 * and that request is successfully processed by a proxied extended 102 * operation handler, then the extended response will include a get 103 * backend set ID response control indicating the backend set(s) that 104 * returned a success result during internal processing. Note that if the 105 * same extended request was processed by multiple entry-balancing 106 * request processors (i.e., if the deployment includes multiple 107 * entry-balanced subtrees), then the extended response may include a 108 * separate get backend set ID response control for each entry-balancing 109 * request processor used to process the request.</LI> 110 * <LI>If a modify request includes a get backend set ID request control, the 111 * modify response will include a get backend set ID response control if 112 * the entry was successfully modified in an entry-balanced data set.</LI> 113 * <LI>If a modify DN request includes a get backend set ID request control, 114 * the modify DN response will include a get backend set ID response 115 * control if the entry was successfully moved and/or renamed in an 116 * entry-balanced data set.</LI> 117 * <LI>If a modify DN request includes a get backend set ID request control, 118 * the modify DN response will include a get backend set ID response 119 * control if the entry was successfully moved and/or renamed in an 120 * entry-balanced data set.</LI> 121 * <LI>If a search request includes a get backend set ID request control, any 122 * search result entries retrieved from an entry-balanced data set will 123 * include a get backend set ID response control. The search result done 124 * message will not include a get backend set ID response control.</LI> 125 * </UL> 126 * 127 * Note the response for any operation involving an entry that exists outside of 128 * an entry-balanced dat set will not include a get backend set ID response 129 * control. Similarly, the response for any non-successful operation may not 130 * include a get backend set ID response control even if it involved processing 131 * in one or more backend sets. Also note that even if an entry exists in 132 * multiple backend sets (i.e., because it is at or above the balancing point), 133 * the get backend set ID response control may only include one backend set ID 134 * if only one backend set was accessed during the course of processing the 135 * operation. 136 * <BR><BR> 137 * The get backend set ID request control has an OID of 138 * "1.3.6.1.4.1.30221.2.5.33" and no value. It is recommended that the control 139 * be non-critical so that the associated operation may still be processed even 140 * if the target server does not support this control (and note that even if 141 * the server supports the control, the server may not return a response control 142 * if the operation was not successful or did not access entry-balanced data). 143 * 144 * @see GetBackendSetIDResponseControl 145 * @see RouteToBackendSetRequestControl 146 */ 147@NotMutable() 148@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 149public final class GetBackendSetIDRequestControl 150 extends Control 151{ 152 /** 153 * The OID (1.3.6.1.4.1.30221.2.5.33) for the get backend set ID request 154 * control. 155 */ 156 @NotNull public static final String GET_BACKEND_SET_ID_REQUEST_OID = 157 "1.3.6.1.4.1.30221.2.5.33"; 158 159 160 161 /** 162 * The serial version UID for this serializable class. 163 */ 164 private static final long serialVersionUID = 7874405591825684773L; 165 166 167 168 /** 169 * Creates a new get backend set ID request control. It will not be marked 170 * critical. 171 */ 172 public GetBackendSetIDRequestControl() 173 { 174 this(false); 175 } 176 177 178 179 /** 180 * Creates a new get backend set ID request control with the specified 181 * criticality. 182 * 183 * @param isCritical Indicates whether this control should be marked 184 * critical. 185 */ 186 public GetBackendSetIDRequestControl(final boolean isCritical) 187 { 188 super(GET_BACKEND_SET_ID_REQUEST_OID, isCritical, null); 189 } 190 191 192 193 /** 194 * Creates a new get backend set ID request control which is decoded from the 195 * provided generic control. 196 * 197 * @param control The generic control to be decoded as a get backend set ID 198 * request control. 199 * 200 * @throws LDAPException If the provided control cannot be decoded as a get 201 * backend set ID request control. 202 */ 203 public GetBackendSetIDRequestControl(@NotNull final Control control) 204 throws LDAPException 205 { 206 super(control); 207 208 if (control.hasValue()) 209 { 210 throw new LDAPException(ResultCode.DECODING_ERROR, 211 ERR_GET_BACKEND_SET_ID_REQUEST_HAS_VALUE.get()); 212 } 213 } 214 215 216 217 /** 218 * {@inheritDoc} 219 */ 220 @Override() 221 @NotNull() 222 public String getControlName() 223 { 224 return INFO_CONTROL_NAME_GET_BACKEND_SET_ID_REQUEST.get(); 225 } 226 227 228 229 /** 230 * Retrieves a representation of this get backend set ID request control as a 231 * JSON object. The JSON object uses the following fields (note that since 232 * this control does not have a value, neither the {@code value-base64} nor 233 * {@code value-json} fields may be present): 234 * <UL> 235 * <LI> 236 * {@code oid} -- A mandatory string field whose value is the object 237 * identifier for this control. For the get backend set ID request 238 * control, the OID is "1.3.6.1.4.1.30221.2.5.33". 239 * </LI> 240 * <LI> 241 * {@code control-name} -- An optional string field whose value is a 242 * human-readable name for this control. This field is only intended for 243 * descriptive purposes, and when decoding a control, the {@code oid} 244 * field should be used to identify the type of control. 245 * </LI> 246 * <LI> 247 * {@code criticality} -- A mandatory Boolean field used to indicate 248 * whether this control is considered critical. 249 * </LI> 250 * </UL> 251 * 252 * @return A JSON object that contains a representation of this control. 253 */ 254 @Override() 255 @NotNull() 256 public JSONObject toJSONControl() 257 { 258 return new JSONObject( 259 new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID, 260 GET_BACKEND_SET_ID_REQUEST_OID), 261 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME, 262 INFO_CONTROL_NAME_GET_BACKEND_SET_ID_REQUEST.get()), 263 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY, 264 isCritical())); 265 } 266 267 268 269 /** 270 * Attempts to decode the provided object as a JSON representation of a get 271 * backend set ID request control. 272 * 273 * @param controlObject The JSON object to be decoded. It must not be 274 * {@code null}. 275 * @param strict Indicates whether to use strict mode when decoding 276 * the provided JSON object. If this is {@code true}, 277 * then this method will throw an exception if the 278 * provided JSON object contains any unrecognized 279 * fields. If this is {@code false}, then unrecognized 280 * fields will be ignored. 281 * 282 * @return The get backend set ID request control that was decoded from 283 * the provided JSON object. 284 * 285 * @throws LDAPException If the provided JSON object cannot be parsed as a 286 * valid get backend set ID request control. 287 */ 288 @NotNull() 289 public static GetBackendSetIDRequestControl decodeJSONControl( 290 @NotNull final JSONObject controlObject, 291 final boolean strict) 292 throws LDAPException 293 { 294 final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper( 295 controlObject, strict, false, false); 296 297 return new GetBackendSetIDRequestControl(jsonControl.getCriticality()); 298 } 299 300 301 302 /** 303 * {@inheritDoc} 304 */ 305 @Override() 306 public void toString(@NotNull final StringBuilder buffer) 307 { 308 buffer.append("GetBackendSetIDRequestControl(isCritical="); 309 buffer.append(isCritical()); 310 buffer.append(')'); 311 } 312}