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