You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/07/22 14:35:58 UTC
svn commit: r966621 - in
/directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core:
DefaultDirectoryService.java collective/CollectiveAttributeInterceptor.java
subtree/SubentryInterceptor.java
Author: elecharny
Date: Thu Jul 22 12:35:58 2010
New Revision: 966621
URL: http://svn.apache.org/viewvc?rev=966621&view=rev
Log:
o Added some comments
o Avoided some useless work if the entry does not have any collectivAttribute
o Fixed a bug in the delete() methods in the subentry interceptor
Modified:
directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
Modified: directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=966621&r1=966620&r2=966621&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Thu Jul 22 12:35:58 2010
@@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -92,7 +91,6 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.name.DN;
import org.apache.directory.shared.ldap.name.RDN;
import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
import org.apache.directory.shared.ldap.util.DateUtils;
import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
@@ -806,6 +804,10 @@ public class DefaultDirectoryService imp
while ( cursor.previous() ) // apply ldifs in reverse order
{
ChangeLogEvent event = cursor.get();
+
+ //System.out.println( "------------------------------------------------------------------" );
+ //System.out.println( event );
+
List<LdifEntry> reverses = event.getReverseLdifs();
for ( LdifEntry reverse:reverses )
Modified: directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java?rev=966621&r1=966620&r2=966621&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java (original)
+++ directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java Thu Jul 22 12:35:58 2010
@@ -104,10 +104,13 @@ public class CollectiveAttributeIntercep
public boolean accept( SearchingOperationContext operation, ClonedServerEntry result ) throws Exception
{
String[] retAttrs = operation.getSearchControls().getReturningAttributes();
- addCollectiveAttributes( operation, result, retAttrs );
- // Add the CollectiveAttributeSubentries AT if needed
- addCollectiveAttributeSubentries( result, retAttrs );
+ if ( addCollectiveAttributes( operation, result, retAttrs ) )
+ {
+
+ // Add the CollectiveAttributeSubentries AT if needed
+ addCollectiveAttributeSubentries( result, retAttrs );
+ }
return true;
}
@@ -176,19 +179,24 @@ public class CollectiveAttributeIntercep
{
return null;
}
+
+ boolean hasCollectiveAttribute = false;
// Adding the collective attributes if any
if ( ( lookupContext.getAttrsId() == null ) || ( lookupContext.getAttrsId().size() == 0 ) )
{
- addCollectiveAttributes( lookupContext, result, SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
+ hasCollectiveAttribute = addCollectiveAttributes( lookupContext, result, SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
}
else
{
- addCollectiveAttributes( lookupContext, result, lookupContext.getAttrsIdArray() );
+ hasCollectiveAttribute = addCollectiveAttributes( lookupContext, result, lookupContext.getAttrsIdArray() );
}
// Add the CollectiveAttributeSubentries AT if needed
- addCollectiveAttributeSubentries( result, lookupContext.getAttrsIdArray() );
+ if ( hasCollectiveAttribute )
+ {
+ addCollectiveAttributeSubentries( result, lookupContext.getAttrsIdArray() );
+ }
return result;
}
@@ -350,9 +358,10 @@ public class CollectiveAttributeIntercep
* are added to
* @param entry the entry to have the collective attributes injected
* @param retAttrs array or attribute type to be specifically included in the result entry(s)
+ * @return true if the entry has been modified
* @throws LdapException if there are problems accessing subentries
*/
- private void addCollectiveAttributes( OperationContext opContext, Entry entry, String[] retAttrs ) throws LdapException
+ private boolean addCollectiveAttributes( OperationContext opContext, Entry entry, String[] retAttrs ) throws LdapException
{
EntryAttribute collectiveAttributeSubentries = ( ( ClonedServerEntry ) entry ).getOriginalEntry().get(
ADS_COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
@@ -363,7 +372,7 @@ public class CollectiveAttributeIntercep
*/
if ( collectiveAttributeSubentries == null )
{
- return;
+ return false;
}
/*
@@ -385,7 +394,7 @@ public class CollectiveAttributeIntercep
* This entry does not allow any collective attributes
* to be injected into itself.
*/
- return;
+ return false;
}
exclusions = new HashSet<String>();
@@ -507,6 +516,8 @@ public class CollectiveAttributeIntercep
}
}
}
+
+ return true;
}
@@ -529,25 +540,48 @@ public class CollectiveAttributeIntercep
}
+ /**
+ * Inject the collectiveAttributeSubentries operational attribute into the
+ * entry, as it's not anymore stored in the backend.
+ */
private void addCollectiveAttributeSubentries( Entry entry, String[] requestedAttributes ) throws LdapException
{
if ( requestedAttributes == null )
{
- // Nothing to do
+ // Nothing to do, the uszer hasn't requested the operational attributes
return;
}
+ // First get the subentry UUID which is stored into the internal
+ // ads-collectiveAttributeSubentries attribute
EntryAttribute adsCollectiveAttributeSubentries = entry.get( ADS_COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
if ( adsCollectiveAttributeSubentries == null )
{
+ // We have none, that means we don't have any collective attribute in the entry
return;
}
-
+
+ // Now, get the subentry associated with this UUID
Subentry subentry = subentryInterceptor.getSubentryCache().getSubentry( adsCollectiveAttributeSubentries.getString() );
+ if ( subentry == null )
+ {
+ // Ok, the cache has been cleaned up since the attribute has been
+ // added to the entry. Unlikely, but anyway...
+ return;
+ }
+
+ // Loop on all the requested attributes. We have to deal with the following
+ // special cases :
+ // '1.1' : we can ignore this one
+ // '+' : we can add the requested attribute, the user wants all of them
+ // '*' : bypass
+ // any attribute : if the collectiveAttributeSubentries is requested, then
+ // add it.
for ( String requestedAttribute : requestedAttributes )
{
+ // '+' ? => add the collectiveAttributeSubentries attribute and return
if ( requestedAttribute.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
{
// Add the missing collectiveAttributeSubentries and exit
@@ -556,19 +590,29 @@ public class CollectiveAttributeIntercep
return;
}
+ // '*' and '1.1' are irrelevant
if ( requestedAttribute.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) || requestedAttribute.equals( SchemaConstants.NO_ATTRIBUTE ) )
{
continue;
}
- AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( requestedAttribute );
-
- if ( attributeType.equals( COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) )
+ try
{
- // Add the missing collectiveAttributeSubentries and exit
- entry.put( COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT, subentry.getDn().getNormName() );
-
- return;
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( requestedAttribute );
+
+ // The user has specifically requested the collectiveAttributeSubentries attribute,
+ // we just have to add it and return.
+ if ( attributeType.equals( COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) )
+ {
+ // Add the missing collectiveAttributeSubentries and exit
+ entry.put( COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT, subentry.getDn().getNormName() );
+
+ return;
+ }
+ }
+ catch ( LdapException le )
+ {
+ // The attribute is unknown, no problem, we simply ignore it
}
}
Modified: directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java?rev=966621&r1=966620&r2=966621&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java (original)
+++ directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java Thu Jul 22 12:35:58 2010
@@ -365,7 +365,7 @@ public class SubentryInterceptor extends
/**
* Update all the entries under an AP adding the
*/
- private void updateEntries( OperationEnum operation, CoreSession session, DN subentryDn, DN apDn, SubtreeSpecification ss, DN baseDn, List<EntryAttribute> operationalAttributes ) throws LdapException
+ private void updateEntries( OperationEnum operation, CoreSession session, String subentryUuid, DN apDn, SubtreeSpecification ss, DN baseDn, List<EntryAttribute> operationalAttributes ) throws LdapException
{
ExprNode filter = new PresenceNode( OBJECT_CLASS_AT ); // (objectClass=*)
SearchControls controls = new SearchControls();
@@ -397,7 +397,7 @@ public class SubentryInterceptor extends
break;
case REMOVE :
- modifications = getOperationalModsForRemove( subentryDn, candidate );
+ modifications = getOperationalModsForRemove( subentryUuid, candidate );
break;
/*
@@ -407,7 +407,7 @@ public class SubentryInterceptor extends
*/
}
- LOG.debug( "The entry {} has been evaluated to true for subentry {}", candidate.getDn(), subentryDn );
+ LOG.debug( "The entry {} has been evaluated to true for subentry {}", candidate.getDn(), subentryUuid );
nexus.modify( new ModifyOperationContext( session, candidateDn, modifications ) );
}
}
@@ -727,18 +727,17 @@ public class SubentryInterceptor extends
* @return the set of modifications required to remove an entry's reference to
* a subentry
*/
- private List<Modification> getOperationalModsForRemove( DN subentryDn, Entry candidate ) throws LdapException
+ private List<Modification> getOperationalModsForRemove( String subentryUuid, Entry candidate ) throws LdapException
{
List<Modification> modifications = new ArrayList<Modification>();
- String dn = subentryDn.getNormName();
for ( AttributeType operationalAttribute : SUBENTRY_OPATTRS )
{
EntryAttribute opAttr = candidate.get( operationalAttribute );
- if ( ( opAttr != null ) && opAttr.contains( dn ) )
+ if ( ( opAttr != null ) && opAttr.contains( subentryUuid ) )
{
- EntryAttribute attr = new DefaultEntryAttribute( operationalAttribute, dn );
+ EntryAttribute attr = new DefaultEntryAttribute( operationalAttribute, subentryUuid );
modifications.add( new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr ) );
}
}
@@ -925,7 +924,7 @@ public class SubentryInterceptor extends
DN baseDn = ( DN ) apDn.clone();
baseDn.addAll( subentry.getSubtreeSpecification().getBase() );
- updateEntries( OperationEnum.ADD, addContext.getSession(), dn, apDn, subentry.getSubtreeSpecification(), baseDn, operationalAttributes );
+ updateEntries( OperationEnum.ADD, addContext.getSession(), subentryUuid, apDn, subentry.getSubtreeSpecification(), baseDn, operationalAttributes );
// Store the newly modified entry into the context for later use in interceptor
// just in case
@@ -1015,7 +1014,7 @@ public class SubentryInterceptor extends
baseDn.addAll( removedSubentry.getSubtreeSpecification().getBase() );
// Remove all the references to this removed subentry from all the selected entries
- updateEntries( OperationEnum.REMOVE, deleteContext.getSession(), dn, apDn, removedSubentry.getSubtreeSpecification(), baseDn, null );
+ updateEntries( OperationEnum.REMOVE, deleteContext.getSession(), subentryUuid, apDn, removedSubentry.getSubtreeSpecification(), baseDn, null );
// Now delete the subentry itself
next.delete( deleteContext );