001/* 002 * Copyright 2008-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-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) 2008-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 the server 057 * ID of the server that actually processed the associated request. It may be 058 * used for requests sent directly to a Directory Server, but it is more useful 059 * when the request will pass through a Directory Proxy Server instance because 060 * the corresponding {@link GetServerIDResponseControl} will provide the server 061 * ID of the backend server used to process the request. This server ID may be 062 * used in a {@link RouteToServerRequestControl} instance to request that 063 * subsequent operations be processed by the same server. See the documentation 064 * for the {@code RouteToServerRequestControl} for an example that demonstrates 065 * this. 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 * <BR> 077 * This control does not have a value. The criticality may be either 078 * {@code true} or {@code false}. 079 */ 080@NotMutable() 081@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 082public final class GetServerIDRequestControl 083 extends Control 084{ 085 /** 086 * The OID (1.3.6.1.4.1.30221.2.5.14) for the get server ID request control. 087 */ 088 @NotNull public static final String GET_SERVER_ID_REQUEST_OID = 089 "1.3.6.1.4.1.30221.2.5.14"; 090 091 092 /** 093 * The serial version UID for this serializable class. 094 */ 095 private static final long serialVersionUID = -6015835755174298354L; 096 097 098 099 /** 100 * Creates a new get server ID request control. It will not be marked 101 * critical. 102 */ 103 public GetServerIDRequestControl() 104 { 105 this(false); 106 } 107 108 109 110 /** 111 * Creates a new get server ID request control with the specified 112 * criticality. 113 * 114 * @param isCritical Indicates whether this control should be marked 115 * critical. 116 */ 117 public GetServerIDRequestControl(final boolean isCritical) 118 { 119 super(GET_SERVER_ID_REQUEST_OID, isCritical, null); 120 } 121 122 123 124 /** 125 * Creates a new get server ID request control which is decoded from the 126 * provided generic control. 127 * 128 * @param control The generic control to be decoded as a get server ID 129 * request control. 130 * 131 * @throws LDAPException If the provided control cannot be decoded as a get 132 * server ID request control. 133 */ 134 public GetServerIDRequestControl(@NotNull final Control control) 135 throws LDAPException 136 { 137 super(control); 138 139 if (control.hasValue()) 140 { 141 throw new LDAPException(ResultCode.DECODING_ERROR, 142 ERR_GET_SERVER_ID_REQUEST_HAS_VALUE.get()); 143 } 144 } 145 146 147 148 /** 149 * {@inheritDoc} 150 */ 151 @Override() 152 @NotNull() 153 public String getControlName() 154 { 155 return INFO_CONTROL_NAME_GET_SERVER_ID_REQUEST.get(); 156 } 157 158 159 160 /** 161 * Retrieves a representation of this get server ID request control as a JSON 162 * object. The JSON object uses the following fields (note that since this 163 * control does not have a value, neither the {@code value-base64} nor 164 * {@code value-json} fields may be present): 165 * <UL> 166 * <LI> 167 * {@code oid} -- A mandatory string field whose value is the object 168 * identifier for this control. For the get server ID request control, 169 * the OID is "1.3.6.1.4.1.30221.2.5.14". 170 * </LI> 171 * <LI> 172 * {@code control-name} -- An optional string field whose value is a 173 * human-readable name for this control. This field is only intended for 174 * descriptive purposes, and when decoding a control, the {@code oid} 175 * field should be used to identify the type of control. 176 * </LI> 177 * <LI> 178 * {@code criticality} -- A mandatory Boolean field used to indicate 179 * whether this control is considered critical. 180 * </LI> 181 * </UL> 182 * 183 * @return A JSON object that contains a representation of this control. 184 */ 185 @Override() 186 @NotNull() 187 public JSONObject toJSONControl() 188 { 189 return new JSONObject( 190 new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID, 191 GET_SERVER_ID_REQUEST_OID), 192 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME, 193 INFO_CONTROL_NAME_GET_SERVER_ID_REQUEST.get()), 194 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY, 195 isCritical())); 196 } 197 198 199 200 /** 201 * Attempts to decode the provided object as a JSON representation of a get 202 * server ID request control. 203 * 204 * @param controlObject The JSON object to be decoded. It must not be 205 * {@code null}. 206 * @param strict Indicates whether to use strict mode when decoding 207 * the provided JSON object. If this is {@code true}, 208 * then this method will throw an exception if the 209 * provided JSON object contains any unrecognized 210 * fields. If this is {@code false}, then unrecognized 211 * fields will be ignored. 212 * 213 * @return The get server ID request control that was decoded from the 214 * provided JSON object. 215 * 216 * @throws LDAPException If the provided JSON object cannot be parsed as a 217 * valid get server ID request control. 218 */ 219 @NotNull() 220 public static GetServerIDRequestControl decodeJSONControl( 221 @NotNull final JSONObject controlObject, 222 final boolean strict) 223 throws LDAPException 224 { 225 final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper( 226 controlObject, strict, false, false); 227 228 return new GetServerIDRequestControl( 229 jsonControl.getCriticality()); 230 } 231 232 233 234 /** 235 * {@inheritDoc} 236 */ 237 @Override() 238 public void toString(@NotNull final StringBuilder buffer) 239 { 240 buffer.append("GetServerIDRequestControl(isCritical="); 241 buffer.append(isCritical()); 242 buffer.append(')'); 243 } 244}