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