001/*
002 * Copyright 2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2022 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 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.text;
037
038
039
040import java.util.Collections;
041import java.util.List;
042
043import com.unboundid.ldap.sdk.DereferencePolicy;
044import com.unboundid.ldap.sdk.SearchScope;
045import com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType;
046import com.unboundid.ldap.sdk.unboundidds.logs.LogException;
047import com.unboundid.ldap.sdk.unboundidds.logs.v2.SearchRequestAccessLogMessage;
048import com.unboundid.util.NotExtensible;
049import com.unboundid.util.NotMutable;
050import com.unboundid.util.NotNull;
051import com.unboundid.util.Nullable;
052import com.unboundid.util.ThreadSafety;
053import com.unboundid.util.ThreadSafetyLevel;
054
055
056
057/**
058 * This class provides a data structure that holds information about a
059 * text-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 TextFormattedSearchRequestAccessLogMessage
075       extends TextFormattedRequestAccessLogMessage
076       implements SearchRequestAccessLogMessage
077{
078  /**
079   * The serial version UID for this serializable class.
080   */
081  private static final long serialVersionUID = 7498979077353447769L;
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 text-formatted search request access log message from the
113   * provided message string.
114   *
115   * @param  logMessageString  The string representation of this log message.
116   *                           It must not be {@code null}.
117   *
118   * @throws  LogException  If the provided string cannot be parsed as a valid
119   *                        log message.
120   */
121  public TextFormattedSearchRequestAccessLogMessage(
122              @NotNull final String logMessageString)
123         throws LogException
124  {
125    this(new TextFormattedLogMessage(logMessageString));
126  }
127
128
129
130  /**
131   * Creates a new text-formatted search request access log message from the
132   * provided message.
133   *
134   * @param  logMessage  The log message to use to create this search request
135   *                     access log message.  It must not be {@code null}.
136   */
137  TextFormattedSearchRequestAccessLogMessage(
138       @NotNull final TextFormattedLogMessage logMessage)
139  {
140    super(logMessage);
141
142    baseDN = getString(TextFormattedAccessLogFields.SEARCH_BASE_DN);
143    filter = getString(TextFormattedAccessLogFields.SEARCH_FILTER);
144    sizeLimit =
145         getIntegerNoThrow(TextFormattedAccessLogFields.SEARCH_SIZE_LIMIT);
146    timeLimit = getIntegerNoThrow(
147         TextFormattedAccessLogFields.SEARCH_TIME_LIMIT_SECONDS);
148    typesOnly = getBooleanNoThrow(
149         TextFormattedAccessLogFields.SEARCH_TYPES_ONLY);
150
151
152    final Integer scopeValue = getIntegerNoThrow(
153         TextFormattedAccessLogFields.SEARCH_SCOPE_VALUE);
154    if (scopeValue == null)
155    {
156      scope = null;
157    }
158    else
159    {
160      scope = SearchScope.valueOf(scopeValue);
161    }
162
163
164    final String derefStr =
165         getString(TextFormattedAccessLogFields.SEARCH_DEREF_POLICY);
166    if (derefStr == null)
167    {
168      dereferencePolicy = null;
169    }
170    else
171    {
172      DereferencePolicy policy = null;
173      for (final DereferencePolicy p : DereferencePolicy.values())
174      {
175        if (p.getName().equalsIgnoreCase(derefStr))
176        {
177          policy = p;
178          break;
179        }
180      }
181
182      dereferencePolicy = policy;
183    }
184
185
186    final List<String> requestedAttrsList = getCommaDelimitedStringList(
187         TextFormattedAccessLogFields.SEARCH_REQUESTED_ATTRIBUTES);
188    if ((requestedAttrsList.size() == 1) &&
189         requestedAttrsList.get(0).equals("ALL"))
190    {
191      requestedAttributes = Collections.emptyList();
192    }
193    else
194    {
195      requestedAttributes = requestedAttrsList;
196    }
197  }
198
199
200
201  /**
202   * {@inheritDoc}
203   */
204  @Override()
205  @NotNull()
206  public final AccessLogOperationType getOperationType()
207  {
208    return AccessLogOperationType.SEARCH;
209  }
210
211
212
213  /**
214   * {@inheritDoc}
215   */
216  @Override()
217  @Nullable()
218  public final String getBaseDN()
219  {
220    return baseDN;
221  }
222
223
224
225  /**
226   * {@inheritDoc}
227   */
228  @Override()
229  @Nullable()
230  public final SearchScope getScope()
231  {
232    return scope;
233  }
234
235
236
237  /**
238   * {@inheritDoc}
239   */
240  @Override()
241  @Nullable()
242  public final String getFilter()
243  {
244    return filter;
245  }
246
247
248
249  /**
250   * {@inheritDoc}
251   */
252  @Override()
253  @Nullable()
254  public final DereferencePolicy getDereferencePolicy()
255  {
256    return dereferencePolicy;
257  }
258
259
260
261  /**
262   * {@inheritDoc}
263   */
264  @Override()
265  @Nullable()
266  public final Integer getSizeLimit()
267  {
268    return sizeLimit;
269  }
270
271
272
273  /**
274   * {@inheritDoc}
275   */
276  @Override()
277  @Nullable()
278  public final Integer getTimeLimitSeconds()
279  {
280    return timeLimit;
281  }
282
283
284
285  /**
286   * {@inheritDoc}
287   */
288  @Override()
289  @Nullable()
290  public final Boolean getTypesOnly()
291  {
292    return typesOnly;
293  }
294
295
296
297  /**
298   * {@inheritDoc}
299   */
300  @Override()
301  @NotNull()
302  public final List<String> getRequestedAttributes()
303  {
304    return requestedAttributes;
305  }
306}