001/*
002 * Copyright 2010-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2010-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) 2010-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.controls;
037
038
039
040import com.unboundid.asn1.ASN1OctetString;
041import com.unboundid.ldap.sdk.Control;
042import com.unboundid.ldap.sdk.LDAPException;
043import com.unboundid.ldap.sdk.ResultCode;
044import com.unboundid.ldap.sdk.experimental.
045            DraftBeheraLDAPPasswordPolicy10RequestControl;
046import com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest;
047import com.unboundid.util.NotMutable;
048import com.unboundid.util.NotNull;
049import com.unboundid.util.ThreadSafety;
050import com.unboundid.util.ThreadSafetyLevel;
051import com.unboundid.util.Validator;
052
053import static com.unboundid.ldap.sdk.controls.ControlMessages.*;
054
055
056
057/**
058 * This class provides an implementation of the transaction specification
059 * request control as defined in
060 * <A HREF="http://www.ietf.org/rfc/rfc5805.txt">RFC 5805</A>.  It may be used
061 * to indicate that the associated add, delete, modify, modify DN, or password
062 * modify operation is part of an LDAP transaction.  The transaction should be
063 * created with the start transaction extended operation, which will obtain a
064 * transaction ID, and the transaction may be committed or aborted using the end
065 * transaction extended operation.
066 * <BR><BR>
067 * Note that directory servers may limit the set of controls that are available
068 * for use in requests that are part of a transaction.  RFC 5805 section 4
069 * indicates that the following controls may be used in conjunction with the
070 * transaction specification request control:  {@link AssertionRequestControl},
071 * {@link ManageDsaITRequestControl}, {@link PreReadRequestControl}, and
072 * {@link PostReadRequestControl}.  The
073 * {@link ProxiedAuthorizationV1RequestControl} and
074 * {@link ProxiedAuthorizationV2RequestControl} controls cannot be included in
075 * requests that are part of a transaction, but you can include them in the
076 * {@link StartTransactionExtendedRequest} to indicate that all operations
077 * within the transaction should be processed with the specified authorization
078 * identity.
079 * <BR><BR>
080 * The Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 server products
081 * support the following additional UnboundID-specific controls in conjunction
082 * with operations included in a transaction:  account usable request control,
083 * {@link DraftBeheraLDAPPasswordPolicy10RequestControl}, hard delete request
084 * control, intermediate client request control, replication repair request
085 * control, soft delete request control, soft deleted entry access request
086 * control, {@link SubtreeDeleteRequestControl}, and undelete request control.
087 * <BR><BR>
088 * See the documentation for the {@link StartTransactionExtendedRequest} class
089 * for an example of processing an LDAP transaction.
090 */
091@NotMutable()
092@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
093public final class TransactionSpecificationRequestControl
094       extends Control
095{
096  /**
097   * The OID (1.3.6.1.1.21.2) for the transaction specification request control.
098   */
099  @NotNull public static final String TRANSACTION_SPECIFICATION_REQUEST_OID =
100       "1.3.6.1.1.21.2";
101
102
103
104  /**
105   * The serial version UID for this serializable class.
106   */
107  private static final long serialVersionUID = 6489819774149849092L;
108
109
110
111  // The transaction ID for the associated transaction.
112  @NotNull private final ASN1OctetString transactionID;
113
114
115
116  /**
117   * Creates a new transaction specification request control with the provided
118   * transaction ID.
119   *
120   * @param  transactionID  The transaction ID for the associated transaction,
121   *                        as obtained from the start transaction extended
122   *                        operation.  It must not be {@code null}.
123   */
124  public TransactionSpecificationRequestControl(
125              @NotNull final ASN1OctetString transactionID)
126  {
127    super(TRANSACTION_SPECIFICATION_REQUEST_OID, true,
128         new ASN1OctetString(transactionID.getValue()));
129
130    Validator.ensureNotNull(transactionID);
131    this.transactionID = transactionID;
132  }
133
134
135
136  /**
137   * Creates a new transaction specification request control which is decoded
138   * from the provided generic control.
139   *
140   * @param  control  The generic control to be decoded as a transaction
141   *                  specification request control.
142   *
143   * @throws  LDAPException  If the provided control cannot be decoded as a
144   *                         transaction specification request control.
145   */
146  public TransactionSpecificationRequestControl(
147              @NotNull final Control control)
148         throws LDAPException
149  {
150    super(control);
151
152    transactionID = control.getValue();
153    if (transactionID == null)
154    {
155      throw new LDAPException(ResultCode.DECODING_ERROR,
156           ERR_TXN_REQUEST_CONTROL_NO_VALUE.get());
157    }
158  }
159
160
161
162  /**
163   * Retrieves the transaction ID for the associated transaction.
164   *
165   * @return  The transaction ID for the associated transaction.
166   */
167  @NotNull()
168  public ASN1OctetString getTransactionID()
169  {
170    return transactionID;
171  }
172
173
174
175  /**
176   * {@inheritDoc}
177   */
178  @Override()
179  @NotNull()
180  public String getControlName()
181  {
182    return INFO_CONTROL_NAME_TXN_SPECIFICATION_REQUEST.get();
183  }
184
185
186
187  /**
188   * {@inheritDoc}
189   */
190  @Override()
191  public void toString(@NotNull final StringBuilder buffer)
192  {
193    buffer.append("TransactionSpecificationRequestControl(transactionID='");
194    buffer.append(transactionID.stringValue());
195    buffer.append("')");
196  }
197}