Fix for DIRSERVER-2133
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/AttributeTypeProvider.java b/core-api/src/main/java/org/apache/directory/server/core/api/AttributeTypeProvider.java
index eeedc77..bb55288 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/AttributeTypeProvider.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/AttributeTypeProvider.java
@@ -55,6 +55,7 @@
private final AttributeType userPassword;
private final AttributeType nbChildren;
private final AttributeType nbSubordinates;
+ private final AttributeType hasSubordinates;
private final AttributeType[] subentryOperationalAttributes;
@@ -86,6 +87,7 @@
userPassword = schemaManager.getAttributeType( SchemaConstants.USER_PASSWORD_AT_OID );
nbChildren = schemaManager.getAttributeType( ApacheSchemaConstants.NB_CHILDREN_OID );
nbSubordinates = schemaManager.getAttributeType( ApacheSchemaConstants.NB_SUBORDINATES_OID );
+ hasSubordinates = schemaManager.getAttributeType( SchemaConstants.HAS_SUBORDINATES_AT );
subentryOperationalAttributes = new AttributeType[]
{
@@ -295,6 +297,15 @@
}
+ /**
+ * @return the operational attributes of a hasSubordinates
+ */
+ public AttributeType getHasSubordinates()
+ {
+ return hasSubordinates;
+ }
+
+
/**
* @return the <code>userPassword</code> {@link AttributeType}.
*/
diff --git a/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java b/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
index 0039658..9599fe7 100644
--- a/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
+++ b/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
@@ -2145,4 +2145,39 @@
assertEquals(3, count);
cursor.close();
}
+
+
+ @Test
+ public void testSearchSubordinates() throws Exception
+ {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ controls.setDerefLinkFlag( false );
+ controls.setReturningAttributes( new String[]
+ { "+", "*" } );
+ sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
+ .getJndiValue() );
+ HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+
+ NamingEnumeration<SearchResult> list = sysRoot.search( "ou=testing01", "(ObjectClass=*)", controls );
+
+ while ( list.hasMore() )
+ {
+ SearchResult result = list.next();
+ map.put( result.getName(), result.getAttributes() );
+ }
+
+ list.close();
+
+ assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+
+ Attributes attrs = map.get( "ou=testing01,ou=system" );
+
+ assertNotNull( attrs.get( "createTimestamp" ) );
+ assertNotNull( attrs.get( "creatorsName" ) );
+ assertNotNull( attrs.get( "objectClass" ) );
+ assertNotNull( attrs.get( "ou" ) );
+ assertNotNull( attrs.get( "hasSubordinates" ) );
+ assertEquals( "TRUE", attrs.get( "hasSubordinates" ).get() );
+ }
}
diff --git a/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java b/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
index 1576c97..b0cca73 100644
--- a/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
+++ b/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
@@ -674,11 +674,14 @@
AttributeTypeOptions nbChildrenAto = new AttributeTypeOptions( nbChildrenAt );
AttributeType nbSubordinatesAt = directoryService.getAtProvider().getNbSubordinates();
AttributeTypeOptions nbSubordinatesAto = new AttributeTypeOptions( nbSubordinatesAt );
+ AttributeType hasSubordinatesAt = directoryService.getAtProvider().getHasSubordinates();
+ AttributeTypeOptions hasSubordinatesAto = new AttributeTypeOptions( hasSubordinatesAt );
if ( returningAttributes != null )
{
boolean nbChildrenRequested = returningAttributes.contains( nbChildrenAto ) || allAttributes;
boolean nbSubordinatesRequested = returningAttributes.contains( nbSubordinatesAto ) || allAttributes;
+ boolean hasSubordinatesRequested = returningAttributes.contains( hasSubordinatesAto ) || allAttributes;
if ( nbChildrenRequested || nbSubordinatesRequested )
{
@@ -699,6 +702,15 @@
entry.add( new DefaultAttribute( nbSubordinatesAt,
Long.toString( nbSubordinates ) ) );
}
+
+ if ( hasSubordinatesRequested )
+ {
+ entry.add( new DefaultAttribute( hasSubordinatesAt, "TRUE" ) );
+ }
+ else
+ {
+ entry.add( new DefaultAttribute( hasSubordinatesAt, "FALSE" ) );
+ }
}
}
}