001 /*
002 * Copyright 2009-2015 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2015 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.ldap.sdk.unboundidds.logs;
022
023
024
025 import java.util.Collections;
026 import java.util.LinkedList;
027 import java.util.List;
028 import java.util.StringTokenizer;
029
030 import com.unboundid.ldap.sdk.DereferencePolicy;
031 import com.unboundid.ldap.sdk.Filter;
032 import com.unboundid.ldap.sdk.SearchScope;
033 import com.unboundid.util.NotExtensible;
034 import com.unboundid.util.NotMutable;
035 import com.unboundid.util.ThreadSafety;
036 import com.unboundid.util.ThreadSafetyLevel;
037
038 import static com.unboundid.util.Debug.*;
039
040
041
042 /**
043 * <BLOCKQUOTE>
044 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
045 * LDAP SDK for Java. It is not available for use in applications that
046 * include only the Standard Edition of the LDAP SDK, and is not supported for
047 * use in conjunction with non-UnboundID products.
048 * </BLOCKQUOTE>
049 * This class provides a data structure that holds information about a log
050 * message that may appear in the Directory Server access log about a search
051 * request received from a client.
052 */
053 @NotExtensible()
054 @NotMutable()
055 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
056 public class SearchRequestAccessLogMessage
057 extends OperationRequestAccessLogMessage
058 {
059 /**
060 * The serial version UID for this serializable class.
061 */
062 private static final long serialVersionUID = -6751258649156129642L;
063
064
065
066 // The typesOnly value for the search request.
067 private final Boolean typesOnly;
068
069 // The alias dereferencing policy for the search request.
070 private final DereferencePolicy derefPolicy;
071
072 // The size limit for the search request.
073 private final Integer sizeLimit;
074
075 // The time limit for the search request.
076 private final Integer timeLimit;
077
078 // The list of requested attributes for the search request.
079 private final List<String> requestedAttributes;
080
081 // The scope for the search request.
082 private final SearchScope scope;
083
084 // The base DN for the search request.
085 private final String baseDN;
086
087 // The string representation of the filter for the search request.
088 private final String filter;
089
090
091
092 /**
093 * Creates a new search request access log message from the provided message
094 * string.
095 *
096 * @param s The string to be parsed as a search request access log message.
097 *
098 * @throws LogException If the provided string cannot be parsed as a valid
099 * log message.
100 */
101 public SearchRequestAccessLogMessage(final String s)
102 throws LogException
103 {
104 this(new LogMessage(s));
105 }
106
107
108
109 /**
110 * Creates a new search request access log message from the provided log
111 * message.
112 *
113 * @param m The log message to be parsed as a search request access log
114 * message.
115 */
116 public SearchRequestAccessLogMessage(final LogMessage m)
117 {
118 super(m);
119
120 baseDN = getNamedValue("base");
121 filter = getNamedValue("filter");
122 sizeLimit = getNamedValueAsInteger("sizeLimit");
123 timeLimit = getNamedValueAsInteger("timeLimit");
124 typesOnly = getNamedValueAsBoolean("typesOnly");
125
126 SearchScope ss = null;
127 try
128 {
129 ss = SearchScope.definedValueOf(getNamedValueAsInteger("scope"));
130 }
131 catch (Exception e)
132 {
133 debugException(e);
134 }
135 scope = ss;
136
137 DereferencePolicy deref = null;
138 final String derefStr = getNamedValue("deref");
139 if (derefStr != null)
140 {
141 for (final DereferencePolicy p : DereferencePolicy.values())
142 {
143 if (p.getName().equalsIgnoreCase(derefStr))
144 {
145 deref = p;
146 break;
147 }
148 }
149 }
150 derefPolicy = deref;
151
152 final String attrStr = getNamedValue("attrs");
153 if (attrStr == null)
154 {
155 requestedAttributes = null;
156 }
157 else if (attrStr.equals("ALL"))
158 {
159 requestedAttributes = Collections.emptyList();
160 }
161 else
162 {
163 final LinkedList<String> attrs = new LinkedList<String>();
164 final StringTokenizer st = new StringTokenizer(attrStr, ",", false);
165 while (st.hasMoreTokens())
166 {
167 attrs.add(st.nextToken());
168 }
169 requestedAttributes = Collections.unmodifiableList(attrs);
170 }
171 }
172
173
174
175 /**
176 * Retrieves the base DN for the search request.
177 *
178 * @return The base DN for the search request, or {@code null} if it is not
179 * included in the log message.
180 */
181 public final String getBaseDN()
182 {
183 return baseDN;
184 }
185
186
187
188 /**
189 * Retrieves the scope for the search request.
190 *
191 * @return The scope for the search request, or {@code null} if it is not
192 * included in the log message.
193 */
194 public final SearchScope getScope()
195 {
196 return scope;
197 }
198
199
200
201 /**
202 * Retrieves a string representation of the filter for the search request.
203 *
204 * @return A string representation of the filter for the search request, or
205 * {@code null} if it is not included in the log message.
206 */
207 public final String getFilter()
208 {
209 return filter;
210 }
211
212
213
214 /**
215 * Retrieves a parsed representation of the filter for the search request.
216 *
217 * @return A parsed representation of the filter for the search request, or
218 * {@code null} if it is not included in the log message or the
219 * filter string cannot be parsed as a filter.
220 */
221 public final Filter getParsedFilter()
222 {
223 try
224 {
225 if (filter == null)
226 {
227 return null;
228 }
229 else
230 {
231 return Filter.create(filter);
232 }
233 }
234 catch (Exception e)
235 {
236 debugException(e);
237 return null;
238 }
239 }
240
241
242
243 /**
244 * Retrieves the dereference policy for the search request.
245 *
246 * @return The dereference policy for the search request, or {@code null} if
247 * it is not included in the log message or the value cannot be
248 * parsed as a valid {@code DereferencePolicy} value.
249 */
250 public final DereferencePolicy getDereferencePolicy()
251 {
252 return derefPolicy;
253 }
254
255
256
257 /**
258 * Retrieves the size limit for the search request.
259 *
260 * @return The size limit for the search request, or {@code null} if it is
261 * not included in the log message or the value cannot be parsed as
262 * an integer.
263 */
264 public final Integer getSizeLimit()
265 {
266 return sizeLimit;
267 }
268
269
270
271 /**
272 * Retrieves the time limit for the search request.
273 *
274 * @return The time limit for the search request, or {@code null} if it is
275 * not included in the log message or the value cannot be parsed as
276 * an integer.
277 */
278 public final Integer getTimeLimit()
279 {
280 return timeLimit;
281 }
282
283
284
285 /**
286 * Retrieves the typesOnly value for the search request.
287 *
288 * @return {@code true} if only attribute type names should be included in
289 * entries that are returned, {@code false} if both attribute types
290 * and values should be returned, or {@code null} if is not included
291 * in the log message or cannot be parsed as a Boolean.
292 */
293 public final Boolean typesOnly()
294 {
295 return typesOnly;
296 }
297
298
299
300 /**
301 * Retrieves the list of requested attributes for the search request.
302 *
303 * @return The list of requested attributes for the search request, an empty
304 * list if the client did not explicitly request any attributes, or
305 * {@code null} if it is not included in the log message.
306 */
307 public final List<String> getRequestedAttributes()
308 {
309 return requestedAttributes;
310 }
311
312
313
314 /**
315 * {@inheritDoc}
316 */
317 @Override()
318 public final AccessLogOperationType getOperationType()
319 {
320 return AccessLogOperationType.SEARCH;
321 }
322 }