001/* 002 * Copyright 2008-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-2024 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-2024 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.JSONControlDecodeHelper; 042import com.unboundid.ldap.sdk.LDAPException; 043import com.unboundid.ldap.sdk.ResultCode; 044import com.unboundid.util.NotMutable; 045import com.unboundid.util.NotNull; 046import com.unboundid.util.ThreadSafety; 047import com.unboundid.util.ThreadSafetyLevel; 048import com.unboundid.util.json.JSONField; 049import com.unboundid.util.json.JSONObject; 050 051import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 052 053 054 055/** 056 * This class defines a request control that may be used to indicate that the 057 * server should process all aspects of the associated bind request (including 058 * password policy processing) but should not actually change the identity for 059 * the client connection, regardless of whether the authentication is 060 * successful. 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 * This control can be very useful for applications that perform binds to 073 * authenticate users but also use connection pooling to re-use connections 074 * for multiple operations. Bind operations are normally not well-suited for 075 * use on pooled connections because they change the identity of that 076 * connection, but the retain identity request control solves that problem by 077 * performing all bind processing but does not change the identity associated 078 * with the client connection. 079 * <BR><BR> 080 * There is no corresponding response control. If the bind is successful, then 081 * the server should return a bind response with the {@code ResultCode#SUCCESS} 082 * result code just as if the bind request had not included the retain identity 083 * request control. 084 * <BR><BR> 085 * This control is not based on any public standard. It was originally 086 * developed for use with the Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 087 * 8661 Directory Server. It does not have a value. 088 * <BR><BR> 089 * <H2>Example</H2> 090 * The following example demonstrates the use of the retain identity request 091 * control: 092 * <PRE> 093 * SimpleBindRequest bindRequest = new SimpleBindRequest( 094 * "uid=john.doe,ou=People,dc=example,dc=com", "password", 095 * new RetainIdentityRequestControl()); 096 * 097 * BindResult bindResult; 098 * try 099 * { 100 * bindResult = connection.bind(bindRequest); 101 * // The bind was successful and the account is usable, but the identity 102 * // associated with the client connection hasn't changed. 103 * } 104 * catch (LDAPException le) 105 * { 106 * bindResult = new BindResult(le.toLDAPResult()); 107 * // The bind was unsuccessful, potentially because the credentials were 108 * // invalid or the account is unusable for some reason (e.g., disabled, 109 * // locked, expired password, etc.). The identity associated with the 110 * // client connection hasn't changed. 111 * } 112 * </PRE> 113 */ 114@NotMutable() 115@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 116public final class RetainIdentityRequestControl 117 extends Control 118{ 119 /** 120 * The OID (1.3.6.1.4.1.30221.2.5.3) for the retain identity request control. 121 */ 122 @NotNull public static final String RETAIN_IDENTITY_REQUEST_OID = 123 "1.3.6.1.4.1.30221.2.5.3"; 124 125 126 127 /** 128 * The serial version UID for this serializable class. 129 */ 130 private static final long serialVersionUID = 9066549673766581236L; 131 132 133 134 /** 135 * Creates a new retain identity request control. It will be marked critical. 136 */ 137 public RetainIdentityRequestControl() 138 { 139 super(RETAIN_IDENTITY_REQUEST_OID, true, null); 140 } 141 142 143 144 /** 145 * Creates a new retain identity request control which is decoded from 146 * the provided generic control. 147 * 148 * @param control The generic control to be decoded as a retain identity 149 * request control. 150 * 151 * @throws LDAPException If the provided control cannot be decoded as a 152 * retain identity request control. 153 */ 154 public RetainIdentityRequestControl(@NotNull final Control control) 155 throws LDAPException 156 { 157 super(control); 158 159 if (control.hasValue()) 160 { 161 throw new LDAPException(ResultCode.DECODING_ERROR, 162 ERR_RETAIN_IDENTITY_REQUEST_HAS_VALUE.get()); 163 } 164 } 165 166 167 168 /** 169 * {@inheritDoc} 170 */ 171 @Override() 172 @NotNull() 173 public String getControlName() 174 { 175 return INFO_CONTROL_NAME_RETAIN_IDENTITY_REQUEST.get(); 176 } 177 178 179 180 /** 181 * Retrieves a representation of this retain identity request control as a 182 * JSON object. The JSON object uses the following fields (note that since 183 * this control does not have a value, neither the {@code value-base64} nor 184 * {@code value-json} fields may be present): 185 * <UL> 186 * <LI> 187 * {@code oid} -- A mandatory string field whose value is the object 188 * identifier for this control. For the retain identity request control, 189 * the OID is "1.3.6.1.4.1.30221.2.5.3". 190 * </LI> 191 * <LI> 192 * {@code control-name} -- An optional string field whose value is a 193 * human-readable name for this control. This field is only intended for 194 * descriptive purposes, and when decoding a control, the {@code oid} 195 * field should be used to identify the type of control. 196 * </LI> 197 * <LI> 198 * {@code criticality} -- A mandatory Boolean field used to indicate 199 * whether this control is considered critical. 200 * </LI> 201 * </UL> 202 * 203 * @return A JSON object that contains a representation of this control. 204 */ 205 @Override() 206 @NotNull() 207 public JSONObject toJSONControl() 208 { 209 return new JSONObject( 210 new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID, 211 RETAIN_IDENTITY_REQUEST_OID), 212 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME, 213 INFO_CONTROL_NAME_RETAIN_IDENTITY_REQUEST.get()), 214 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY, 215 isCritical())); 216 } 217 218 219 220 /** 221 * Attempts to decode the provided object as a JSON representation of a 222 * retain identity request control. 223 * 224 * @param controlObject The JSON object to be decoded. It must not be 225 * {@code null}. 226 * @param strict Indicates whether to use strict mode when decoding 227 * the provided JSON object. If this is {@code true}, 228 * then this method will throw an exception if the 229 * provided JSON object contains any unrecognized 230 * fields. If this is {@code false}, then unrecognized 231 * fields will be ignored. 232 * 233 * @return The retain identity request control that was decoded from 234 * the provided JSON object. 235 * 236 * @throws LDAPException If the provided JSON object cannot be parsed as a 237 * valid retain identity request control. 238 */ 239 @NotNull() 240 public static RetainIdentityRequestControl decodeJSONControl( 241 @NotNull final JSONObject controlObject, 242 final boolean strict) 243 throws LDAPException 244 { 245 final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper( 246 controlObject, strict, false, false); 247 248 return new RetainIdentityRequestControl(); 249 } 250 251 252 253 /** 254 * {@inheritDoc} 255 */ 256 @Override() 257 public void toString(@NotNull final StringBuilder buffer) 258 { 259 buffer.append("RetainIdentityRequestControl(isCritical="); 260 buffer.append(isCritical()); 261 buffer.append(')'); 262 } 263}