NodeRefresher.java revision 53c7e80ef538191e3492cc9324c600e166c57a92
/*
* 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 legal-notices/CDDLv1_0.txt
* 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 legal-notices/CDDLv1_0.txt.
* 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 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS
*/
/**
* The class that is in charge of doing the LDAP searches required to update a
* node: search the local entry, detect if it has children, retrieve the
* attributes required to render the node, etc.
*/
public class NodeRefresher extends AbstractNodeTask {
/** The enumeration containing all the states the refresher can have. */
public enum State
{
/** The refresher is queued, but not started. */
/** The refresher is reading the local entry. */
/** The refresher is solving a referral. */
/** The refresher is detecting whether the entry has children or not. */
/** The refresher is searching for the children of the entry. */
/** The refresher is finished. */
/** The refresher is cancelled. */
/** The refresher has been interrupted. */
/** The refresher has failed. */
}
boolean recursive;
boolean isLeafNode;
final boolean differential;
/**
* The constructor of the refresher object.
* @param node the node on the tree to be updated.
* @param ctlr the BrowserController.
* @param localEntry the local entry corresponding to the node.
* @param recursive whether this task is recursive or not (children must be searched).
*/
super(node);
controller = ctlr;
this.localEntry = localEntry;
differential = false;
}
/**
* Returns the local entry the refresher is handling.
* @return the local entry the refresher is handling.
*/
public SearchResult getLocalEntry() {
return localEntry;
}
/**
* Returns the remote entry for the node. It will be <CODE>null</CODE> if
* the entry is not a referral.
* @return the remote entry for the node.
*/
public SearchResult getRemoteEntry() {
return remoteEntry;
}
/**
* Returns the URL of the remote entry. It will be <CODE>null</CODE> if
* the entry is not a referral.
* @return the URL of the remote entry.
*/
public LDAPURL getRemoteUrl() {
return remoteUrl;
}
/**
* Tells whether the node is a leaf or not.
* @return <CODE>true</CODE> if the node is a leaf and <CODE>false</CODE>
* otherwise.
*/
public boolean isLeafNode() {
return isLeafNode;
}
/**
* Returns the child entries of the node.
* @return the child entries of the node.
*/
return childEntries;
}
/**
* Returns whether this refresher object is working on differential mode or
* not.
* @return <CODE>true</CODE> if the refresher is working on differential
* mode and <CODE>false</CODE> otherwise.
*/
public boolean isDifferential() {
return differential;
}
/**
* Returns the exception that occurred during the processing. It returns
* <CODE>null</CODE> if no exception occurred.
* @return the exception that occurred during the processing.
*/
public Exception getException() {
return exception;
}
/**
* Returns the argument of the exception that occurred during the processing.
* It returns <CODE>null</CODE> if no exception occurred or if the exception
* has no arguments.
* @return the argument exception that occurred during the processing.
*/
public Object getExceptionArg() {
return exceptionArg;
}
/**
* Returns the displayed entry in the browser. This depends on the
* visualization options in the BrowserController.
* @return the remote entry if the entry is a referral and the
* BrowserController is following referrals and the local entry otherwise.
*/
public SearchResult getDisplayedEntry() {
{
}
else {
result = localEntry;
}
return result;
}
/**
* Returns the LDAP URL of the displayed entry in the browser. This depends
* on the visualization options in the BrowserController.
* @return the remote entry LDAP URL if the entry is a referral and the
* BrowserController is following referrals and the local entry LDAP URL
* otherwise.
*/
public LDAPURL getDisplayedUrl() {
{
}
else {
}
return result;
}
/**
* Returns whether the refresh is over or not.
* @return <CODE>true</CODE> if the refresh is over and <CODE>false</CODE>
* otherwise.
*/
public boolean isInFinalState() {
return state == State.FINISHED || state == State.CANCELLED || state == State.FAILED || state == State.INTERRUPTED;
}
/** The method that actually does the refresh. */
public void run() {
try {
boolean checkExpand = false;
if (localEntry == null) {
}
if (!isInFinalState()) {
}
}
/* If the node is not expanded, we have to refresh its children when we expand it */
node.setRefreshNeededOnExpansion(true);
checkExpand = true;
}
{
{
public void run()
{
}
});
}
}
}
catch (NamingException ne)
{
exceptionArg = null;
}
catch(SearchAbandonException x) {
exception = x.getException();
exceptionArg = x.getArg();
try {
changeStateTo(x.getState());
}
catch(SearchAbandonException xx) {
// We've done all what we can...
}
}
}
/**
* Tells whether a custom filter is being used (specified by the user in the
* browser dialog) or not.
* @return <CODE>true</CODE> if a custom filter is being used and
* <CODE>false</CODE> otherwise.
*/
private boolean useCustomFilter()
{
boolean result=false;
{
result =
}
return result;
}
/**
* Performs the search in the case the user specified a custom filter.
* @param node the parent node we perform the search from.
* @param ctx the connection to be used.
* @throws NamingException if a problem occurred.
*/
throws NamingException
{
ctls);
try
{
if (!s.hasMore())
{
}
while (s.hasMore())
{
s.next();
}
}
catch (SizeLimitExceededException slme)
{
// We are just searching for an entry, but if there is more than one
// this exception will be thrown. We call sr.hasMore after the
// first entry has been retrieved to avoid sending a systematic
// abandon when closing the s NamingEnumeration.
// See CR 6976906.
}
finally
{
s.close();
}
}
/**
* Performs the search in the case the user specified a custom filter.
* @param dn the parent DN we perform the search from.
* @param ctx the connection to be used.
* @throws NamingException if a problem occurred.
*/
throws NamingException
{
ctls);
try
{
if (!s.hasMore())
{
}
while (s.hasMore())
{
s.next();
}
}
catch (SizeLimitExceededException slme)
{
// We are just searching for an entry, but if there is more than one
// this exception will be thrown. We call sr.hasMore after the
// first entry has been retrieved to avoid sending a systematic
// abandon when closing the s NamingEnumeration.
// See CR 6976906.
}
finally
{
s.close();
}
}
/** Read the local entry associated to the current node. */
private void runReadLocalEntry() throws SearchAbandonException {
try {
if (useCustomFilter())
{
// Check that the entry verifies the filter
}
ctls);
try
{
while (s.hasMore())
{
localEntry = s.next();
}
}
finally
{
s.close();
}
if (localEntry == null) {
/* Not enough rights to read the entry or the entry simply does not exist */
}
} else {
}
}
catch(NamingException x) {
}
finally {
}
}
}
/**
* Solve the referral associated to the current node.
* This routine assumes that node.getReferral() is non null
* and that BrowserController.getFollowReferrals() == true.
* It also protect the browser against looping referrals by
* limiting the number of hops.
* @throws SearchAbandonException if the hop count limit for referrals has
* been exceeded.
* @throws NamingException if an error occurred searching the entry.
*/
private void runSolveReferral()
throws SearchAbandonException, NamingException {
int hopCount = 0;
{
hopCount++;
}
{
}
}
/**
* Searches for the remote entry.
* @param referral the referral list to be used to search the remote entry.
* @throws SearchAbandonException if an error occurs.
*/
throws SearchAbandonException {
int i = 0;
{
try {
{
// Use the local server connection.
}
{
/* The referral has not a target DN specified: we
have to use the DN of the entry that contains the
referral... */
if (remoteEntry != null) {
} else {
}
/* We have to recreate the url including the target DN we are using */
url.getExtensions());
}
{
// Check that the entry verifies the filter
}
ctls);
try
{
boolean found = false;
{
{
}
else
{
}
found = true;
}
if (!found)
{
throw new NameNotFoundException();
}
}
catch (SizeLimitExceededException sle)
{
// We are just searching for an entry, but if there is more than one
// this exception will be thrown. We call sr.hasMore after the
// first entry has been retrieved to avoid sending a systematic
// abandon when closing the sr NamingEnumeration.
// See CR 6976906.
}
finally
{
}
}
catch (InterruptedNamingException x) {
}
catch (NamingException | DirectoryException x) {
lastException = x;
lastExceptionArg = referral[i];
}
finally {
}
}
i = i + 1;
}
throw new SearchAbandonException(
}
else
{
{
// The URL is to be transformed: the code assumes that the URL points
// to the remote entry.
}
remoteEntry = entry;
}
}
/**
* Tells whether the provided node must be automatically expanded or not.
* This is used when the user provides a custom filter, in this case we
* expand automatically the tree.
* @param node the node to analyze.
* @return <CODE>true</CODE> if the node must be expanded and
* <CODE>false</CODE> otherwise.
*/
{
boolean mustAutomaticallyExpand = false;
if (controller.isAutomaticExpand())
{
// Limit the number of expansion levels to 3
int nLevels = 0;
{
nLevels ++;
}
}
return mustAutomaticallyExpand;
}
/**
* Detects whether the entries has children or not.
* @throws SearchAbandonException if the search was abandoned.
* @throws NamingException if an error during the search occurred.
*/
private void runDetectChildren()
throws SearchAbandonException, NamingException {
}
else {
}
}
/**
* Detects whether the entry has children by performing a search using the
* entry as base DN.
* @throws SearchAbandonException if there is an error.
*/
private void runDetectChildrenManually() throws SearchAbandonException {
try {
// We set the search constraints so that only one entry is returned.
// It's enough to know if the entry has children or not.
if (useCustomFilter())
{
}
else
{
}
// Send an LDAP search
ctls);
isLeafNode = true;
// Check if parentNode has children
while (searchResults.hasMoreElements()) {
isLeafNode = false;
}
}
catch (SizeLimitExceededException e)
{
// We are just searching for an entry, but if there is more than one
// this exception will be thrown. We call sr.hasMore after the
// first entry has been retrieved to avoid sending a systematic
// abandon when closing the searchResults NamingEnumeration.
// See CR 6976906.
}
catch (NamingException x) {
}
finally {
}
if (searchResults != null)
{
try
{
}
catch (NamingException x)
{
}
}
}
}
/**
* NUMSUBORDINATE HACK
* numsubordinates is not usable if the displayed entry
* is listed in in the hacker.
* Note: *usable* means *usable for detecting children presence*.
*/
private boolean isNumSubOrdinatesUsable() throws NamingException {
if (!hasSubOrdinates)
{
}
// Other values are usable
return true;
}
/**
* Searches for the children.
* @throws SearchAbandonException if an error occurs.
*/
private void runSearchChildren() throws SearchAbandonException {
parentNode.setSizeLimitReached(false);
try {
// Send an LDAP search
if (useCustomFilter())
{
}
else
{
}
int parentComponents;
try
{
}
catch (Throwable t)
{
t);
}
ctls);
try
{
{
{
continue;
}
else
{
}
boolean add = false;
if (useCustomFilter())
{
// Check that is an immediate child: use a faster method by just
// comparing the number of components.
try
{
}
catch (Throwable t)
{
throw new RuntimeException("Error decoding dns: "+t, t);
}
if (!add)
{
// Is not a direct child. Check if the parent has been added,
// if it is the case, do not add the parent. If is not the case,
// search for the parent and add it.
{
}
boolean mustAddParent = true;
{
try
{
{
mustAddParent = false;
break;
}
}
catch (Throwable t)
{
throw new RuntimeException("Error decoding dn: "+
}
}
if (mustAddParent)
{
final boolean resultValue[] = {true};
// Check the children added to the tree
try
{
{
public void run()
{
{
try
{
{
resultValue[0] = false;
break;
}
}
catch (Throwable t)
{
throw new RuntimeException("Error decoding dn: "+
}
}
}
});
}
catch (Throwable t)
{
// Ignore
}
}
if (mustAddParent)
{
}
}
}
else
{
add = true;
}
if (add)
{
childEntries.add(r);
// Time to time we update the display
}
}
}
}
finally
{
}
}
catch (SizeLimitExceededException slee)
{
parentNode.setSizeLimitReached(true);
}
catch (NamingException x) {
}
finally {
{
}
}
}
/**
* Returns the entry for the given dn.
* The code assumes that the request controls are set in the connection.
* @param ctx the connection to be used.
* @param dn the DN of the entry to be searched.
* @throws NamingException if an error occurs.
*/
throws NamingException
{
// Send an LDAP search
ctls);
try
{
{
}
}
finally
{
}
return sr;
}
/** Utilities. */
/**
* Change the state of the task and inform the BrowserController.
* @param newState the new state for the refresher.
*/
try {
}
catch(InterruptedException x) {
}
}
/**
* Transform an exception into a TaskAbandonException.
* If no exception is passed, the routine checks if the task has
* been canceled and throws an TaskAbandonException accordingly.
* @param x the exception.
*/
if (x != null) {
if (x instanceof InterruptedException || x instanceof InterruptedNamingException)
{
}
else {
}
}
else if (isCanceled()) {
}
throw tax;
}
}
/**
* Removes the quotes surrounding the provided name. JNDI can return relative
* names with this format.
* @param name the relative name to be treated.
* @return an String representing the provided relative name without
* surrounding quotes.
*/
{
{
{
}
else
{
}
}
else
{
return name;
}
}
/** DEBUG : Dump the state of the task. */
void dump() {
}
/**
* Checks that the entry's objectClass contains 'referral' and that the
* attribute 'ref' is present.
* @param entry the search result.
* @return <CODE>true</CODE> if the entry's objectClass contains 'referral'
* and the attribute 'ref' is present and <CODE>false</CODE> otherwise.
* @throws NamingException if an error occurs.
*/
boolean result = false;
{
if (isReferral) {
break;
}
}
}
return result;
}
/**
* Returns the scope to be used in a JNDI request based on the information
* of an LDAP URL.
* @param url the LDAP URL.
* @return the scope to be used in a JNDI request.
*/
{
int scope;
{
{
case BASE_OBJECT:
break;
case WHOLE_SUBTREE:
break;
case SUBORDINATES:
break;
case SINGLE_LEVEL:
break;
default:
}
}
else
{
}
return scope;
}
/**
* Returns the filter to be used in a JNDI request based on the information
* of an LDAP URL.
* @param url the LDAP URL.
* @return the filter.
*/
{
{
}
return filter;
}
/**
* Check that there is no loop in terms of DIT (the check basically identifies
* whether we are pointing to an entry above in the same server).
* @param url the URL to the remote entry. It is assumed that the base DN
* of the URL points to the remote entry.
* @param referral the referral used to retrieve the remote entry.
* @throws SearchAbandonException if there is a loop issue (the remoteEntry
* is actually an entry in the same server as the local entry but above in the
* DIT).
*/
{
boolean checkSucceeded = true;
try
{
{
int adminPort =
if (checkSucceeded)
{
int portUserData =
}
}
}
catch (OpenDsException odse)
{
// Ignore
}
if (!checkSucceeded)
{
throw new SearchAbandonException(
}
}
}