SearchOperationBasis.java revision 7e6345b129555b8ed3ec87d83b42a3cc55b66cf1
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
*/
/**
* This class defines an operation that may be used to locate entries in the
* Directory Server based on a given set of criteria.
*/
public class SearchOperationBasis
extends AbstractOperation
implements PreParseSearchOperation,
{
/**
* The tracer object for the debug logger.
*/
// Indicates whether a search result done response has been sent to the
// client.
private AtomicBoolean responseSent;
// Indicates whether the client is able to handle referrals.
private boolean clientAcceptsReferrals;
// Indicates whether to include the account usable control with search result
// entries.
private boolean includeUsableControl;
// Indicates whether to only real attributes should be returned.
private boolean realAttributesOnly;
// Indicates whether LDAP subentries should be returned.
private boolean returnLDAPSubentries;
// Indicates whether to include attribute types only or both types and values.
private boolean typesOnly;
// Indicates whether to only virtual attributes should be returned.
private boolean virtualAttributesOnly;
// The raw, unprocessed base DN as included in the request from the client.
private ByteString rawBaseDN;
// The dereferencing policy for the search operation.
private DereferencePolicy derefPolicy;
// The base DN for the search operation.
// The proxied authorization target DN for this operation.
private DN proxiedAuthorizationDN;
// The number of entries that have been sent to the client.
private int entriesSent;
// The number of search result references that have been sent to the client.
private int referencesSent;
// The size limit for the search operation.
private int sizeLimit;
// The time limit for the search operation.
private int timeLimit;
// The raw, unprocessed filter as included in the request from the client.
// The set of attributes that should be returned in matching entries.
// The set of response controls for this search operation.
// The time that processing started on this operation.
private long processingStartTime;
// The time that processing ended on this operation.
private long processingStopTime;
// The time that the search time limit has expired.
private long timeLimitExpiration;
// The matched values control associated with this search operation.
private MatchedValuesControl matchedValuesControl;
// The search filter for the search operation.
private SearchFilter filter;
// The search scope for the search operation.
private SearchScope scope;
// Indicates wether to send the search result done to the client or not
private boolean sendResponse = true;
/**
* Creates a new search operation with the provided information.
*
* @param clientConnection The client connection with which this operation
* is associated.
* @param operationID The operation ID for this operation.
* @param messageID The message ID of the request with which this
* operation is associated.
* @param requestControls The set of controls included in the request.
* @param rawBaseDN The raw, unprocessed base DN as included in the
* request from the client.
* @param scope The scope for this search operation.
* @param derefPolicy The alias dereferencing policy for this search
* operation.
* @param sizeLimit The size limit for this search operation.
* @param timeLimit The time limit for this search operation.
* @param typesOnly The typesOnly flag for this search operation.
* @param rawFilter the raw, unprocessed filter as included in the
* request from the client.
* @param attributes The requested attributes for this search
* operation.
*/
long operationID,
{
this.derefPolicy = derefPolicy;
if (attributes == null)
{
}
else
{
this.attributes = attributes;
}
{
}
else
{
if (sizeLimit <= 0)
{
}
else
{
}
}
{
}
else
{
if (timeLimit <= 0)
{
}
else
{
}
}
entriesSent = 0;
referencesSent = 0;
clientAcceptsReferrals = true;
includeUsableControl = false;
responseSent = new AtomicBoolean(false);
returnLDAPSubentries = false;
realAttributesOnly = false;
virtualAttributesOnly = false;
}
/**
* Creates a new search operation with the provided information.
*
* @param clientConnection The client connection with which this operation
* is associated.
* @param operationID The operation ID for this operation.
* @param messageID The message ID of the request with which this
* operation is associated.
* @param requestControls The set of controls included in the request.
* @param baseDN The base DN for this search operation.
* @param scope The scope for this search operation.
* @param derefPolicy The alias dereferencing policy for this search
* operation.
* @param sizeLimit The size limit for this search operation.
* @param timeLimit The time limit for this search operation.
* @param typesOnly The typesOnly flag for this search operation.
* @param filter The filter for this search operation.
* @param attributes The attributes for this search operation.
*/
long operationID,
{
this.derefPolicy = derefPolicy;
if (attributes == null)
{
}
else
{
this.attributes = attributes;
}
{
}
else
{
if (sizeLimit <= 0)
{
}
else
{
}
}
{
}
else
{
if (timeLimit <= 0)
{
}
else
{
}
}
entriesSent = 0;
referencesSent = 0;
clientAcceptsReferrals = true;
includeUsableControl = false;
responseSent = new AtomicBoolean(false);
returnLDAPSubentries = false;
}
/**
* {@inheritDoc}
*/
public final ByteString getRawBaseDN()
{
return rawBaseDN;
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
try
{
{
}
}
catch (DirectoryException de)
{
if (debugEnabled())
{
}
}
return baseDN;
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public final SearchScope getScope()
{
return scope;
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public final DereferencePolicy getDerefPolicy()
{
return derefPolicy;
}
/**
* {@inheritDoc}
*/
{
this.derefPolicy = derefPolicy;
}
/**
* {@inheritDoc}
*/
public final int getSizeLimit()
{
return sizeLimit;
}
/**
* {@inheritDoc}
*/
public final void setSizeLimit(int sizeLimit)
{
}
/**
* {@inheritDoc}
*/
public final int getTimeLimit()
{
return timeLimit;
}
/**
* {@inheritDoc}
*/
public final void setTimeLimit(int timeLimit)
{
}
/**
* {@inheritDoc}
*/
public final boolean getTypesOnly()
{
return typesOnly;
}
/**
* {@inheritDoc}
*/
public final void setTypesOnly(boolean typesOnly)
{
}
/**
* {@inheritDoc}
*/
public final RawFilter getRawFilter()
{
return rawFilter;
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public final SearchFilter getFilter()
{
try
{
{
}
}
catch (DirectoryException de)
{
if (debugEnabled())
{
}
}
return filter;
}
/**
* {@inheritDoc}
*/
{
return attributes;
}
/**
* {@inheritDoc}
*/
{
if (attributes == null)
{
this.attributes.clear();
}
else
{
this.attributes = attributes;
}
}
/**
* {@inheritDoc}
*/
public final int getEntriesSent()
{
return entriesSent;
}
/**
* {@inheritDoc}
*/
public final int getReferencesSent()
{
return referencesSent;
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
boolean evaluateAci)
{
boolean typesOnly = getTypesOnly();
// See if the size limit has been exceeded. If so, then don't send the
// entry and indicate that the search should end.
{
return false;
}
// See if the time limit has expired. If so, then don't send the entry and
// indicate that the search should end.
{
return false;
}
// Determine whether the provided entry is a subentry and if so whether it
// should be returned.
if (entry.isLDAPSubentry())
{
(! isReturnLDAPSubentries()))
{
// Check to see if the filter contains an equality element with the
// objectclass attribute type and a value of "ldapSubentry". If so,
// then we'll return it anyway. Technically, this isn't part of the
// specification so we don't need to get carried away with really in
// depth checks. Just do best effort for earlier draft compatibility.
if (! isReturnLDAPSubentries())
{
// We still shouldn't return it even based on the filter.
// Just throw it away without doing anything.
return true;
}
}
}
else
{
if (isReturnLDAPSubentries())
{
// Subentries are visible and normal entries are not.
return true;
}
}
// Determine whether to include the account usable control. If so, then
// create it now.
if (isIncludeUsableControl())
{
try
{
// FIXME -- Need a way to enable PWP debugging.
{
{
}
}
else
{
{
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
// Check to see if the entry can be read by the client.
if (evaluateAci)
{
controls);
return true;
}
}
// Make a copy of the entry and pare it down to only include the set
// of requested attributes.
// NOTE: that this copy will include the objectClass attribute.
// If there is a matched values control, then further pare down the entry
// based on the filters that it contains.
{
// First, look at the set of objectclasses.
// NOTE: the objectClass attribute is also present and must be
// dealt with later.
while (ocIterator.hasNext())
{
AttributeValue v =
{
ocIterator.remove();
}
}
// Next, the set of user attributes (incl. objectClass attribute).
.getUserAttributes().entrySet())
{
AttributeType t = e.getKey();
for (Attribute a : oldAttributes)
{
// Assume that the attribute will be either empty or contain
// very few values.
for (AttributeValue v : a)
{
if (matchedValuesControl.valueMatches(t, v))
{
}
}
}
}
// Then the set of operational attributes.
{
AttributeType t = e.getKey();
for (Attribute a : oldAttributes)
{
// Assume that the attribute will be either empty or contain
// very few values.
for (AttributeValue v : a)
{
if (matchedValuesControl.valueMatches(t, v))
{
}
}
}
}
}
// Convert the provided entry to a search result entry.
controls);
// Strip out any attributes that the client does not have access to.
// FIXME: need some way to prevent plugins from adding attributes or
// values that the client is not permitted to see.
if (evaluateAci)
{
}
// Invoke any search entry plugins that may be registered with the server.
// Send the entry to the client.
if (pluginResult.sendResponse())
{
try
{
// Log the entry sent to the client.
logSearchResultEntry(this, searchEntry);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
}
return false;
}
}
return pluginResult.continueProcessing();
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
boolean evaluateAci)
{
// See if the time limit has expired. If so, then don't send the entry and
// indicate that the search should end.
{
return false;
}
// See if we know that this client can't handle referrals. If so, then
// don't even try to send it.
if (! isClientAcceptsReferrals())
{
return true;
}
// See if the client has permission to read this reference.
if (evaluateAci)
{
return true;
}
}
// Invoke any search reference plugins that may be registered with the
// server.
// Send the reference to the client. Note that this could throw an
// exception, which would indicate that the associated client can't handle
// referrals. If that't the case, then set a flag so we'll know not to try
// to send any more.
if (pluginResult.sendResponse())
{
try
{
if (sendSearchReference(reference))
{
// Log the entry sent to the client.
logSearchResultReference(this, reference);
// FIXME -- Should the size limit apply here?
}
else
{
// We know that the client can't handle referrals, so we won't try to
// send it any more.
setClientAcceptsReferrals(false);
}
}
catch (DirectoryException de)
{
if (debugEnabled())
{
}
return false;
}
}
return pluginResult.continueProcessing();
}
/**
* {@inheritDoc}
*/
public final void sendSearchResultDone()
{
// Send the search result done message to the client. We want to make sure
// that this only gets sent once, and it's possible that this could be
// multithreaded in the event of a persistent search, so do it safely.
if (responseSent.compareAndSet(false, true))
{
// Send the response to the client.
clientConnection.sendResponse(this);
// Log the search result.
logSearchResultDone(this);
// Invoke the post-response search plugins.
}
}
/**
* {@inheritDoc}
*/
@Override()
public final OperationType getOperationType()
{
// Note that no debugging will be done in this method because it is a likely
// candidate for being called by the logging subsystem.
return OperationType.SEARCH;
}
/**
* {@inheritDoc}
*/
@Override()
public final String[][] getRequestLogElements()
{
// Note that no debugging will be done in this method because it is a likely
// candidate for being called by the logging subsystem.
{
}
else
{
{
}
}
return new String[][]
{
};
}
/**
* {@inheritDoc}
*/
@Override()
public final String[][] getResponseLogElements()
{
// Note that no debugging will be done in this method because it is a likely
// candidate for being called by the logging subsystem.
if (errorMessageBuffer == null)
{
errorMessage = null;
}
else
{
}
{
matchedDNStr = null;
}
else
{
}
{
}
else
{
{
}
}
return new String[][]
{
new String[] { LOG_ELEMENT_REFERENCES_SENT,
};
}
/**
* {@inheritDoc}
*/
public DN getProxiedAuthorizationDN()
{
return proxiedAuthorizationDN;
}
/**
* {@inheritDoc}
*/
@Override()
{
return responseControls;
}
/**
* {@inheritDoc}
*/
@Override()
{
}
/**
* {@inheritDoc}
*/
@Override()
{
}
/**
* {@inheritDoc}
*/
@Override()
{
{
this.cancelRequest = cancelRequest;
}
}
/**
* {@inheritDoc}
*/
@Override()
{
}
/**
* {@inheritDoc}
*/
}
/**
* {@inheritDoc}
*/
public boolean isReturnLDAPSubentries()
{
return returnLDAPSubentries;
}
/**
* {@inheritDoc}
*/
public void setReturnLDAPSubentries(boolean returnLDAPSubentries)
{
}
/**
* {@inheritDoc}
*/
{
return matchedValuesControl;
}
/**
* {@inheritDoc}
*/
{
this.matchedValuesControl = controls;
}
/**
* {@inheritDoc}
*/
public boolean isIncludeUsableControl()
{
return includeUsableControl;
}
/**
* {@inheritDoc}
*/
public void setIncludeUsableControl(boolean includeUsableControl)
{
}
/**
* {@inheritDoc}
*/
public Long getTimeLimitExpiration()
{
return timeLimitExpiration;
}
/**
* {@inheritDoc}
*/
public boolean isClientAcceptsReferrals()
{
return clientAcceptsReferrals;
}
/**
* {@inheritDoc}
*/
public void setClientAcceptsReferrals(boolean clientAcceptReferrals)
{
}
/**
* {@inheritDoc}
*/
public void incrementEntriesSent()
{
entriesSent++;
}
/**
* {@inheritDoc}
*/
public void incrementReferencesSent()
{
}
/**
* {@inheritDoc}
*/
public boolean isSendResponse()
{
return sendResponse;
}
/**
* {@inheritDoc}
*/
public void setSendResponse(boolean sendResponse)
{
this.sendResponse = sendResponse;
}
/**
* {@inheritDoc}
*/
public boolean isRealAttributesOnly()
{
return this.realAttributesOnly;
}
/**
* {@inheritDoc}
*/
public boolean isVirtualAttributesOnly()
{
return this.virtualAttributesOnly;
}
/**
* {@inheritDoc}
*/
public void setRealAttributesOnly(boolean realAttributesOnly)
{
this.realAttributesOnly = realAttributesOnly;
}
/**
* {@inheritDoc}
*/
public void setVirtualAttributesOnly(boolean virtualAttributesOnly)
{
}
/**
* {@inheritDoc}
*/
throws DirectoryException
{
}
/**
* {@inheritDoc}
*/
throws DirectoryException
{
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public final void run()
{
// Start the processing timer.
// Log the search request message.
logSearchRequest(this);
setSendResponse(true);
// Get the plugin config manager that will be used for invoking plugins.
int timeLimit = getTimeLimit();
if (timeLimit <= 0)
{
}
else
{
// FIXME -- Factor in the user's effective time limit.
}
try
{
// Check for and handle a request to cancel this operation.
checkIfCanceled(false);
if(!preParseResult.continueProcessing())
{
return;
}
// Check for and handle a request to cancel this operation.
checkIfCanceled(false);
// Process the search base and filter to convert them from their raw forms
// as provided by the client to the forms required for the rest of the
// search processing.
return;
}
// Retrieve the network group attached to the client connection
// and get a workflow to process the operation.
{
// We have found no workflow for the requested base DN, just return
// a no such entry result code and stop the processing.
return;
}
}
catch(CanceledOperationException coe)
{
if (debugEnabled())
{
}
}
finally
{
// Stop the processing timer.
{
// If everything is successful to this point and it is not a persistent
// search, then send the search result done message to the client.
// Otherwise, we'll want to make the size and time limit values
// unlimited to ensure that the remainder of the persistent search
// isn't subject to those restrictions.
if (isSendResponse())
{
}
else
{
setSizeLimit(0);
setTimeLimit(0);
}
}
else if(cancelRequest.notifyOriginalRequestor() ||
{
}
// If no cancel result, set it
if(cancelResult == null)
{
}
}
}
/**
* Invokes the post response plugins.
*/
private void invokePostResponsePlugins()
{
// Get the plugin config manager that will be used for invoking plugins.
// Invoke the post response plugins that have been registered with
// the current operation
}
/**
* Updates the error message and the result code of the operation.
*
* This method is called because no workflows were found to process
* the operation.
*/
private void updateOperationErrMsgAndResCode()
{
}
/**
* Checks if the filter contains an equality element with the
* objectclass attribute type and a value of "ldapSubentry"
* and if so sets returnLDAPSubentries to <code>true</code>.
*
* @param filter The complete filter being checked, of which
* this filter may be a subset.
* @param depth The current depth of the evaluation, which
* is used to prevent infinite recursion due
* to highly nested filters and eventually
* running out of stack space.
*/
{
// Paranoid check to avoid recursion deep enough to provoke
// the stack overflow. This should never happen because if
// a given filter is too nested SearchFilter exception gets
// raised long before this method is invoked.
if (depth >= MAX_NESTED_FILTER_DEPTH)
{
if (debugEnabled())
{
}
return;
}
switch (filter.getFilterType())
{
case EQUALITY:
{
{
setReturnLDAPSubentries(true);
}
}
break;
case AND:
case OR:
{
if (isReturnLDAPSubentries())
{
// No point in continuing.
break;
}
}
break;
}
}
}