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 2009/05/29 00:25:50 UTC

svn commit: r779787 - in /directory/apacheds/trunk: core/src/main/java/org/apache/directory/server/core/ jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ server-integ/src/test/java/org/apache/directory/server/operati...

Author: elecharny
Date: Thu May 28 22:25:49 2009
New Revision: 779787

URL: http://svn.apache.org/viewvc?rev=779787&view=rev
Log:
o Added some Javadoc
o Added Stefan's test for alias (commented atm)
o Added some decent exception handling
o Minor typoes  fixing

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
    directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=779787&r1=779786&r2=779787&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Thu May 28 22:25:49 2009
@@ -813,25 +813,25 @@
                 {
                     switch( reverse.getChangeType().getChangeType() )
                     {
-                        case( ChangeType.ADD_ORDINAL ):
+                        case ChangeType.ADD_ORDINAL :
                             adminSession.add( 
                                 new DefaultServerEntry( registries, reverse.getEntry() ), true ); 
                             break;
                             
-                        case( ChangeType.DELETE_ORDINAL ):
+                        case ChangeType.DELETE_ORDINAL :
                             adminSession.delete( reverse.getDn(), true );
                             break;
                             
-                        case( ChangeType.MODIFY_ORDINAL ):
+                        case ChangeType.MODIFY_ORDINAL :
                             List<Modification> mods = reverse.getModificationItems();
     
                             adminSession.modify( reverse.getDn(), mods, true );
                             break;
                             
-                        case( ChangeType.MODDN_ORDINAL ):
+                        case ChangeType.MODDN_ORDINAL :
                             // NO BREAK - both ModDN and ModRDN handling is the same
                         
-                        case( ChangeType.MODRDN_ORDINAL ):
+                        case ChangeType.MODRDN_ORDINAL :
                             LdapDN forwardDn = event.getForwardLdif().getDn();
                             LdapDN reverseDn = reverse.getDn();
                             

Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=779787&r1=779786&r2=779787&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java Thu May 28 22:25:49 2009
@@ -58,6 +58,7 @@
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
@@ -883,12 +884,20 @@
         {
             if ( aliasDn.equals( normalizedAliasTargetDn ) )
             {
-                throw new NamingException( "[36] aliasDereferencingProblem - " + "attempt to create alias to itself." );
+                String msg = "[36] aliasDereferencingProblem - attempt to create alias to itself.";
+                ResultCodeEnum rc = ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
+                LdapNamingException e = new LdapNamingException( msg, rc );
+                e.setResolvedName( aliasDn );
+                throw e;
             }
 
-            throw new NamingException( "[36] aliasDereferencingProblem - "
+            String msg = "[36] aliasDereferencingProblem - "
                 + "attempt to create alias with cycle to relative " + aliasTarget
-                + " not allowed from descendent alias " + aliasDn );
+                + " not allowed from descendent alias " + aliasDn;
+            ResultCodeEnum rc = ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
+            LdapNamingException e = new LdapNamingException( msg, rc );
+            e.setResolvedName( aliasDn );
+            throw e;
         }
 
         /*
@@ -901,27 +910,34 @@
          */
         if ( !normalizedAliasTargetDn.startsWith( normSuffix ) )
         {
-            // Complain specifically about aliases to outside naming contexts
-            throw new NamingException( "[36] aliasDereferencingProblem -"
+            String msg = "[36] aliasDereferencingProblem - "
                 + " the alias points to an entry outside of the " + upSuffix.getUpName()
-                + " namingContext to an object whose existance cannot be" + " determined." );
+                + " namingContext to an object whose existance cannot be determined.";
+            ResultCodeEnum rc = ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
+            LdapNamingException e = new LdapNamingException( msg, rc );
+            e.setResolvedName( aliasDn );
+            throw e;
         }
 
         // L O O K U P   T A R G E T   I D
         targetId = ndnIdx.forwardLookup( normalizedAliasTargetDn.toNormName() );
 
         /*
-         * Check For Target Existance
+         * Check For Target Existence
          * 
-         * We do not allow the creation of inconsistant aliases.  Aliases should
+         * We do not allow the creation of inconsistent aliases.  Aliases should
          * not be broken links.  If the target does not exist we start screaming
          */
         if ( null == targetId )
         {
             // Complain about target not existing
-            throw new NamingException( "[33] aliasProblem - "
-                + "the alias when dereferenced would not name a known object "
-                + "the aliasedObjectName must be set to a valid existing " + "entry." );
+            String msg = "[33] aliasProblem - "
+                + "the alias '" + aliasDn.getUpName() + "' when dereferenced would not name a known object."
+                + "The aliased ObjectName '" + aliasTarget + "' must be set to a valid existing entry.";
+            ResultCodeEnum rc = ResultCodeEnum.ALIAS_PROBLEM;
+            LdapNamingException e = new LdapNamingException( msg, rc );
+            e.setResolvedName( aliasDn );
+            throw e;
         }
 
         /*
@@ -936,9 +952,12 @@
          */
         if ( null != aliasIdx.reverseLookup( targetId ) )
         {
-            // Complain about illegal alias chain
-            throw new NamingException( "[36] aliasDereferencingProblem -"
-                + " the alias points to another alias.  Alias chaining is" + " not supported by this backend." );
+            String msg = "[36] aliasDereferencingProblem - "
+                + " the alias points to another alias.  Alias chaining is not supported by this backend.";
+            ResultCodeEnum rc = ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
+            LdapNamingException e = new LdapNamingException( msg, rc );
+            e.setResolvedName( aliasDn );
+            throw e;
         }
 
         // Add the alias to the simple alias index
@@ -988,6 +1007,9 @@
 
     // TODO Change signature to not require the DN parameter since it is now
     // in the ServerEntry  !!!
+    /**
+     * {@inheritDoc}
+     */
     @SuppressWarnings("unchecked")
     public void add( LdapDN normName, ServerEntry entry ) throws Exception
     {
@@ -1031,7 +1053,10 @@
         if ( objectClass == null )
         {
             String msg = "Entry " + normName.getUpName() + " contains no objectClass attribute: " + entry;
-            throw new LdapSchemaViolationException( msg, ResultCodeEnum.OBJECT_CLASS_VIOLATION );
+            ResultCodeEnum rc = ResultCodeEnum.OBJECT_CLASS_VIOLATION;
+            NamingException e = new LdapSchemaViolationException( msg, rc );
+            e.setResolvedName( normName );
+            throw e;
         }
 
         // Start adding the system userIndices

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java?rev=779787&r1=779786&r2=779787&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java Thu May 28 22:25:49 2009
@@ -74,6 +74,7 @@
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 import org.apache.directory.server.integ.LdapServerFactory;
+import org.apache.directory.server.integ.ServerIntegrationUtils;
 import org.apache.directory.server.integ.SiRunner;
 import org.apache.directory.server.ldap.LdapService;
 import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
@@ -1245,4 +1246,76 @@
         assertFalse( res.hasMore() );
     }
 
+    
+    protected Attributes getPersonAttributes( String sn, String cn )
+    {
+        Attributes attrs = new BasicAttributes( true );
+        Attribute ocls = new BasicAttribute( "objectClass" );
+        ocls.add( "top" );
+        ocls.add( "person" );
+        attrs.put( ocls );
+        attrs.put( "cn", cn );
+        attrs.put( "sn", sn );
+
+        return attrs;
+    }
+
+
+    protected Attributes getOrgUnitAttributes( String ou )
+    {
+        Attributes attrs = new BasicAttributes( true );
+        Attribute ocls = new BasicAttribute( "objectClass" );
+        ocls.add( "top" );
+        ocls.add( "organizationalUnit" );
+        attrs.put( ocls );
+        attrs.put( "ou", ou );
+
+        return attrs;
+    }
+
+    
+    /**
+     * <pre>
+     * ou=system
+     *   |--ou=sales
+     *   |    |--cn=real  <--real entry
+     *   |--ou=engineering
+     *        |--cn=alias  <--alias, pointing to the real entry
+     * </pre>
+     * 
+     * @throws NamingException 
+     *
+    @Test
+    public void test_DIRSERVER_1357() throws Exception
+    {
+        DirContext ctx = ( DirContext ) ServerIntegrationUtils.getWiredContext( ldapService ).lookup( "ou=system" );
+
+        Attributes salesAttrs = getOrgUnitAttributes( "sales" );
+        ctx.createSubcontext( "ou=sales", salesAttrs );
+
+        Attributes engAttrs = getOrgUnitAttributes( "engineering" );
+        ctx.createSubcontext( "ou=engineering", engAttrs );
+
+        // The real entry under ou=sales
+        Attributes fooAttrs = getPersonAttributes( "real", "real" );
+        ctx.createSubcontext( "cn=real,ou=sales", fooAttrs );
+
+        // The alias under ou=engineering, pointing to the real entry
+        Attributes aliasAttrs = new BasicAttributes( true );
+        Attribute aliasOC = new BasicAttribute( "objectClass" );
+        aliasOC.add( "top" );
+        aliasOC.add( "alias" );
+        aliasOC.add( "extensibleObject" );
+        aliasAttrs.put( aliasOC );
+        aliasAttrs.put( "cn", "alias" );
+        aliasAttrs.put( "aliasedObjectName", "cn=real,ou=sales,ou=system" );
+        ctx.createSubcontext( "cn=alias,ou=engineering", aliasAttrs );
+
+        // Delete the real entry first
+        ctx.destroySubcontext( "cn=real,ou=sales" );
+
+        // Now the alias entry still exists, but points to nowhere.
+        // When trying to delete the alias entry an exception occurs.
+        ctx.destroySubcontext( "cn=alias,ou=engineering" );
+    }*/
 }

Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java?rev=779787&r1=779786&r2=779787&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java Thu May 28 22:25:49 2009
@@ -260,6 +260,14 @@
     int count() throws Exception;
 
 
+    /**
+     * Add an entry into the store. 
+     * 
+     * @param normName TODO: Remove this parameter.
+     * @param entry The entry to add
+     * 
+     * @throws Exception If the addition failed.
+     */
     void add( LdapDN normName, ServerEntry entry ) throws Exception;