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/09/08 19:19:06 UTC
svn commit: r995162 -
/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java
Author: elecharny
Date: Wed Sep 8 17:19:06 2010
New Revision: 995162
URL: http://svn.apache.org/viewvc?rev=995162&view=rev
Log:
Updated the AdministrativePoint cache in the admin interceptor
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java?rev=995162&r1=995161&r2=995162&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java Wed Sep 8 17:19:06 2010
@@ -375,6 +375,10 @@ public class AdministrativePointIntercep
}
+ /**
+ * Find the parent for the given administrative point. If the AP is an AAP, the parent will be the closest
+ * AAP or the closest SAP. If we have a SAP between the added AAP and a AAP, then
+ */
private AdministrativePoint findParent( AdministrativePoint ap, DnNode<List<AdministrativePoint>> currentNode )
{
List<AdministrativePoint> aps = currentNode.getElement();
@@ -505,6 +509,37 @@ public class AdministrativePointIntercep
}
+ /**
+ * Update The Administrative Points cache, adding the given AdminPoint
+ */
+ private void addAPCache( EntryAttribute adminPoint, AddOperationContext addContext ) throws LdapException
+ {
+ // Now, update the cache
+ String uuid = addContext.getEntry().get( ENTRY_UUID_AT ).getString();
+
+ // Construct the AdministrativePoint objects
+ List<AdministrativePoint> administrativePoints = createAdministrativePoints( adminPoint, addContext.getDn(),
+ uuid );
+
+ // Store the APs in the AP cache
+ adminPointCache.add( addContext.getDn(), administrativePoints );
+
+ System.out.println( "After addition : " + adminPointCache );
+ }
+
+
+ /**
+ * Update The Administrative Points cache, removing the given AdminPoint
+ */
+ private void deleteAPCache( EntryAttribute adminPoint, DeleteOperationContext deleteContext ) throws LdapException
+ {
+ // Store the APs in the AP cache
+ adminPointCache.remove( deleteContext.getDn() );
+
+ System.out.println( "After deletion : " + adminPointCache );
+ }
+
+
//-------------------------------------------------------------------------------------------
// Interceptor initialization
//-------------------------------------------------------------------------------------------
@@ -624,6 +659,9 @@ public class AdministrativePointIntercep
next.add( addContext );
+ // Now, update the AdminPoint cache
+ addAPCache( adminPoint, addContext );
+
LOG.debug( "Added an Autonomous Administrative Point at {}", entry.getDn() );
return;
@@ -674,45 +712,125 @@ public class AdministrativePointIntercep
// Ok, we are golden.
next.add( addContext );
- // Now, update the cache
- String uuid = addContext.getEntry().get( ENTRY_UUID_AT ).getString();
+ // Now, update the AdminPoint cache
+ addAPCache( adminPoint, addContext );
- // Construct the AdministrativePoint objects
- List<AdministrativePoint> administrativePoints = createAdministrativePoints( adminPoint, addContext.getDn(),
- uuid );
+ LOG.debug( "Added an Administrative Point at {}", entry.getDn() );
- for ( AdministrativePoint ap : administrativePoints )
+ return;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void delete( NextInterceptor next, DeleteOperationContext deleteContext ) throws LdapException
+ {
+ Entry entry = deleteContext.getEntry();
+
+ // Check if we are deleting an Administrative Point
+ EntryAttribute adminPoint = entry.get( ADMINISTRATIVE_ROLE_AT );
+
+ if ( adminPoint == null )
{
- if ( ap.isAutonomous() )
+ // Nope, go on.
+ next.delete( deleteContext );
+
+ LOG.debug( "Exit from Administrative Interceptor" );
+
+ return;
+ }
+
+ LOG.debug( "Deletion of an administrative point at {} for the role {}", entry.getDn(), adminPoint );
+
+ // Check that the removed AdministrativeRoles are valid
+ for ( Value<?> role : adminPoint )
+ {
+ if ( !isValidRole( role.getString() ) )
{
- // Find the parent
- AdministrativePoint parent = findParent( ap, adminPointCache );
- ap.setParent( parent );
+ String message = "Cannot remove the given role, it's not a valid one :" + role;
+ LOG.error( message );
+ throw new LdapUnwillingToPerformException( message );
+ }
+ }
- // We won't have any children as the entry has just been added
+ // Now we are trying to remove an Administrative point. We have to check that the removed
+ // AP is correct if it's an AAP : it should not have any other role
+ if ( adminPoint.contains( SchemaConstants.AUTONOMOUS_AREA ) )
+ {
+ if ( adminPoint.size() > 1 )
+ {
+ String message = "Cannot remove an Autonomous Administratve Point when some other"
+ + " roles are removed : " + adminPoint;
+ LOG.error( message );
+ throw new LdapUnwillingToPerformException( message );
}
else
{
- // Find the parent
- AdministrativePoint parent = findParent( ap, adminPointCache );
- ap.setParent( parent );
+ // Ok, we can remove the AAP
+ LOG.debug( "Deleting an Autonomous Administrative Point at {}", entry.getDn() );
+
+ next.delete( deleteContext );
+
+ // Now, update the AdminPoint cache
+ deleteAPCache( adminPoint, deleteContext );
- // We won't have any children as the entry has just been added
+ LOG.debug( "Deleted an Autonomous Administrative Point at {}", entry.getDn() );
+
+ return;
}
}
- LOG.debug( "Added an Autonomous Administrative Point at {}", entry.getDn() );
+ // check that we can't mix Inner and Specific areas
+ if ( ( ( adminPoint.contains( SchemaConstants.ACCESS_CONTROL_SPECIFIC_AREA ) || adminPoint
+ .contains( SchemaConstants.ACCESS_CONTROL_SPECIFIC_AREA_OID ) ) && ( adminPoint
+ .contains( SchemaConstants.ACCESS_CONTROL_INNER_AREA ) || adminPoint
+ .contains( SchemaConstants.ACCESS_CONTROL_INNER_AREA_OID ) ) )
+ || ( ( adminPoint.contains( SchemaConstants.COLLECTIVE_ATTRIBUTE_SPECIFIC_AREA ) || adminPoint
+ .contains( SchemaConstants.COLLECTIVE_ATTRIBUTE_SPECIFIC_AREA_OID ) ) && ( adminPoint
+ .contains( SchemaConstants.COLLECTIVE_ATTRIBUTE_INNER_AREA ) || adminPoint
+ .contains( SchemaConstants.COLLECTIVE_ATTRIBUTE_INNER_AREA_OID ) ) )
+ || ( ( adminPoint.contains( SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) || adminPoint
+ .contains( SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA_OID ) ) && ( adminPoint
+ .contains( SchemaConstants.TRIGGER_EXECUTION_INNER_AREA ) || adminPoint
+ .contains( SchemaConstants.TRIGGER_EXECUTION_INNER_AREA_OID ) ) ) )
+ {
+ // This is inconsistent
+ String message = "Cannot delete a specific Administrative Point and the same"
+ + " inner Administrative point at the same time : " + adminPoint;
+ LOG.error( message );
+ throw new LdapUnwillingToPerformException( message );
+ }
+
+ // Check that we don't delete the same role twice now
+ Set<String> seenRoles = new HashSet<String>();
- return;
- }
+ for ( Value<?> role : adminPoint )
+ {
+ String trimmedRole = StringTools.toLowerCase( StringTools.trim( role.getString() ) );
+ if ( seenRoles.contains( trimmedRole ) )
+ {
+ // Already seen : an error
+ String message = "The role " + role.getString() + " has already been seen.";
+ LOG.error( message );
+ throw new LdapUnwillingToPerformException( message );
+ }
- /**
- * {@inheritDoc}
- */
- public void delete( NextInterceptor next, DeleteOperationContext deleteContext ) throws LdapException
- {
+ // Add the role and its OID into the seen roles
+ seenRoles.add( trimmedRole );
+ seenRoles.add( ROLES_OID.get( trimmedRole ) );
+ }
+
+ // Ok, we are golden.
next.delete( deleteContext );
+
+ // Now, update the AdminPoint cache
+ deleteAPCache( adminPoint, deleteContext );
+
+ LOG.debug( "Deleted an Administrative Point at {}", entry.getDn() );
+
+ return;
}