001/* 002 * Copyright 2012-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2012-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.asn1.ASN1Element; 041import com.unboundid.asn1.ASN1Sequence; 042import com.unboundid.ldap.sdk.Control; 043import com.unboundid.ldap.sdk.DeleteRequest; 044import com.unboundid.ldap.sdk.LDAPException; 045import com.unboundid.ldap.sdk.ResultCode; 046import com.unboundid.util.Debug; 047import com.unboundid.util.NotMutable; 048import com.unboundid.util.StaticUtils; 049import com.unboundid.util.ThreadSafety; 050import com.unboundid.util.ThreadSafetyLevel; 051 052import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 053 054 055 056/** 057 * This class provides a request control which may be included in a delete 058 * request to indicate that the server should completely remove the target 059 * entry, even if it would otherwise process the operation as a soft delete and 060 * merely hide the entry from most clients. 061 * <BR> 062 * <BLOCKQUOTE> 063 * <B>NOTE:</B> This class, and other classes within the 064 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 065 * supported for use against Ping Identity, UnboundID, and 066 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 067 * for proprietary functionality or for external specifications that are not 068 * considered stable or mature enough to be guaranteed to work in an 069 * interoperable way with other types of LDAP servers. 070 * </BLOCKQUOTE> 071 * <BR> 072 * The criticality for this control may be either {@code TRUE} or {@code FALSE}, 073 * but this will only impact how the delete request is to be handled by servers 074 * which do not support this control. A criticality of {@code TRUE} will cause 075 * any server which does not support this control to reject the request, while 076 * a criticality of {@code FALSE} should cause the delete request to be 077 * processed as if the control had not been included (i.e., as a regular "hard" 078 * delete). 079 * <BR><BR> 080 * The control may optionally have a value. If a value is provided, then it 081 * must be the encoded representation of an empty ASN.1 sequence, like: 082 * <PRE> 083 * HardDeleteRequestValue ::= SEQUENCE { 084 * ... } 085 * </PRE> 086 * In the future, the value sequence may allow one or more elements to customize 087 * the behavior of the hard delete operation, but at present no such elements 088 * are defined. 089 * See the documentation for the {@link SoftDeleteRequestControl} class for an 090 * example demonstrating the use of this control. 091 * 092 * @see SoftDeleteRequestControl 093 */ 094@NotMutable() 095@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 096public final class HardDeleteRequestControl 097 extends Control 098{ 099 /** 100 * The OID (1.3.6.1.4.1.30221.2.5.22) for the hard delete request control. 101 */ 102 public static final String HARD_DELETE_REQUEST_OID = 103 "1.3.6.1.4.1.30221.2.5.22"; 104 105 106 107 /** 108 * The serial version UID for this serializable class. 109 */ 110 private static final long serialVersionUID = 1169625153021056712L; 111 112 113 114 /** 115 * Creates a new hard delete request control. It will not be marked critical. 116 */ 117 public HardDeleteRequestControl() 118 { 119 this(false); 120 } 121 122 123 124 /** 125 * Creates a new hard delete request control with the provided information. 126 * 127 * @param isCritical Indicates whether this control should be marked 128 * critical. This will only have an effect on the way the 129 * associated delete operation is handled by servers which 130 * do NOT support the hard delete request control. For 131 * such servers, a control that is critical will cause the 132 * hard delete attempt to fail, while a control that is 133 * not critical will be processed as if the control was 134 * not included in the request (i.e., as a normal "hard" 135 * delete). 136 */ 137 public HardDeleteRequestControl(final boolean isCritical) 138 { 139 super(HARD_DELETE_REQUEST_OID, isCritical, null); 140 } 141 142 143 144 /** 145 * Creates a new hard delete request control which is decoded from the 146 * provided generic control. 147 * 148 * @param control The generic control to be decoded as a hard delete request 149 * control. 150 * 151 * @throws LDAPException If the provided control cannot be decoded as a hard 152 * delete request control. 153 */ 154 public HardDeleteRequestControl(final Control control) 155 throws LDAPException 156 { 157 super(control); 158 159 if (control.hasValue()) 160 { 161 try 162 { 163 final ASN1Sequence valueSequence = 164 ASN1Sequence.decodeAsSequence(control.getValue().getValue()); 165 final ASN1Element[] elements = valueSequence.elements(); 166 if (elements.length > 0) 167 { 168 throw new LDAPException(ResultCode.DECODING_ERROR, 169 ERR_HARD_DELETE_REQUEST_UNSUPPORTED_VALUE_ELEMENT_TYPE.get( 170 StaticUtils.toHex(elements[0].getType()))); 171 } 172 } 173 catch (final LDAPException le) 174 { 175 Debug.debugException(le); 176 throw le; 177 } 178 catch (final Exception e) 179 { 180 Debug.debugException(e); 181 throw new LDAPException(ResultCode.DECODING_ERROR, 182 ERR_HARD_DELETE_REQUEST_CANNOT_DECODE_VALUE.get( 183 StaticUtils.getExceptionMessage(e)), 184 e); 185 } 186 } 187 } 188 189 190 191 /** 192 * Creates a new delete request that may be used to hard delete the specified 193 * target entry. 194 * 195 * @param targetDN The DN of the entry to be hard deleted. 196 * @param isCritical Indicates whether this control should be marked 197 * critical. This will only have an effect on the way the 198 * associated delete operation is handled by servers which 199 * do NOT support the hard delete request control. For 200 * such servers, a control that is critical will cause the 201 * hard delete attempt to fail, while a control that is 202 * not critical will be processed as if the control was 203 * not included in the request (i.e., as a normal "hard" 204 * delete). 205 * 206 * @return A delete request with the specified target DN and an appropriate 207 * hard delete request control. 208 */ 209 public static DeleteRequest createHardDeleteRequest(final String targetDN, 210 final boolean isCritical) 211 { 212 final Control[] controls = 213 { 214 new HardDeleteRequestControl(isCritical) 215 }; 216 217 return new DeleteRequest(targetDN, controls); 218 } 219 220 221 222 /** 223 * {@inheritDoc} 224 */ 225 @Override() 226 public String getControlName() 227 { 228 return INFO_CONTROL_NAME_HARD_DELETE_REQUEST.get(); 229 } 230 231 232 233 /** 234 * {@inheritDoc} 235 */ 236 @Override() 237 public void toString(final StringBuilder buffer) 238 { 239 buffer.append("HardDeleteRequestControl(isCritical="); 240 buffer.append(isCritical()); 241 buffer.append(')'); 242 } 243}