001/*
002 * Copyright 2009-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
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 */
021package com.unboundid.ldap.sdk.unboundidds.logs;
022
023
024
025import java.util.ArrayList;
026import java.util.Collections;
027import java.util.LinkedList;
028import java.util.List;
029import java.util.StringTokenizer;
030
031import com.unboundid.util.NotMutable;
032import com.unboundid.util.ThreadSafety;
033import com.unboundid.util.ThreadSafetyLevel;
034
035
036
037/**
038 * This class provides a data structure that holds information about a log
039 * message that may appear in the Directory Server access log about a search
040 * result entry returned to a client.
041 * <BR>
042 * <BLOCKQUOTE>
043 *   <B>NOTE:</B>  This class, and other classes within the
044 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
045 *   supported for use against Ping Identity, UnboundID, and
046 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
047 *   for proprietary functionality or for external specifications that are not
048 *   considered stable or mature enough to be guaranteed to work in an
049 *   interoperable way with other types of LDAP servers.
050 * </BLOCKQUOTE>
051 */
052@NotMutable()
053@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
054public final class SearchEntryAccessLogMessage
055       extends SearchRequestAccessLogMessage
056{
057  /**
058   * The serial version UID for this serializable class.
059   */
060  private static final long serialVersionUID = 6423635071693560277L;
061
062
063
064  // The names of the attributes included in the entry that was returned.
065  private final List<String> attributesReturned;
066
067  // The list of response control OIDs for the operation.
068  private final List<String> responseControlOIDs;
069
070  // The DN of the entry returned.
071  private final String dn;
072
073
074
075  /**
076   * Creates a new search result entry access log message from the provided
077   * message string.
078   *
079   * @param  s  The string to be parsed as a search result entry access log
080   *            message.
081   *
082   * @throws  LogException  If the provided string cannot be parsed as a valid
083   *                        log message.
084   */
085  public SearchEntryAccessLogMessage(final String s)
086         throws LogException
087  {
088    this(new LogMessage(s));
089  }
090
091
092
093  /**
094   * Creates a new search result entry access log message from the provided log
095   * message.
096   *
097   * @param  m  The log message to be parsed as a search entry access log
098   *            message.
099   */
100  public SearchEntryAccessLogMessage(final LogMessage m)
101  {
102    super(m);
103
104    dn = getNamedValue("dn");
105
106    final String controlStr = getNamedValue("responseControls");
107    if (controlStr == null)
108    {
109      responseControlOIDs = Collections.emptyList();
110    }
111    else
112    {
113      final LinkedList<String> controlList = new LinkedList<>();
114      final StringTokenizer t = new StringTokenizer(controlStr, ",");
115      while (t.hasMoreTokens())
116      {
117        controlList.add(t.nextToken());
118      }
119      responseControlOIDs = Collections.unmodifiableList(controlList);
120    }
121
122    final String attrs = getNamedValue("attrsReturned");
123    if (attrs == null)
124    {
125      attributesReturned = null;
126    }
127    else
128    {
129      final ArrayList<String> l = new ArrayList<>(10);
130      final StringTokenizer tokenizer = new StringTokenizer(attrs, ",");
131      while (tokenizer.hasMoreTokens())
132      {
133        l.add(tokenizer.nextToken());
134      }
135
136      attributesReturned = Collections.unmodifiableList(l);
137    }
138  }
139
140
141
142  /**
143   * Retrieves the DN of the entry returned to the client.
144   *
145   * @return  The DN of the entry returned to the client, or {@code null} if it
146   *          is not included in the log message.
147   */
148  public String getDN()
149  {
150    return dn;
151  }
152
153
154
155  /**
156   * Retrieves the names of the attributes included in the entry that was
157   * returned.
158   *
159   * @return  The names of the attributes included in the entry that was
160   *          returned, or {@code null} if it is not included in the log
161   *          message.
162   */
163  public List<String> getAttributesReturned()
164  {
165    return attributesReturned;
166  }
167
168
169
170  /**
171   * Retrieves the OIDs of any response controls contained in the log message.
172   *
173   * @return  The OIDs of any response controls contained in the log message, or
174   *          an empty list if it is not included in the log message.
175   */
176  public List<String> getResponseControlOIDs()
177  {
178    return responseControlOIDs;
179  }
180
181
182
183  /**
184   * {@inheritDoc}
185   */
186  @Override()
187  public AccessLogMessageType getMessageType()
188  {
189    return AccessLogMessageType.ENTRY;
190  }
191}