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