001/* 002 * Copyright 2009-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2009-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) 2009-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.asn1.ASN1OctetString; 041import com.unboundid.ldap.sdk.Control; 042import com.unboundid.ldap.sdk.DecodeableControl; 043import com.unboundid.ldap.sdk.JSONControlDecodeHelper; 044import com.unboundid.ldap.sdk.LDAPException; 045import com.unboundid.ldap.sdk.LDAPResult; 046import com.unboundid.ldap.sdk.ResultCode; 047import com.unboundid.util.NotMutable; 048import com.unboundid.util.NotNull; 049import com.unboundid.util.Nullable; 050import com.unboundid.util.ThreadSafety; 051import com.unboundid.util.ThreadSafetyLevel; 052import com.unboundid.util.json.JSONField; 053import com.unboundid.util.json.JSONObject; 054 055import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 056 057 058 059/** 060 * This class provides an implementation of the unsolicited cancel response 061 * control, which may be returned by the Directory Server if an operation is 062 * canceled by the server without a cancel or abandon request from the client. 063 * This control does not have a value. 064 * <BR> 065 * <BLOCKQUOTE> 066 * <B>NOTE:</B> This class, and other classes within the 067 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 068 * supported for use against Ping Identity, UnboundID, and 069 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 070 * for proprietary functionality or for external specifications that are not 071 * considered stable or mature enough to be guaranteed to work in an 072 * interoperable way with other types of LDAP servers. 073 * </BLOCKQUOTE> 074 */ 075@NotMutable() 076@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 077public final class UnsolicitedCancelResponseControl 078 extends Control 079 implements DecodeableControl 080{ 081 /** 082 * The OID (1.3.6.1.4.1.30221.2.5.7) for the unsolicited cancel response 083 * control. 084 */ 085 @NotNull public static final String UNSOLICITED_CANCEL_RESPONSE_OID = 086 "1.3.6.1.4.1.30221.2.5.7"; 087 088 089 090 /** 091 * The serial version UID for this serializable class. 092 */ 093 private static final long serialVersionUID = 36962888392922937L; 094 095 096 097 /** 098 * Creates a new unsolicited cancel response control. 099 */ 100 public UnsolicitedCancelResponseControl() 101 { 102 super(UNSOLICITED_CANCEL_RESPONSE_OID, false, null); 103 } 104 105 106 107 /** 108 * Creates a new account usable response control with the provided 109 * information. 110 * 111 * @param oid The OID for the control. 112 * @param isCritical Indicates whether the control should be marked 113 * critical. 114 * @param value The encoded value for the control. This may be 115 * {@code null} if no value was provided. 116 * 117 * @throws LDAPException If the provided control cannot be decoded as an 118 * account usable response control. 119 */ 120 public UnsolicitedCancelResponseControl(@NotNull final String oid, 121 final boolean isCritical, 122 @Nullable final ASN1OctetString value) 123 throws LDAPException 124 { 125 super(oid, isCritical, value); 126 127 if (value != null) 128 { 129 throw new LDAPException(ResultCode.DECODING_ERROR, 130 ERR_UNSOLICITED_CANCEL_RESPONSE_HAS_VALUE.get()); 131 } 132 } 133 134 135 136 /** 137 * {@inheritDoc} 138 */ 139 @Override() 140 @NotNull() 141 public UnsolicitedCancelResponseControl decodeControl( 142 @NotNull final String oid, 143 final boolean isCritical, 144 @Nullable final ASN1OctetString value) 145 throws LDAPException 146 { 147 return new UnsolicitedCancelResponseControl(oid, isCritical, value); 148 } 149 150 151 152 /** 153 * Extracts an unsolicited cancel response control from the provided result. 154 * 155 * @param result The result from which to retrieve the unsolicited cancel 156 * response control. 157 * 158 * @return The unsolicited cancel response control contained in the provided 159 * result, or {@code null} if the result did not contain an 160 * unsolicited cancel response control. 161 * 162 * @throws LDAPException If a problem is encountered while attempting to 163 * decode the unsolicited cancel response control 164 * contained in the provided result. 165 */ 166 @Nullable() 167 public static UnsolicitedCancelResponseControl get( 168 @NotNull final LDAPResult result) 169 throws LDAPException 170 { 171 final Control c = 172 result.getResponseControl(UNSOLICITED_CANCEL_RESPONSE_OID); 173 if (c == null) 174 { 175 return null; 176 } 177 178 if (c instanceof UnsolicitedCancelResponseControl) 179 { 180 return (UnsolicitedCancelResponseControl) c; 181 } 182 else 183 { 184 return new UnsolicitedCancelResponseControl(c.getOID(), c.isCritical(), 185 c.getValue()); 186 } 187 } 188 189 190 191 /** 192 * {@inheritDoc} 193 */ 194 @Override() 195 @NotNull() 196 public String getControlName() 197 { 198 return INFO_CONTROL_NAME_UNSOLICITED_CANCEL_RESPONSE.get(); 199 } 200 201 202 203 /** 204 * Retrieves a representation of this unsolicited cancel response control as a 205 * JSON object. The JSON object uses the following fields (note that since 206 * this control does not have a value, neither the {@code value-base64} nor 207 * {@code value-json} fields may be present): 208 * <UL> 209 * <LI> 210 * {@code oid} -- A mandatory string field whose value is the object 211 * identifier for this control. For the unsolicited cancel response 212 * control, the OID is "1.3.6.1.4.1.30221.2.5.7". 213 * </LI> 214 * <LI> 215 * {@code control-name} -- An optional string field whose value is a 216 * human-readable name for this control. This field is only intended for 217 * descriptive purposes, and when decoding a control, the {@code oid} 218 * field should be used to identify the type of control. 219 * </LI> 220 * <LI> 221 * {@code criticality} -- A mandatory Boolean field used to indicate 222 * whether this control is considered critical. 223 * </LI> 224 * </UL> 225 * 226 * @return A JSON object that contains a representation of this control. 227 */ 228 @Override() 229 @NotNull() 230 public JSONObject toJSONControl() 231 { 232 return new JSONObject( 233 new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID, 234 UNSOLICITED_CANCEL_RESPONSE_OID), 235 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME, 236 INFO_CONTROL_NAME_UNSOLICITED_CANCEL_RESPONSE.get()), 237 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY, 238 isCritical())); 239 } 240 241 242 243 /** 244 * Attempts to decode the provided object as a JSON representation of an 245 * unsolicited cancel response control. 246 * 247 * @param controlObject The JSON object to be decoded. It must not be 248 * {@code null}. 249 * @param strict Indicates whether to use strict mode when decoding 250 * the provided JSON object. If this is {@code true}, 251 * then this method will throw an exception if the 252 * provided JSON object contains any unrecognized 253 * fields. If this is {@code false}, then unrecognized 254 * fields will be ignored. 255 * 256 * @return The unsolicited cancel response control that was decoded from 257 * the provided JSON object. 258 * 259 * @throws LDAPException If the provided JSON object cannot be parsed as a 260 * valid unsolicited cancel response control. 261 */ 262 @NotNull() 263 public static UnsolicitedCancelResponseControl decodeJSONControl( 264 @NotNull final JSONObject controlObject, 265 final boolean strict) 266 throws LDAPException 267 { 268 final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper( 269 controlObject, strict, false, false); 270 271 return new UnsolicitedCancelResponseControl(); 272 } 273 274 275 276 /** 277 * {@inheritDoc} 278 */ 279 @Override() 280 public void toString(@NotNull final StringBuilder buffer) 281 { 282 buffer.append("UnsolicitedCancelResponseControl()"); 283 } 284}