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