001/* 002 * Copyright 2009-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2009-2020 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) 2015-2020 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.ldap.sdk.DereferencePolicy; 046import com.unboundid.ldap.sdk.Filter; 047import com.unboundid.ldap.sdk.SearchScope; 048import com.unboundid.util.Debug; 049import com.unboundid.util.NotExtensible; 050import com.unboundid.util.NotMutable; 051import com.unboundid.util.ThreadSafety; 052import com.unboundid.util.ThreadSafetyLevel; 053 054 055 056/** 057 * This class provides a data structure that holds information about a log 058 * message that may appear in the Directory Server access log about a search 059 * request received from a client. 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 SearchRequestAccessLogMessage 075 extends OperationRequestAccessLogMessage 076{ 077 /** 078 * The serial version UID for this serializable class. 079 */ 080 private static final long serialVersionUID = -6751258649156129642L; 081 082 083 084 // The typesOnly value for the search request. 085 private final Boolean typesOnly; 086 087 // The alias dereferencing policy for the search request. 088 private final DereferencePolicy derefPolicy; 089 090 // The size limit for the search request. 091 private final Integer sizeLimit; 092 093 // The time limit for the search request. 094 private final Integer timeLimit; 095 096 // The list of requested attributes for the search request. 097 private final List<String> requestedAttributes; 098 099 // The scope for the search request. 100 private final SearchScope scope; 101 102 // The base DN for the search request. 103 private final String baseDN; 104 105 // The string representation of the filter for the search request. 106 private final String filter; 107 108 109 110 /** 111 * Creates a new search request access log message from the provided message 112 * string. 113 * 114 * @param s The string to be parsed as a search request access log message. 115 * 116 * @throws LogException If the provided string cannot be parsed as a valid 117 * log message. 118 */ 119 public SearchRequestAccessLogMessage(final String s) 120 throws LogException 121 { 122 this(new LogMessage(s)); 123 } 124 125 126 127 /** 128 * Creates a new search request access log message from the provided log 129 * message. 130 * 131 * @param m The log message to be parsed as a search request access log 132 * message. 133 */ 134 public SearchRequestAccessLogMessage(final LogMessage m) 135 { 136 super(m); 137 138 baseDN = getNamedValue("base"); 139 filter = getNamedValue("filter"); 140 sizeLimit = getNamedValueAsInteger("sizeLimit"); 141 timeLimit = getNamedValueAsInteger("timeLimit"); 142 typesOnly = getNamedValueAsBoolean("typesOnly"); 143 144 SearchScope ss = null; 145 try 146 { 147 ss = SearchScope.definedValueOf(getNamedValueAsInteger("scope")); 148 } 149 catch (final Exception e) 150 { 151 Debug.debugException(e); 152 } 153 scope = ss; 154 155 DereferencePolicy deref = null; 156 final String derefStr = getNamedValue("deref"); 157 if (derefStr != null) 158 { 159 for (final DereferencePolicy p : DereferencePolicy.values()) 160 { 161 if (p.getName().equalsIgnoreCase(derefStr)) 162 { 163 deref = p; 164 break; 165 } 166 } 167 } 168 derefPolicy = deref; 169 170 final String attrStr = getNamedValue("attrs"); 171 if (attrStr == null) 172 { 173 requestedAttributes = null; 174 } 175 else if (attrStr.equals("ALL")) 176 { 177 requestedAttributes = Collections.emptyList(); 178 } 179 else 180 { 181 final LinkedList<String> attrs = new LinkedList<>(); 182 final StringTokenizer st = new StringTokenizer(attrStr, ",", false); 183 while (st.hasMoreTokens()) 184 { 185 attrs.add(st.nextToken()); 186 } 187 requestedAttributes = Collections.unmodifiableList(attrs); 188 } 189 } 190 191 192 193 /** 194 * Retrieves the base DN for the search request. 195 * 196 * @return The base DN for the search request, or {@code null} if it is not 197 * included in the log message. 198 */ 199 public final String getBaseDN() 200 { 201 return baseDN; 202 } 203 204 205 206 /** 207 * Retrieves the scope for the search request. 208 * 209 * @return The scope for the search request, or {@code null} if it is not 210 * included in the log message. 211 */ 212 public final SearchScope getScope() 213 { 214 return scope; 215 } 216 217 218 219 /** 220 * Retrieves a string representation of the filter for the search request. 221 * 222 * @return A string representation of the filter for the search request, or 223 * {@code null} if it is not included in the log message. 224 */ 225 public final String getFilter() 226 { 227 return filter; 228 } 229 230 231 232 /** 233 * Retrieves a parsed representation of the filter for the search request. 234 * 235 * @return A parsed representation of the filter for the search request, or 236 * {@code null} if it is not included in the log message or the 237 * filter string cannot be parsed as a filter. 238 */ 239 public final Filter getParsedFilter() 240 { 241 try 242 { 243 if (filter == null) 244 { 245 return null; 246 } 247 else 248 { 249 return Filter.create(filter); 250 } 251 } 252 catch (final Exception e) 253 { 254 Debug.debugException(e); 255 return null; 256 } 257 } 258 259 260 261 /** 262 * Retrieves the dereference policy for the search request. 263 * 264 * @return The dereference policy for the search request, or {@code null} if 265 * it is not included in the log message or the value cannot be 266 * parsed as a valid {@code DereferencePolicy} value. 267 */ 268 public final DereferencePolicy getDereferencePolicy() 269 { 270 return derefPolicy; 271 } 272 273 274 275 /** 276 * Retrieves the size limit for the search request. 277 * 278 * @return The size limit for the search request, or {@code null} if it is 279 * not included in the log message or the value cannot be parsed as 280 * an integer. 281 */ 282 public final Integer getSizeLimit() 283 { 284 return sizeLimit; 285 } 286 287 288 289 /** 290 * Retrieves the time limit for the search request. 291 * 292 * @return The time limit for the search request, or {@code null} if it is 293 * not included in the log message or the value cannot be parsed as 294 * an integer. 295 */ 296 public final Integer getTimeLimit() 297 { 298 return timeLimit; 299 } 300 301 302 303 /** 304 * Retrieves the typesOnly value for the search request. 305 * 306 * @return {@code true} if only attribute type names should be included in 307 * entries that are returned, {@code false} if both attribute types 308 * and values should be returned, or {@code null} if is not included 309 * in the log message or cannot be parsed as a Boolean. 310 */ 311 public final Boolean typesOnly() 312 { 313 return typesOnly; 314 } 315 316 317 318 /** 319 * Retrieves the list of requested attributes for the search request. 320 * 321 * @return The list of requested attributes for the search request, an empty 322 * list if the client did not explicitly request any attributes, or 323 * {@code null} if it is not included in the log message. 324 */ 325 public final List<String> getRequestedAttributes() 326 { 327 return requestedAttributes; 328 } 329 330 331 332 /** 333 * {@inheritDoc} 334 */ 335 @Override() 336 public final AccessLogOperationType getOperationType() 337 { 338 return AccessLogOperationType.SEARCH; 339 } 340}