001/* 002 * Copyright 2007-2022 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2007-2022 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-2022 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.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.NotNull; 045import com.unboundid.util.ThreadSafety; 046import com.unboundid.util.ThreadSafetyLevel; 047 048import static com.unboundid.ldap.sdk.controls.ControlMessages.*; 049 050 051 052/** 053 * This class provides an implementation of the ManageDsaIT control as described 054 * in <A HREF="http://www.ietf.org/rfc/rfc3296.txt">RFC 3296</A>. This control 055 * may be used to request that the directory server treat all entries as if they 056 * were regular entries. 057 * <BR><BR> 058 * One of the most common uses of the ManageDsaIT control is to request that the 059 * directory server to treat an entry containing the "{@code referral}" object 060 * class as a regular entry rather than a smart referral. Normally, when the 061 * server encounters an entry with the {@code referral} object class, it sends 062 * a referral with the URLs contained in the {@code ref} attribute of that 063 * entry. However, if the ManageDsaIT control is included then the operation 064 * will attempt to operate on the referral definition itself rather than sending 065 * that referral to the client. 066 * <BR><BR> 067 * <H2>Example</H2> 068 * The following example demonstrates the use of the ManageDsaIT control to 069 * delete an entry that may or may not be a referral: 070 * <PRE> 071 * // Establish a connection to the directory server. Even though it's the 072 * // default behavior, we'll explicitly configure the connection to not follow 073 * // referrals. 074 * LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions(); 075 * connectionOptions.setFollowReferrals(false); 076 * LDAPConnection connection = new LDAPConnection(connectionOptions, 077 * serverAddress, serverPort, bindDN, bindPassword); 078 * 079 * // Try to delete an entry that will result in a referral. Without the 080 * // ManageDsaIT request control, we should get an exception. 081 * DeleteRequest deleteRequest = 082 * new DeleteRequest("ou=referral entry,dc=example,dc=com"); 083 * LDAPResult deleteResult; 084 * try 085 * { 086 * deleteResult = connection.delete(deleteRequest); 087 * } 088 * catch (LDAPException le) 089 * { 090 * // This exception is expected because we should get a referral, and 091 * // the connection is configured to not follow referrals. 092 * deleteResult = le.toLDAPResult(); 093 * ResultCode resultCode = le.getResultCode(); 094 * String errorMessageFromServer = le.getDiagnosticMessage(); 095 * String[] referralURLs = le.getReferralURLs(); 096 * } 097 * LDAPTestUtils.assertResultCodeEquals(deleteResult, ResultCode.REFERRAL); 098 * LDAPTestUtils.assertHasReferral(deleteResult); 099 * 100 * // Update the delete request to include the ManageDsaIT request control, 101 * // which will cause the server to try to delete the referral entry instead 102 * // of returning a referral response. We'll assume that the delete is 103 * // successful. 104 * deleteRequest.addControl(new ManageDsaITRequestControl()); 105 * try 106 * { 107 * deleteResult = connection.delete(deleteRequest); 108 * } 109 * catch (LDAPException le) 110 * { 111 * // The delete shouldn't trigger a referral, but it's possible that the 112 * // operation failed for some other reason (e.g., entry doesn't exist, the 113 * // user doesn't have permission to delete it, etc.). 114 * deleteResult = le.toLDAPResult(); 115 * } 116 * LDAPTestUtils.assertResultCodeEquals(deleteResult, ResultCode.SUCCESS); 117 * LDAPTestUtils.assertMissingReferral(deleteResult); 118 * 119 * connection.close(); 120 * </PRE> 121 */ 122@NotMutable() 123@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 124public final class ManageDsaITRequestControl 125 extends Control 126{ 127 /** 128 * The OID (2.16.840.1.113730.3.4.2) for the ManageDsaIT request control. 129 */ 130 @NotNull public static final String MANAGE_DSA_IT_REQUEST_OID = 131 "2.16.840.1.113730.3.4.2"; 132 133 134 135 /** 136 * The serial version UID for this serializable class. 137 */ 138 private static final long serialVersionUID = -4540943247829123783L; 139 140 141 142 /** 143 * Creates a new ManageDsaIT request control. The control will not be marked 144 * critical. 145 */ 146 public ManageDsaITRequestControl() 147 { 148 super(MANAGE_DSA_IT_REQUEST_OID, false, null); 149 } 150 151 152 153 /** 154 * Creates a new ManageDsaIT request control. 155 * 156 * @param isCritical Indicates whether the control should be marked 157 * critical. 158 */ 159 public ManageDsaITRequestControl(final boolean isCritical) 160 { 161 super(MANAGE_DSA_IT_REQUEST_OID, isCritical, null); 162 } 163 164 165 166 /** 167 * Creates a new ManageDsaIT request control which is decoded from the 168 * provided generic control. 169 * 170 * @param control The generic control to be decoded as a ManageDsaIT request 171 * control. 172 * 173 * @throws LDAPException If the provided control cannot be decoded as a 174 * ManageDsaIT request control. 175 */ 176 public ManageDsaITRequestControl(@NotNull final Control control) 177 throws LDAPException 178 { 179 super(control); 180 181 if (control.hasValue()) 182 { 183 throw new LDAPException(ResultCode.DECODING_ERROR, 184 ERR_MANAGE_DSA_IT_HAS_VALUE.get()); 185 } 186 } 187 188 189 190 /** 191 * {@inheritDoc} 192 */ 193 @Override() 194 @NotNull() 195 public String getControlName() 196 { 197 return INFO_CONTROL_NAME_MANAGE_DSAIT_REQUEST.get(); 198 } 199 200 201 202 /** 203 * {@inheritDoc} 204 */ 205 @Override() 206 public void toString(@NotNull final StringBuilder buffer) 207 { 208 buffer.append("ManageDsaITRequestControl(isCritical="); 209 buffer.append(isCritical()); 210 buffer.append(')'); 211 } 212}