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.experimental; 037 038 039 040import com.unboundid.ldap.sdk.Control; 041import com.unboundid.ldap.sdk.LDAPException; 042import com.unboundid.ldap.sdk.ResultCode; 043import com.unboundid.util.NotMutable; 044import com.unboundid.util.NotNull; 045import com.unboundid.util.ThreadSafety; 046import com.unboundid.util.ThreadSafetyLevel; 047 048import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*; 049 050 051 052/** 053 * This class provides an implementation of the LDAP no-op control as defined in 054 * draft-zeilenga-ldap-noop-12. This control may be included in an add, delete, 055 * modify, or modify DN request to indicate that the server should validate the 056 * request but not actually make any changes to the data. It allows the client 057 * to verify that the operation would likely succeed (including schema 058 * validation, access control checks, and other processing) without making any 059 * changes to the server data. 060 * <BR><BR> 061 * Note that an operation which includes the no-op control will never have a 062 * {@link ResultCode#SUCCESS} result. Instead, if the operation would likely 063 * have completed successfully if the no-op control had not been included, then 064 * the server will include a response with the {@link ResultCode#NO_OPERATION} 065 * result. If the operation would not have been successful, then the result 066 * code in the response will be the appropriate result code for that failure. 067 * Note that if the response from the server includes the 068 * {@link ResultCode#NO_OPERATION} result, then the LDAP SDK will not throw an 069 * exception but will instead return the response in an 070 * {@link com.unboundid.ldap.sdk.LDAPResult} object. There is no corresponding 071 * response control. 072 * <BR><BR> 073 * Note that at the time this control was written, the latest version of the 074 * specification may be found in draft-zeilenga-ldap-noop-11. This version of 075 * the document does not explicitly specify either the OID that should be used 076 * for the control, or the result code that should be used for the associated 077 * operation if all other processing is completed successfully but no changes 078 * are made as a result of this control. Until such time as these are defined, 079 * this implementation uses the OID temporarily assigned for its use by the 080 * OpenLDAP Foundation, which is used by at least the OpenLDAP, OpenDS, and the 081 * Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 Directory Server 082 * implementations. 083 * <BR><BR> 084 * <H2>Example</H2> 085 * The following example demonstrates the process for attempting to perform a 086 * modify operation including the LDAP no-op control so that the change is not 087 * actually applied: 088 * <PRE> 089 * ModifyRequest modifyRequest = new ModifyRequest("dc=example,dc=com", 090 * new Modification(ModificationType.REPLACE, "description", 091 * "new value")); 092 * modifyRequest.addControl(new DraftZeilengaLDAPNoOp12RequestControl()); 093 * 094 * try 095 * { 096 * LDAPResult result = connection.modify(modifyRequest); 097 * if (result.getResultCode() == ResultCode.NO_OPERATION) 098 * { 099 * // The modification would likely have succeeded if the no-op control 100 * // hadn't been included in the request. 101 * } 102 * else 103 * { 104 * // The modification would likely have failed if the no-op control 105 * // hadn't been included in the request. 106 * } 107 * } 108 * catch (LDAPException le) 109 * { 110 * // The modification failed even with the no-op control in the request. 111 * } 112 * </PRE> 113 */ 114@NotMutable() 115@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 116public final class DraftZeilengaLDAPNoOp12RequestControl 117 extends Control 118{ 119 /** 120 * The OID (1.3.6.1.4.1.4203.1.10.2) for the LDAP no-op request control. 121 */ 122 @NotNull public static final String NO_OP_REQUEST_OID = 123 "1.3.6.1.4.1.4203.1.10.2"; 124 125 126 127 /** 128 * The serial version UID for this serializable class. 129 */ 130 private static final long serialVersionUID = -7435407787971958294L; 131 132 133 134 /** 135 * Creates a new no-op request control. It will be marked critical, as 136 * required by the control specification. 137 */ 138 public DraftZeilengaLDAPNoOp12RequestControl() 139 { 140 super(NO_OP_REQUEST_OID, true, null); 141 } 142 143 144 145 /** 146 * Creates a new no-op request control which is decoded from the provided 147 * generic control. 148 * 149 * @param control The generic control to be decoded as a no-op request 150 * control. 151 * 152 * @throws LDAPException If the provided control cannot be decoded as a 153 * no-op request control. 154 */ 155 public DraftZeilengaLDAPNoOp12RequestControl(@NotNull final Control control) 156 throws LDAPException 157 { 158 super(control); 159 160 if (control.hasValue()) 161 { 162 throw new LDAPException(ResultCode.DECODING_ERROR, 163 ERR_NOOP_REQUEST_HAS_VALUE.get()); 164 } 165 } 166 167 168 169 /** 170 * {@inheritDoc} 171 */ 172 @Override() 173 @NotNull() 174 public String getControlName() 175 { 176 return INFO_CONTROL_NAME_NOOP_REQUEST.get(); 177 } 178 179 180 181 /** 182 * {@inheritDoc} 183 */ 184 @Override() 185 public void toString(@NotNull final StringBuilder buffer) 186 { 187 buffer.append("NoOpRequestControl(isCritical="); 188 buffer.append(isCritical()); 189 buffer.append(')'); 190 } 191}