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