001/*
002 * Copyright 2009-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-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) 2009-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.NotExtensible;
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 * operation request received from 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@NotExtensible()
069@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
070public abstract class OperationRequestAccessLogMessage
071       extends OperationAccessLogMessage
072{
073  /**
074   * The serial version UID for this serializable class.
075   */
076  private static final long serialVersionUID = -8942685623238040482L;
077
078
079
080  // Indicates whether the request is being processed using a worker thread from
081  // the dedicated administrative session pool.
082  @Nullable private final Boolean usingAdminSessionWorkerThread;
083
084  // The OIDs of the request controls contained in the request.
085  @NotNull private final List<String> requestControlOIDs;
086
087  // Information from the intermediate client request control contained in the
088  // request.
089  @Nullable private final String intermediateClientRequest;
090
091  // Information from the operation purpose control contained in the request.
092  @Nullable private final String operationPurpose;
093
094  // The DN of the user that requested the message.
095  @Nullable private final String requesterDN;
096
097  // The IP address of the client that requested the message.
098  @Nullable private final String requesterIP;
099
100
101
102  /**
103   * Creates a new operation request access log message from the provided log
104   * message.
105   *
106   * @param  m  The log message to be parsed as an operation request access log
107   *            message.
108   */
109  protected OperationRequestAccessLogMessage(@NotNull final LogMessage m)
110  {
111    super(m);
112
113    intermediateClientRequest = getNamedValue("via");
114    operationPurpose          = getNamedValue("opPurpose");
115    requesterDN               = getNamedValue("requesterDN");
116    requesterIP               = getNamedValue("requesterIP");
117
118    usingAdminSessionWorkerThread =
119         getNamedValueAsBoolean("usingAdminSessionWorkerThread");
120
121    final String controlStr = getNamedValue("requestControls");
122    if (controlStr == null)
123    {
124      requestControlOIDs = Collections.emptyList();
125    }
126    else
127    {
128      final LinkedList<String> controlList = new LinkedList<>();
129      final StringTokenizer t = new StringTokenizer(controlStr, ",");
130      while (t.hasMoreTokens())
131      {
132        controlList.add(t.nextToken());
133      }
134      requestControlOIDs = Collections.unmodifiableList(controlList);
135    }
136  }
137
138
139
140  /**
141   * Retrieves the DN of the user that requested the operation.
142   *
143   * @return  The DN of the user that requested the operation, or {@code null}
144   *          if it is not included in the log message.
145   */
146  @Nullable()
147  public final String getRequesterDN()
148  {
149    return requesterDN;
150  }
151
152
153
154  /**
155   * Retrieves the IP address of the client that requested the operation.
156   *
157   * @return  The IP address of the client that requested the operation, or
158   *          {@code null} if it is not included in the log message.
159   */
160  @Nullable()
161  public final String getRequesterIPAddress()
162  {
163    return requesterIP;
164  }
165
166
167
168  /**
169   * Retrieves the content of any intermediate client request control contained
170   * in the request.
171   *
172   * @return  The content of any intermediate client request control contained
173   *          in the request, or {@code null} if it is not included in the log
174   *          message.
175   */
176  @Nullable()
177  public final String getIntermediateClientRequest()
178  {
179    return intermediateClientRequest;
180  }
181
182
183
184  /**
185   * Retrieves the content of any operation purpose request control contained in
186   * the request.
187   *
188   * @return  The content of any operation purpose request control included in
189   *          the request, or {@code null} if it is not included in the log
190   *          message.
191   */
192  @Nullable()
193  public final String getOperationPurpose()
194  {
195    return operationPurpose;
196  }
197
198
199
200  /**
201   * Retrieves the OIDs of any request controls contained in the log message.
202   *
203   * @return  The OIDs of any request controls contained in the log message, or
204   *          an empty list if it is not included in the log message.
205   */
206  @NotNull()
207  public final List<String> getRequestControlOIDs()
208  {
209    return requestControlOIDs;
210  }
211
212
213
214  /**
215   * Indicates whether the operation was processed using a worker thread from
216   * the dedicated administrative session thread pool.
217   *
218   * @return  {@code true} if the operation was processed using a worker thread
219   *          from the dedicated administrative session thread pool,
220   *          {@code false} if it was not, or {@code null} if that information
221   *          was not included in the log message.
222   */
223  @Nullable()
224  public final Boolean usingAdminSessionWorkerThread()
225  {
226    return usingAdminSessionWorkerThread;
227  }
228
229
230
231  /**
232   * {@inheritDoc}
233   */
234  @Override()
235  @NotNull()
236  public AccessLogMessageType getMessageType()
237  {
238    return AccessLogMessageType.REQUEST;
239  }
240}