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.unboundidds.logs;
037
038
039
040import java.util.Collections;
041import java.util.LinkedList;
042import java.util.List;
043import java.util.StringTokenizer;
044
045import com.unboundid.util.NotMutable;
046import com.unboundid.util.NotNull;
047import com.unboundid.util.Nullable;
048import com.unboundid.util.ThreadSafety;
049import com.unboundid.util.ThreadSafetyLevel;
050
051
052
053/**
054 * This class provides a data structure that holds information about a log
055 * message that may appear in the Directory Server access log about an
056 * intermediate response returned to a client.
057 * <BR>
058 * <BLOCKQUOTE>
059 *   <B>NOTE:</B>  This class, and other classes within the
060 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
061 *   supported for use against Ping Identity, UnboundID, and
062 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
063 *   for proprietary functionality or for external specifications that are not
064 *   considered stable or mature enough to be guaranteed to work in an
065 *   interoperable way with other types of LDAP servers.
066 * </BLOCKQUOTE>
067 */
068@NotMutable()
069@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
070public final class IntermediateResponseAccessLogMessage
071       extends OperationRequestAccessLogMessage
072{
073  /**
074   * The serial version UID for this serializable class.
075   */
076  private static final long serialVersionUID = 4480365381503945078L;
077
078
079
080  // The operation type for this access log message.
081  @NotNull private final AccessLogOperationType operationType;
082
083  // The list of response control OIDs for the operation.
084  @NotNull private final List<String> responseControlOIDs;
085
086  // A human-readable version of the intermediate response name.
087  @Nullable private final String name;
088
089  // The OID of the intermediate response.
090  @Nullable private final String oid;
091
092  // A human-readable version of the intermediate response value.
093  @Nullable private final String value;
094
095
096
097  /**
098   * Creates a new intermediate response access log message from the provided
099   * message string.
100   *
101   * @param  s  The string to be parsed as an intermediate response access log
102   *            message.
103   *
104   * @throws  LogException  If the provided string cannot be parsed as a valid
105   *                        log message.
106   */
107  public IntermediateResponseAccessLogMessage(@NotNull final String s)
108         throws LogException
109  {
110    this(new LogMessage(s));
111  }
112
113
114
115  /**
116   * Creates a new intermediate response access log message from the provided
117   * log message.
118   *
119   * @param  m  The log message to be parsed as an intermediate response access
120   *            log message.
121   */
122  public IntermediateResponseAccessLogMessage(@NotNull final LogMessage m)
123  {
124    super(m);
125
126    oid   = getNamedValue("oid");
127    name  = getNamedValue("name");
128    value = getNamedValue("value");
129
130    final String controlStr = getNamedValue("responseControls");
131    if (controlStr == null)
132    {
133      responseControlOIDs = Collections.emptyList();
134    }
135    else
136    {
137      final LinkedList<String> controlList = new LinkedList<>();
138      final StringTokenizer t = new StringTokenizer(controlStr, ",");
139      while (t.hasMoreTokens())
140      {
141        controlList.add(t.nextToken());
142      }
143      responseControlOIDs = Collections.unmodifiableList(controlList);
144    }
145
146    if (m.hasUnnamedValue(AccessLogOperationType.ADD.getLogIdentifier()))
147    {
148      operationType = AccessLogOperationType.ADD;
149    }
150    else if (m.hasUnnamedValue(AccessLogOperationType.BIND.getLogIdentifier()))
151    {
152      operationType = AccessLogOperationType.BIND;
153    }
154    else if (m.hasUnnamedValue(AccessLogOperationType.
155         COMPARE.getLogIdentifier()))
156    {
157      operationType = AccessLogOperationType.COMPARE;
158    }
159    else if (m.hasUnnamedValue(AccessLogOperationType.
160         DELETE.getLogIdentifier()))
161    {
162      operationType = AccessLogOperationType.DELETE;
163    }
164    else if (m.hasUnnamedValue(AccessLogOperationType.
165         EXTENDED.getLogIdentifier()))
166    {
167      operationType = AccessLogOperationType.EXTENDED;
168    }
169    else if (m.hasUnnamedValue(AccessLogOperationType.
170         MODIFY.getLogIdentifier()))
171    {
172      operationType = AccessLogOperationType.MODIFY;
173    }
174    else if (m.hasUnnamedValue(AccessLogOperationType.MODDN.getLogIdentifier()))
175    {
176      operationType = AccessLogOperationType.MODDN;
177    }
178    else if (m.hasUnnamedValue(
179         AccessLogOperationType.SEARCH.getLogIdentifier()))
180    {
181      operationType = AccessLogOperationType.SEARCH;
182    }
183    else
184    {
185      // This shouldn't happen, but we'll assume it's extended.
186      operationType = AccessLogOperationType.EXTENDED;
187    }
188  }
189
190
191
192  /**
193   * Retrieves the OID of the intermediate response.
194   *
195   * @return  The OID of the intermediate response, or {@code null} if it is
196   *          not included in the log message.
197   */
198  @Nullable()
199  public String getOID()
200  {
201    return oid;
202  }
203
204
205
206  /**
207   * Retrieves a human-readable name for the intermediate response.
208   *
209   * @return  A human-readable name for the intermediate response, or
210   *          {@code null} if it is not included in the log message.
211   */
212  @Nullable()
213  public String getIntermediateResponseName()
214  {
215    return name;
216  }
217
218
219
220  /**
221   * Retrieves a human-readable representation of the intermediate response
222   * value.
223   *
224   * @return  A human-readable representation of the intermediate response
225   *          value, or {@code null} if it is not included in the log message.
226   */
227  @Nullable()
228  public String getValueString()
229  {
230    return value;
231  }
232
233
234
235  /**
236   * Retrieves the OIDs of any response controls contained in the log message.
237   *
238   * @return  The OIDs of any response controls contained in the log message, or
239   *          an empty list if it is not included in the log message.
240   */
241  @NotNull()
242  public List<String> getResponseControlOIDs()
243  {
244    return responseControlOIDs;
245  }
246
247
248
249  /**
250   * {@inheritDoc}
251   */
252  @Override()
253  @NotNull()
254  public AccessLogMessageType getMessageType()
255  {
256    return AccessLogMessageType.INTERMEDIATE_RESPONSE;
257  }
258
259
260
261  /**
262   * {@inheritDoc}
263   */
264  @Override()
265  @NotNull()
266  public AccessLogOperationType getOperationType()
267  {
268    return operationType;
269  }
270}