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.List;
041
042import com.unboundid.ldap.sdk.DereferencePolicy;
043import com.unboundid.ldap.sdk.SearchScope;
044import com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType;
045import com.unboundid.ldap.sdk.unboundidds.logs.LogException;
046import com.unboundid.ldap.sdk.unboundidds.logs.v2.SearchRequestAccessLogMessage;
047import com.unboundid.util.NotExtensible;
048import com.unboundid.util.NotMutable;
049import com.unboundid.util.NotNull;
050import com.unboundid.util.Nullable;
051import com.unboundid.util.ThreadSafety;
052import com.unboundid.util.ThreadSafetyLevel;
053import com.unboundid.util.json.JSONObject;
054
055
056
057/**
058 * This class provides a data structure that holds information about a
059 * JSON-formatted search request access log message.
060 * <BR>
061 * <BLOCKQUOTE>
062 *   <B>NOTE:</B>  This class, and other classes within the
063 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
064 *   supported for use against Ping Identity, UnboundID, and
065 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
066 *   for proprietary functionality or for external specifications that are not
067 *   considered stable or mature enough to be guaranteed to work in an
068 *   interoperable way with other types of LDAP servers.
069 * </BLOCKQUOTE>
070 */
071@NotExtensible()
072@NotMutable()
073@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
074public class JSONSearchRequestAccessLogMessage
075       extends JSONRequestAccessLogMessage
076       implements SearchRequestAccessLogMessage
077{
078  /**
079   * The serial version UID for this serializable class.
080   */
081  private static final long serialVersionUID = -913390265725394880L;
082
083
084
085  // The types only flag for the search request.
086  @Nullable private final Boolean typesOnly;
087
088  // The alias dereferencing policy for the search request.
089  @Nullable private final DereferencePolicy dereferencePolicy;
090
091  // The size limit for the search request.
092  @Nullable private final Integer sizeLimit;
093
094  // The time limit for the search request.
095  @Nullable private final Integer timeLimit;
096
097  // The list of requested attributes for the search request.
098  @NotNull private final List<String> requestedAttributes;
099
100  // The scope for the search request.
101  @Nullable private final SearchScope scope;
102
103  // The base DN for ths search request.
104  @Nullable private final String baseDN;
105
106  // The filter for ths search request.
107  @Nullable private final String filter;
108
109
110
111  /**
112   * Creates a new JSON search request access log message from the provided
113   * JSON object.
114   *
115   * @param  jsonObject  The JSON object that contains an encoded representation
116   *                     of this log message.  It must not be {@code null}.
117   *
118   * @throws  LogException  If the provided JSON object cannot be parsed as a
119   *                        valid log message.
120   */
121  public JSONSearchRequestAccessLogMessage(
122              @NotNull final JSONObject jsonObject)
123         throws LogException
124  {
125    super(jsonObject);
126
127    baseDN = getString(JSONFormattedAccessLogFields.SEARCH_BASE_DN);
128    filter = getString(JSONFormattedAccessLogFields.SEARCH_FILTER);
129    sizeLimit =
130         getIntegerNoThrow(JSONFormattedAccessLogFields.SEARCH_SIZE_LIMIT);
131    timeLimit = getIntegerNoThrow(
132         JSONFormattedAccessLogFields.SEARCH_TIME_LIMIT_SECONDS);
133    typesOnly = getBooleanNoThrow(
134         JSONFormattedAccessLogFields.SEARCH_TYPES_ONLY);
135    requestedAttributes = getStringList(
136         JSONFormattedAccessLogFields.SEARCH_REQUESTED_ATTRIBUTES);
137
138
139    final Integer scopeValue = getIntegerNoThrow(
140         JSONFormattedAccessLogFields.SEARCH_SCOPE_VALUE);
141    if (scopeValue == null)
142    {
143      scope = null;
144    }
145    else
146    {
147      scope = SearchScope.valueOf(scopeValue);
148    }
149
150
151    final String derefStr =
152         getString(JSONFormattedAccessLogFields.SEARCH_DEREF_POLICY);
153    if (derefStr == null)
154    {
155      dereferencePolicy = null;
156    }
157    else
158    {
159      DereferencePolicy policy = null;
160      for (final DereferencePolicy p : DereferencePolicy.values())
161      {
162        if (p.getName().equalsIgnoreCase(derefStr))
163        {
164          policy = p;
165          break;
166        }
167      }
168
169      dereferencePolicy = policy;
170    }
171  }
172
173
174
175  /**
176   * {@inheritDoc}
177   */
178  @Override()
179  @NotNull()
180  public final AccessLogOperationType getOperationType()
181  {
182    return AccessLogOperationType.SEARCH;
183  }
184
185
186
187  /**
188   * {@inheritDoc}
189   */
190  @Override()
191  @Nullable()
192  public final String getBaseDN()
193  {
194    return baseDN;
195  }
196
197
198
199  /**
200   * {@inheritDoc}
201   */
202  @Override()
203  @Nullable()
204  public final SearchScope getScope()
205  {
206    return scope;
207  }
208
209
210
211  /**
212   * {@inheritDoc}
213   */
214  @Override()
215  @Nullable()
216  public final String getFilter()
217  {
218    return filter;
219  }
220
221
222
223  /**
224   * {@inheritDoc}
225   */
226  @Override()
227  @Nullable()
228  public final DereferencePolicy getDereferencePolicy()
229  {
230    return dereferencePolicy;
231  }
232
233
234
235  /**
236   * {@inheritDoc}
237   */
238  @Override()
239  @Nullable()
240  public final Integer getSizeLimit()
241  {
242    return sizeLimit;
243  }
244
245
246
247  /**
248   * {@inheritDoc}
249   */
250  @Override()
251  @Nullable()
252  public final Integer getTimeLimitSeconds()
253  {
254    return timeLimit;
255  }
256
257
258
259  /**
260   * {@inheritDoc}
261   */
262  @Override()
263  @Nullable()
264  public final Boolean getTypesOnly()
265  {
266    return typesOnly;
267  }
268
269
270
271  /**
272   * {@inheritDoc}
273   */
274  @Override()
275  @NotNull()
276  public final List<String> getRequestedAttributes()
277  {
278    return requestedAttributes;
279  }
280}