long start = System.currentTimeMillis();
DirContext ctx = null;
try {
ctx = getContext();
} catch ( ServiceConnectionFailedException e ) {
throw new ServiceAccessException(this, e);
}
Uri parentUri = uri.getParentUri();
String objectName = getObjectNameFromUri( uri );
Vector parentBindings = new Vector();
Vector childBindings = new Vector();
// As long as this node isn't the root node create a parent binding.
// This doesn't appear to do anything, but just in case.
if ( !uri.toString().equals( "/" ) ) {
parentBindings.add( new ObjectNode.Binding( objectName, parentUri.toString() ) );
}
SearchControls controls = new SearchControls();
controls.setSearchScope( searchScope );
// If the uri matches the scope create a SubjectNode with bindings for all
// of the results from a jndi search
if ( uri.isStoreRoot() ) {
try {
NamingEnumeration results = ctx.search(
container,
filter,
controls );
if ( !results.hasMore() ) {
getLogger().log(
name + ": No objects found in container " + container +
" that match filter " + filter + ".",
LOG_CHANNEL,
Logger.WARNING );
}
while ( results.hasMore() ) {
SearchResult result = null;
try {
result = (SearchResult)results.next();
} catch ( NamingException e ) {
getLogger().log(
name + ": Error getting next search result.",
e, LOG_CHANNEL, Logger.ERROR );
}
String name = result.getName();
if ( !validatePathName( name ) ) {
continue;
}
String value = parseLdapName(name);
if (principalNameAttribute != null) {
String uriValue = ((String)result.getAttributes().get(principalNameAttribute).get()).toLowerCase();
objectNameMap.put(uriValue, value);
value = uriValue;
}
getLogger().log(
name + ": Creating child binding \"" + value + "\" for \"" +
uri.toString() + "\".",
LOG_CHANNEL, Logger.DEBUG );
childBindings.add(
new ObjectNode.Binding( value, uri.toString() + "/" + value ) );
}
} catch ( NamingException e ) {
getLogger().log(
name + ": Error during search.",
e, LOG_CHANNEL, Logger.ERROR );
}
} else {
// If the uri matches the scope + something try to do a lookup
// of the "+ something" in LDAP.
try {
if (principalNameAttribute != null && objectNameMap.get(objectName) == null)
retrieveObject(parentUri);
NamingEnumeration results = ctx.search(
container,
rdnAttribute + "=" + (principalNameAttribute != null ? (String)objectNameMap.get(objectName) : objectName),
controls);
if ( !results.hasMore() ) {
if (ctx != null) {
closeContext(ctx);
}
throw new ObjectNotFoundException( uri );
}
} catch ( NamingException e ) {
getLogger().log(
name + ": Error retrieving " + uri.toString(),
e, LOG_CHANNEL, Logger.ERROR );
if (ctx != null) {
closeContext(ctx);
}
throw new ServiceAccessException( this, e );
}
}
getLogger().log( name + ": Creating SubjectNode for \"" + uri.toString() + "\".",
LOG_CHANNEL, Logger.DEBUG );