001/*
002 * Copyright 2022-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2022-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) 2022-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.v2.json;
037
038
039
040import java.util.Set;
041
042import com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType;
043import com.unboundid.ldap.sdk.unboundidds.logs.LogException;
044import com.unboundid.ldap.sdk.unboundidds.logs.v2.
045            OperationRequestAccessLogMessage;
046import com.unboundid.util.NotExtensible;
047import com.unboundid.util.NotNull;
048import com.unboundid.util.Nullable;
049import com.unboundid.util.ThreadSafety;
050import com.unboundid.util.ThreadSafetyLevel;
051import com.unboundid.util.json.JSONObject;
052
053
054
055/**
056 * This class provides a data structure that holds information about a
057 * JSON-formatted operation request access log message.
058 * <BR>
059 * <BLOCKQUOTE>
060 *   <B>NOTE:</B>  This class, and other classes within the
061 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
062 *   supported for use against Ping Identity, UnboundID, and
063 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
064 *   for proprietary functionality or for external specifications that are not
065 *   considered stable or mature enough to be guaranteed to work in an
066 *   interoperable way with other types of LDAP servers.
067 * </BLOCKQUOTE>
068 */
069@NotExtensible()
070@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE)
071public abstract class JSONRequestAccessLogMessage
072       extends JSONAccessLogMessage
073       implements OperationRequestAccessLogMessage
074{
075  /**
076   * The serial version UID for this serializable class.
077   */
078  private static final long serialVersionUID = -8154114903633681042L;
079
080
081
082  // Indicates whether the operation was processed using an admin session
083  // worker thread.
084  @Nullable private final Boolean usingAdminSessionWorkerThread;
085
086  // The message ID for this log message.
087  @Nullable private final Integer messageID;
088
089  // The intermediate client request control for this log message.
090  @Nullable private final JSONIntermediateClientRequestControl
091       intermediateClientRequestControl;
092
093  // The operation purpose request control for this log message.
094  @Nullable private final JSONOperationPurposeRequestControl
095       operationPurposeRequestControl;
096
097  // The operation ID for this log message.
098  @Nullable private final Long operationID;
099
100  // The triggered by connection ID for this log message.
101  @Nullable private final Long triggeredByConnectionID;
102
103  // The triggered by operation ID for this log message.
104  @Nullable private final Long triggeredByOperationID;
105
106  // The request control OIDs for this log message.
107  @NotNull private final Set<String> requestControlOIDs;
108
109  // The administrative operation message for this log message.
110  @Nullable private final String administrativeOperationMessage;
111
112  // The origin for this log message.
113  @Nullable private final String origin;
114
115  // The requester DN for this log message.
116  @Nullable private final String requesterDN;
117
118  // The requester IP address for this log message.
119  @Nullable private final String requesterIPAddress;
120
121
122
123  /**
124   * Creates a new JSON request access log message from the provided JSON
125   * object.
126   *
127   * @param  jsonObject  The JSON object that contains an encoded representation
128   *                     of this log message.  It must not be {@code null}.
129   *
130   * @throws  LogException  If the provided JSON object cannot be parsed as a
131   *                        valid log message.
132   */
133  protected JSONRequestAccessLogMessage(@NotNull final JSONObject jsonObject)
134            throws LogException
135  {
136    super(jsonObject);
137
138    operationID = getLongNoThrow(JSONFormattedAccessLogFields.OPERATION_ID);
139    messageID = getIntegerNoThrow(JSONFormattedAccessLogFields.MESSAGE_ID);
140    origin = getString(JSONFormattedAccessLogFields.ORIGIN);
141    triggeredByConnectionID = getLongNoThrow(
142         JSONFormattedAccessLogFields.TRIGGERED_BY_CONNECTION_ID);
143    triggeredByOperationID = getLongNoThrow(
144         JSONFormattedAccessLogFields.TRIGGERED_BY_OPERATION_ID);
145    requesterDN = getString(JSONFormattedAccessLogFields.REQUESTER_DN);
146    requesterIPAddress = getString(
147         JSONFormattedAccessLogFields.REQUESTER_IP_ADDRESS);
148    usingAdminSessionWorkerThread = getBooleanNoThrow(
149         JSONFormattedAccessLogFields.USING_ADMIN_SESSION_WORKER_THREAD);
150    administrativeOperationMessage = getString(
151         JSONFormattedAccessLogFields.ADMINISTRATIVE_OPERATION);
152    requestControlOIDs = getStringSet(
153         JSONFormattedAccessLogFields.REQUEST_CONTROL_OIDS);
154
155    final JSONObject intermediateClientRequestObject =
156         jsonObject.getFieldAsObject(
157              JSONFormattedAccessLogFields.INTERMEDIATE_CLIENT_REQUEST_CONTROL.
158                   getFieldName());
159    if (intermediateClientRequestObject == null)
160    {
161      intermediateClientRequestControl = null;
162    }
163    else
164    {
165      intermediateClientRequestControl =
166           new JSONIntermediateClientRequestControl(
167                intermediateClientRequestObject);
168    }
169
170    final JSONObject operationPurposeRequestObject =
171         jsonObject.getFieldAsObject(
172              JSONFormattedAccessLogFields.OPERATION_PURPOSE.getFieldName());
173    if (operationPurposeRequestObject == null)
174    {
175      operationPurposeRequestControl = null;
176    }
177    else
178    {
179      operationPurposeRequestControl = new JSONOperationPurposeRequestControl(
180           operationPurposeRequestObject);
181    }
182  }
183
184
185
186  /**
187   * {@inheritDoc}
188   */
189  @Override()
190  @NotNull()
191  public AccessLogMessageType getMessageType()
192  {
193    return AccessLogMessageType.REQUEST;
194  }
195
196
197
198  /**
199   * {@inheritDoc}
200   */
201  @Override()
202  @Nullable()
203  public final Long getOperationID()
204  {
205    return operationID;
206  }
207
208
209
210  /**
211   * {@inheritDoc}
212   */
213  @Override()
214  @Nullable()
215  public final Integer getMessageID()
216  {
217    return messageID;
218  }
219
220
221
222  /**
223   * {@inheritDoc}
224   */
225  @Override()
226  @Nullable()
227  public final String getOrigin()
228  {
229    return origin;
230  }
231
232
233
234  /**
235   * {@inheritDoc}
236   */
237  @Override()
238  @Nullable()
239  public final Long getTriggeredByConnectionID()
240  {
241    return triggeredByConnectionID;
242  }
243
244
245
246  /**
247   * {@inheritDoc}
248   */
249  @Override()
250  @Nullable()
251  public final Long getTriggeredByOperationID()
252  {
253    return triggeredByOperationID;
254  }
255
256
257
258  /**
259   * {@inheritDoc}
260   */
261  @Override()
262  @Nullable()
263  public final String getRequesterDN()
264  {
265    return requesterDN;
266  }
267
268
269
270  /**
271   * {@inheritDoc}
272   */
273  @Override()
274  @Nullable()
275  public final String getRequesterIPAddress()
276  {
277    return requesterIPAddress;
278  }
279
280
281
282  /**
283   * {@inheritDoc}
284   */
285  @Override()
286  @NotNull()
287  public final Set<String> getRequestControlOIDs()
288  {
289    return requestControlOIDs;
290  }
291
292
293
294  /**
295   * {@inheritDoc}
296   */
297  @Override()
298  @Nullable()
299  public final Boolean getUsingAdminSessionWorkerThread()
300  {
301    return usingAdminSessionWorkerThread;
302  }
303
304
305
306  /**
307   * {@inheritDoc}
308   */
309  @Override()
310  @Nullable()
311  public final String getAdministrativeOperationMessage()
312  {
313    return administrativeOperationMessage;
314  }
315
316
317
318  /**
319   * Retrieves information about an intermediate client request control included
320   * in the log message.
321   *
322   * @return  An intermediate client request control included in the log
323   *          message, or {@code null} if no intermediate client request control
324   *          is available.
325   */
326  @Nullable()
327  public final JSONIntermediateClientRequestControl
328                    getIntermediateClientRequestControl()
329  {
330    return intermediateClientRequestControl;
331  }
332
333
334
335  /**
336   * Retrieves information about an operation purpose request control included
337   * in the log message.
338   *
339   * @return  An operation purpose request control included in the log message,
340   *          or {@code null} if no operation purpose request control is
341   *          available.
342   */
343  @Nullable()
344  public final JSONOperationPurposeRequestControl
345                    getOperationPurposeRequestControl()
346  {
347    return operationPurposeRequestControl;
348  }
349}