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 2008/08/15 01:12:13 UTC
svn commit: r686082 [3/7] - in /directory:
apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/
apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/
apacheds/branches/bigbang/c...
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java Thu Aug 14 16:12:09 2008
@@ -20,7 +20,6 @@
package org.apache.directory.server.core.entry;
-import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -38,6 +37,7 @@
import org.apache.directory.server.schema.registries.DefaultRegistries;
import org.apache.directory.server.schema.registries.OidRegistry;
import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
import org.apache.directory.shared.ldap.schema.OidNormalizer;
@@ -174,4 +174,97 @@
assertEquals( entry, result );
}
+
+
+ @Test public void testSerializeServerEntryWithEmptyDN() throws Exception
+ {
+ LdapDN dn = new LdapDN( "" );
+ dn.normalize( oids );
+
+ ServerEntry entry = new DefaultServerEntry( registries, dn );
+ entry.add( "objectClass", "top", "person", "inetOrgPerson", "organizationalPerson" );
+ entry.add( "cn", "text", "test" );
+ entry.add( "SN", (String)null );
+ entry.add( "userPassword", StringTools.getBytesUtf8( "password" ) );
+
+ ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+
+ byte[] data = ses.serialize( entry );
+
+ ServerEntry result = (ServerEntry)ses.deserialize( data );
+
+ assertEquals( entry, result );
+ }
+
+
+ @Test public void testSerializeServerEntryWithNoAttributes() throws Exception
+ {
+ LdapDN dn = new LdapDN( "" );
+ dn.normalize( oids );
+
+ ServerEntry entry = new DefaultServerEntry( registries, dn );
+
+ ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+
+ byte[] data = ses.serialize( entry );
+
+ ServerEntry result = (ServerEntry)ses.deserialize( data );
+
+ assertEquals( entry, result );
+ }
+
+
+ @Test public void testSerializeServerEntryWithAttributeNoValue() throws Exception
+ {
+ LdapDN dn = new LdapDN( "" );
+ dn.normalize( oids );
+
+ ServerEntry entry = new DefaultServerEntry( registries, dn );
+
+ ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+ EntryAttribute oc = new DefaultServerAttribute( "ObjectClass", registries.getAttributeTypeRegistry().lookup( "objectclass" ) );
+ entry.add( oc );
+
+ byte[] data = ses.serialize( entry );
+
+ ServerEntry result = (ServerEntry)ses.deserialize( data );
+
+ assertEquals( entry, result );
+ }
+
+
+ @Test public void testSerializeServerEntryWithAttributeStringValue() throws Exception
+ {
+ LdapDN dn = new LdapDN( "" );
+ dn.normalize( oids );
+
+ ServerEntry entry = new DefaultServerEntry( registries, dn );
+
+ ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+ entry.add( "ObjectClass", "top", "person" );
+
+ byte[] data = ses.serialize( entry );
+
+ ServerEntry result = (ServerEntry)ses.deserialize( data );
+
+ assertEquals( entry, result );
+ }
+
+
+ @Test public void testSerializeServerEntryWithAttributeBinaryValue() throws Exception
+ {
+ LdapDN dn = new LdapDN( "" );
+ dn.normalize( oids );
+
+ ServerEntry entry = new DefaultServerEntry( registries, dn );
+
+ ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+ entry.add( "userPassword", StringTools.getBytesUtf8( "secret" ) );
+
+ byte[] data = ses.serialize( entry );
+
+ ServerEntry result = (ServerEntry)ses.deserialize( data );
+
+ assertEquals( entry, result );
+ }
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerModificationTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerModificationTest.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerModificationTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerModificationTest.java Thu Aug 14 16:12:09 2008
@@ -19,13 +19,43 @@
*/
package org.apache.directory.server.core.entry;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.schema.bootstrap.ApacheSchema;
+import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
+import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
+import org.apache.directory.server.schema.bootstrap.CoreSchema;
+import org.apache.directory.server.schema.bootstrap.CosineSchema;
+import org.apache.directory.server.schema.bootstrap.InetorgpersonSchema;
+import org.apache.directory.server.schema.bootstrap.Schema;
+import org.apache.directory.server.schema.bootstrap.SystemSchema;
+import org.apache.directory.server.schema.registries.DefaultOidRegistry;
+import org.apache.directory.server.schema.registries.DefaultRegistries;
+import org.apache.directory.server.schema.registries.OidRegistry;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.client.ClientAttribute;
+import org.apache.directory.shared.ldap.entry.client.ClientModification;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.schema.AttributeType;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.fail;
+import org.junit.BeforeClass;
import org.junit.Test;
@@ -37,10 +67,118 @@
*/
public class ServerModificationTest
{
+ private static BootstrapSchemaLoader loader;
+ private static Registries registries;
+ private static OidRegistry oidRegistry;
+ private static AttributeType atCN;
+
+ // A SINGLE-VALUE attribute
+ private static AttributeType atC;
+
+
+ /**
+ * Serialize a ServerModification
+ */
+ private ByteArrayOutputStream serializeValue( ServerModification value ) throws IOException
+ {
+ ObjectOutputStream oOut = null;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try
+ {
+ oOut = new ObjectOutputStream( out );
+ value.serialize( oOut );
+ }
+ catch ( IOException ioe )
+ {
+ throw ioe;
+ }
+ finally
+ {
+ try
+ {
+ if ( oOut != null )
+ {
+ oOut.flush();
+ oOut.close();
+ }
+ }
+ catch ( IOException ioe )
+ {
+ throw ioe;
+ }
+ }
+
+ return out;
+ }
+
+
+ /**
+ * Deserialize a ServerModification
+ */
+ private ServerModification deserializeValue( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException, NamingException
+ {
+ ObjectInputStream oIn = null;
+ ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
+
+ try
+ {
+ oIn = new ObjectInputStream( in );
+
+ ServerModification value = new ServerModification();
+ value.deserialize( oIn, registries.getAttributeTypeRegistry() );
+
+ return value;
+ }
+ catch ( IOException ioe )
+ {
+ throw ioe;
+ }
+ finally
+ {
+ try
+ {
+ if ( oIn != null )
+ {
+ oIn.close();
+ }
+ }
+ catch ( IOException ioe )
+ {
+ throw ioe;
+ }
+ }
+ }
+
+
+ /**
+ * Initialize the registries once for the whole test suite
+ */
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ loader = new BootstrapSchemaLoader();
+ oidRegistry = new DefaultOidRegistry();
+ registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
+
+ // load essential bootstrap schemas
+ Set<Schema> bootstrapSchemas = new HashSet<Schema>();
+ bootstrapSchemas.add( new ApachemetaSchema() );
+ bootstrapSchemas.add( new ApacheSchema() );
+ bootstrapSchemas.add( new CoreSchema() );
+ bootstrapSchemas.add( new SystemSchema() );
+ bootstrapSchemas.add( new InetorgpersonSchema() );
+ bootstrapSchemas.add( new CosineSchema() );
+ loader.loadWithDependencies( bootstrapSchemas, registries );
+
+ atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+ atC = registries.getAttributeTypeRegistry().lookup( "c" );
+ }
+
+
@Test public void testCreateServerModification()
{
- AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
- ServerAttribute attribute = new DefaultServerAttribute( at );
+ ServerAttribute attribute = new DefaultServerAttribute( atCN );
attribute.add( "test1", "test2" );
Modification mod = new ServerModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
@@ -57,4 +195,120 @@
assertTrue( clone.getAttribute().contains( "test1" ) );
assertTrue( clone.getAttribute().contains( "test2" ) );
}
+
+
+ /**
+ * Test the copy constructor with a ServerModification
+ *
+ */
+ @Test
+ public void testCopyServerModification()
+ {
+ ServerAttribute attribute = new DefaultServerAttribute( atC );
+ attribute.add( "test1", "test2" );
+ Modification serverModification = new ServerModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
+
+ Modification copy = new ServerModification( registries, serverModification );
+
+ assertTrue( copy instanceof ServerModification );
+ assertEquals( copy, serverModification );
+
+ serverModification.setOperation( ModificationOperation.REMOVE_ATTRIBUTE );
+ assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() );
+
+ ServerAttribute attribute2 = new DefaultServerAttribute( atCN, "t" );
+ serverModification.setAttribute( attribute2 );
+ assertNotSame( attribute2, copy.getAttribute() );
+ }
+
+
+ /**
+ * Test the copy constructor with a ClientModification
+ *
+ */
+ @Test
+ public void testCopyClientModification()
+ {
+ ClientAttribute attribute = new DefaultClientAttribute( atC.getName() );
+ attribute.add( "test1", "test2" );
+ Modification clientModification = new ClientModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
+
+ Modification copy = new ServerModification( registries, clientModification );
+
+ assertTrue( copy instanceof ServerModification );
+ assertFalse( copy instanceof ClientModification );
+ assertFalse( copy.equals( clientModification ) );
+ assertTrue( copy.getAttribute() instanceof ServerAttribute );
+ assertEquals( atC, ((ServerAttribute)copy.getAttribute()).getAttributeType() );
+ assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() );
+ assertTrue( copy.getAttribute().contains( "test1", "test2" ) );
+
+ clientModification.setOperation( ModificationOperation.REMOVE_ATTRIBUTE );
+ assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() );
+
+ ClientAttribute attribute2 = new DefaultClientAttribute( "cn", "t" );
+ clientModification.setAttribute( attribute2 );
+ assertNotSame( attribute2, copy.getAttribute() );
+ }
+
+
+ @Test
+ public void testSerializationModificationADD() throws ClassNotFoundException, IOException, NamingException
+ {
+ EntryAttribute attribute = new DefaultServerAttribute( atCN );
+ attribute.add( "test1", "test2" );
+
+ ServerModification mod = new ServerModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
+
+ Modification modSer = deserializeValue( serializeValue( mod ) );
+
+ assertEquals( mod, modSer );
+ }
+
+
+ @Test
+ public void testSerializationModificationREPLACE() throws ClassNotFoundException, IOException, NamingException
+ {
+ EntryAttribute attribute = new DefaultServerAttribute( atCN );
+ attribute.add( "test1", "test2" );
+
+ ServerModification mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
+
+ Modification modSer = deserializeValue( serializeValue( mod ) );
+
+ assertEquals( mod, modSer );
+ }
+
+
+ @Test
+ public void testSerializationModificationREMOVE() throws ClassNotFoundException, IOException, NamingException
+ {
+ EntryAttribute attribute = new DefaultServerAttribute( atCN );
+ attribute.add( "test1", "test2" );
+
+ ServerModification mod = new ServerModification( ModificationOperation.REMOVE_ATTRIBUTE, attribute );
+
+ Modification modSer = deserializeValue( serializeValue( mod ) );
+
+ assertEquals( mod, modSer );
+ }
+
+
+ @Test
+ public void testSerializationModificationNoAttribute() throws ClassNotFoundException, IOException, NamingException
+ {
+ ServerModification mod = new ServerModification();
+
+ mod.setOperation( ModificationOperation.ADD_ATTRIBUTE );
+
+ try
+ {
+ deserializeValue( serializeValue( mod ) );
+ fail();
+ }
+ catch ( IOException ioe )
+ {
+ assertTrue( true );
+ }
+ }
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java Thu Aug 14 16:12:09 2008
@@ -93,6 +93,82 @@
at.setSyntax( s );
}
+
+ /**
+ * Serialize a ServerStringValue
+ */
+ private ByteArrayOutputStream serializeValue( ServerStringValue value ) throws IOException
+ {
+ ObjectOutputStream oOut = null;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try
+ {
+ oOut = new ObjectOutputStream( out );
+ value.serialize( oOut );
+ }
+ catch ( IOException ioe )
+ {
+ throw ioe;
+ }
+ finally
+ {
+ try
+ {
+ if ( oOut != null )
+ {
+ oOut.flush();
+ oOut.close();
+ }
+ }
+ catch ( IOException ioe )
+ {
+ throw ioe;
+ }
+ }
+
+ return out;
+ }
+
+
+ /**
+ * Deserialize a ServerStringValue
+ */
+ private ServerStringValue deserializeValue( ByteArrayOutputStream out, AttributeType at ) throws IOException, ClassNotFoundException
+ {
+ ObjectInputStream oIn = null;
+ ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
+
+ try
+ {
+ oIn = new ObjectInputStream( in );
+
+ ServerStringValue value = new ServerStringValue( at );
+ value.deserialize( oIn );
+
+ return value;
+ }
+ catch ( IOException ioe )
+ {
+ throw ioe;
+ }
+ finally
+ {
+ try
+ {
+ if ( oIn != null )
+ {
+ oIn.close();
+ }
+ }
+ catch ( IOException ioe )
+ {
+ throw ioe;
+ }
+ }
+ }
+
+
/**
* Test the constructor with a null value
*/
@@ -615,28 +691,17 @@
@Test public void testNormalizedStringValueSerialization() throws NamingException, IOException, ClassNotFoundException
{
// First check with a value which will be normalized
- ServerStringValue sv = new ServerStringValue( at, " Test Test " );
+ ServerStringValue ssv = new ServerStringValue( at, " Test Test " );
- sv.normalize();
- String normalized = sv.getNormalizedValue();
+ ssv.normalize();
+ String normalized = ssv.getNormalizedValue();
assertEquals( "test test", normalized );
- assertEquals( " Test Test ", sv.get() );
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( baos );
+ assertEquals( " Test Test ", ssv.get() );
- sv.writeExternal( out );
+ ServerStringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
- ObjectInputStream in = null;
-
- byte[] data = baos.toByteArray();
- in = new ObjectInputStream( new ByteArrayInputStream( data ) );
-
- ServerStringValue sv2 = new ServerStringValue( at );
- sv2.readExternal( in );
-
- assertEquals( sv, sv2 );
+ assertEquals( ssv, ssvSer );
}
@@ -646,29 +711,17 @@
@Test public void testNoNormalizedStringValueSerialization() throws NamingException, IOException, ClassNotFoundException
{
// First check with a value which will be normalized
- ServerStringValue sv = new ServerStringValue( at, "test" );
+ ServerStringValue ssv = new ServerStringValue( at, "test" );
- sv.normalize();
- String normalized = sv.getNormalizedValue();
+ ssv.normalize();
+ String normalized = ssv.getNormalizedValue();
assertEquals( "test", normalized );
- assertEquals( "test", sv.get() );
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( baos );
-
- sv.writeExternal( out );
-
- ObjectInputStream in = null;
-
- byte[] data = baos.toByteArray();
-
- in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+ assertEquals( "test", ssv.get() );
- ServerStringValue sv2 = new ServerStringValue( at );
- sv2.readExternal( in );
+ ServerStringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
- assertEquals( sv, sv2 );
+ assertEquals( ssv, ssvSer );
}
@@ -678,29 +731,17 @@
@Test public void testNullStringValueSerialization() throws NamingException, IOException, ClassNotFoundException
{
// First check with a value which will be normalized
- ServerStringValue sv = new ServerStringValue( at );
+ ServerStringValue ssv = new ServerStringValue( at );
- sv.normalize();
- String normalized = sv.getNormalizedValue();
+ ssv.normalize();
+ String normalized = ssv.getNormalizedValue();
assertEquals( null, normalized );
- assertEquals( null, sv.get() );
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( baos );
-
- sv.writeExternal( out );
-
- ObjectInputStream in = null;
-
- byte[] data = baos.toByteArray();
+ assertEquals( null, ssv.get() );
- in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+ ServerStringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
- ServerStringValue sv2 = new ServerStringValue( at );
- sv2.readExternal( in );
-
- assertEquals( sv, sv2 );
+ assertEquals( ssv, ssvSer );
}
@@ -710,28 +751,33 @@
@Test public void testEmptyStringValueSerialization() throws NamingException, IOException, ClassNotFoundException
{
// First check with a value which will be normalized
- ServerStringValue sv = new ServerStringValue( at, "" );
+ ServerStringValue ssv = new ServerStringValue( at, "" );
- sv.normalize();
- String normalized = sv.getNormalizedValue();
+ ssv.normalize();
+ String normalized = ssv.getNormalizedValue();
assertEquals( "", normalized );
- assertEquals( "", sv.get() );
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( baos );
+ assertEquals( "", ssv.get() );
- sv.writeExternal( out );
+ ServerStringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
- ObjectInputStream in = null;
+ assertEquals( ssv, ssvSer );
+ }
+
- byte[] data = baos.toByteArray();
+ /**
+ * Test serialization of an empty StringValue
+ */
+ @Test public void testStringValueEmptyNormalizedSerialization() throws NamingException, IOException, ClassNotFoundException
+ {
+ // First check with a value which will be normalized
+ ServerStringValue ssv = new ServerStringValue( at, " " );
- in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+ //assertEquals( "", normalized );
+ assertEquals( " ", ssv.get() );
- ServerStringValue sv2 = new ServerStringValue( at );
- sv2.readExternal( in );
+ ServerStringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
- assertEquals( sv, sv2 );
- }
+ assertEquals( ssv, ssvSer );
+ }
}
\ No newline at end of file
Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java Thu Aug 14 16:12:09 2008
@@ -30,12 +30,15 @@
import org.apache.directory.server.constants.ServerDNConstants;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.authn.LdapPrincipal;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.ldif.ChangeType;
import org.apache.directory.shared.ldap.ldif.LdifEntry;
import org.apache.directory.shared.ldap.ldif.LdifReader;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -91,18 +94,18 @@
*/
public static void injectEntries( DirectoryService service, String ldif ) throws Exception
{
- LdapContext rootDSE = getRootContext( service );
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
for ( LdifEntry entry : entries )
{
- rootDSE.createSubcontext( new LdapDN( entry.getDn() ), entry.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), entry.getEntry() ) );
}
}
- public static LdifEntry getUserAddLdif() throws InvalidNameException
+ public static LdifEntry getUserAddLdif() throws InvalidNameException, NamingException
{
return getUserAddLdif( "uid=akarasulu,ou=users,ou=system", "test".getBytes(), "Alex Karasulu", "Karasulu" );
}
@@ -131,6 +134,28 @@
}
+ public static CoreSession getCoreSession( String principalDn, DirectoryService service, String dn )
+ throws Exception
+ {
+ if ( principalDn == null )
+ {
+ principalDn = "";
+ }
+
+ LdapDN userDn = new LdapDN( principalDn );
+ userDn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
+ LdapPrincipal principal = new LdapPrincipal( userDn, AuthenticationLevel.SIMPLE );
+
+ if ( dn == null )
+ {
+ dn = "";
+ }
+
+ CoreSession session = service.getSession( principal );
+ return session;
+ }
+
+
public static LdapContext getSystemContext( DirectoryService service ) throws Exception
{
return getContext( ServerDNConstants.ADMIN_SYSTEM_DN, service, ServerDNConstants.SYSTEM_DN );
@@ -149,62 +174,58 @@
}
- public static void apply( LdapContext root, LdifEntry entry ) throws NamingException
+ public static void apply( DirectoryService service, LdifEntry entry ) throws Exception
{
LdapDN dn = new LdapDN( entry.getDn() );
+ CoreSession session = service.getAdminSession();
switch( entry.getChangeType().getChangeType() )
{
case( ChangeType.ADD_ORDINAL ):
- root.createSubcontext( dn, entry.getAttributes() );
+ session.add(
+ new DefaultServerEntry( service.getRegistries(), entry.getEntry() ) );
break;
case( ChangeType.DELETE_ORDINAL ):
- root.destroySubcontext( entry.getDn() );
+ session.delete( dn );
break;
case( ChangeType.MODDN_ORDINAL ):
- LdapDN target = new LdapDN( entry.getNewSuperior() );
- if ( entry.getNewRdn() != null )
- {
- target.add( entry.getNewRdn() );
- }
- else
- {
- target.add( dn.getRdn().toString() );
- }
-
- if ( entry.isDeleteOldRdn() )
- {
- root.addToEnvironment( "java.naming.ldap.deleteRDN", "true" );
- }
- else
- {
- root.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
- }
-
- root.rename( dn, target );
- break;
-
case( ChangeType.MODRDN_ORDINAL ):
- target = ( LdapDN ) dn.clone();
- target.remove( dn.size() - 1 );
- target.add( entry.getNewRdn() );
-
- if ( entry.isDeleteOldRdn() )
- {
- root.addToEnvironment( "java.naming.ldap.deleteRDN", "true" );
+ Rdn newRdn = new Rdn( entry.getNewRdn() );
+
+ if ( entry.getNewSuperior() != null )
+ {
+ // It's a move. The superior have changed
+ // Let's see if it's a rename too
+ Rdn oldRdn = dn.getRdn();
+ LdapDN newSuperior = new LdapDN( entry.getNewSuperior() );
+
+ if ( dn.size() == 0 )
+ {
+ throw new IllegalStateException( "can't move the root DSE" );
+ }
+ else if ( oldRdn.equals( newRdn ) )
+ {
+ // Same rdn : it's a move
+ session.move( dn, newSuperior );
+ }
+ else
+ {
+ // it's a move and rename
+ session.moveAndRename( dn, newSuperior, newRdn, entry.isDeleteOldRdn() );
+ }
}
else
{
- root.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
+ // it's a rename
+ session.rename( dn, newRdn, entry.isDeleteOldRdn() );
}
-
- root.rename( dn, target );
- break;
+
+ break;
case( ChangeType.MODIFY_ORDINAL ):
- root.modifyAttributes( dn, entry.getModificationItemsArray() );
+ session.modify( dn, entry.getModificationItems() );
break;
default:
@@ -214,21 +235,18 @@
public static LdifEntry getUserAddLdif( String dnstr, byte[] password, String cn, String sn )
- throws InvalidNameException
+ throws InvalidNameException, NamingException
{
LdapDN dn = new LdapDN( dnstr );
LdifEntry ldif = new LdifEntry();
ldif.setDn( dnstr );
ldif.setChangeType( ChangeType.Add );
- AttributeImpl attr = new AttributeImpl( "objectClass", "top" );
- attr.add( "person" );
- attr.add( "organizationalPerson" );
- attr.add( "inetOrgPerson" );
+ EntryAttribute attr = new DefaultClientAttribute( "objectClass",
+ "top", "person", "organizationalPerson", "inetOrgPerson" );
ldif.addAttribute( attr );
- attr = new AttributeImpl( "ou", "Engineering" );
- attr.add( "People" );
+ attr = new DefaultClientAttribute( "ou", "Engineering", "People" );
ldif.addAttribute( attr );
String uid = ( String ) dn.getRdn().getValue();
Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java Thu Aug 14 16:12:09 2008
@@ -25,11 +25,10 @@
import java.util.List;
import javax.naming.NamingException;
-import javax.naming.ldap.LdapContext;
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.integ.InheritableSettings;
-import org.apache.directory.server.core.integ.IntegrationUtils;
import org.apache.directory.shared.ldap.ldif.LdifEntry;
import org.apache.directory.shared.ldap.ldif.LdifReader;
import org.junit.internal.runners.TestClass;
@@ -191,8 +190,8 @@
LdifReader ldifReader = new LdifReader( in );
LdifEntry entry = ldifReader.next();
- LdapContext root = IntegrationUtils.getRootContext( service );
- root.createSubcontext( entry.getDn(), entry.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), entry.getEntry() ) );
}
catch ( Exception e )
{
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationIT.java Thu Aug 14 16:12:09 2008
@@ -26,7 +26,6 @@
import static org.apache.directory.server.core.integ.IntegrationUtils.*;
-import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.message.ModificationItemImpl;
import org.apache.directory.shared.ldap.name.LdapDN;
@@ -60,62 +59,6 @@
public static DirectoryService service;
- public static LdapContext getRootDSE() throws Exception
- {
- if ( service.isStarted() )
- {
- LdapDN dn = new LdapDN( "uid=admin,ou=system" );
- dn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
- return new ServerLdapContext( service,
- service.getSession( new LdapDN( dn ), "secret".getBytes() ), new LdapDN() );
- }
-
- throw new IllegalStateException( "Cannot acquire rootDSE before the service has been started!" );
- }
-
-
- public static LdapContext getRootDSE( String bindDn ) throws Exception
- {
- if ( service.isStarted() )
- {
- LdapDN dn = new LdapDN( bindDn );
- dn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
- return new ServerLdapContext( service,
- service.getSession( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ) ), new LdapDN() );
- }
-
- throw new IllegalStateException( "Cannot acquire rootDSE before the service has been started!" );
- }
-
-
- public static LdapContext getSystemRoot() throws Exception
- {
- if ( service.isStarted() )
- {
- LdapDN dn = new LdapDN( "uid=admin,ou=system" );
- dn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
- return new ServerLdapContext( service,
- service.getSession( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ) ), new LdapDN( "ou=system" ) );
- }
-
- throw new IllegalStateException( "Cannot acquire rootDSE before the service has been started!" );
- }
-
-
- public static LdapContext getSystemRoot( String bindDn ) throws Exception
- {
- if ( service.isStarted() )
- {
- LdapDN dn = new LdapDN( bindDn );
- dn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
- return new ServerLdapContext( service,
- service.getSession( new LdapPrincipal( dn, AuthenticationLevel.SIMPLE ) ), new LdapDN( "ou=system" ) );
- }
-
- throw new IllegalStateException( "Cannot acquire rootDSE before the service has been started!" );
- }
-
-
/**
* Checks all attributes of the admin account entry minus the userPassword
* attribute.
@@ -163,7 +106,7 @@
@Test
public void test3UseAkarasulu() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
LdapContext ctx = new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) );
@@ -215,7 +158,7 @@
@Test
public void test10TestNonAdminUser() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
assertNotNull( new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) ) );
@@ -225,7 +168,7 @@
@Test
public void test11InvalidateCredentialCache() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
LdapContext ctx = new ServerLdapContext( service,
@@ -301,7 +244,7 @@
@Test
public void testSHA() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
LdapContext ctx = new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) );
@@ -358,7 +301,7 @@
@Test
public void testSSHA() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
LdapContext ctx = new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) );
@@ -414,7 +357,7 @@
@Test
public void testMD5() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
LdapContext ctx = new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) );
@@ -470,7 +413,7 @@
@Test
public void testSMD5() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
LdapContext ctx = new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) );
@@ -526,7 +469,7 @@
@Test
public void testCRYPT() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
LdapContext ctx = new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) );
@@ -582,7 +525,7 @@
@Test
public void testInvalidateCredentialCacheForUpdatingAnotherUsersPassword() throws Exception
{
- apply( getRootDSE(), getUserAddLdif() );
+ apply( service, getUserAddLdif() );
// bind as akarasulu
String userDn = "uid=akarasulu,ou=users,ou=system";
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java Thu Aug 14 16:12:09 2008
@@ -20,25 +20,40 @@
package org.apache.directory.server.core.authz;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.server.core.CoreSession;
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.authn.LdapPrincipal;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.integ.CiRunner;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
import org.apache.directory.server.core.integ.annotations.Factory;
+import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.client.ClientModification;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.FilterParser;
+import org.apache.directory.shared.ldap.filter.SearchScope;
import org.apache.directory.shared.ldap.ldif.LdifEntry;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.NamingException;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.SearchControls;
-import javax.naming.ldap.LdapContext;
/**
@@ -64,11 +79,13 @@
public void testNoDeleteOnAdminByNonAdmin() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
+
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
try
{
- getContext( akarasulu.getDn(), service, "ou=system" ).destroySubcontext( "uid=admin" );
+ service.getAdminSession().delete( new LdapDN( "uid=admin,ou=system") );
fail( "User 'admin' should not be able to delete his account" );
}
catch ( LdapNoPermissionException e )
@@ -87,12 +104,16 @@
public void testNoRdnChangesOnAdminByNonAdmin() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
- LdapContext rootDSE = getContext( akarasulu.getDn(), service, "" );
+
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
try
{
- rootDSE.rename( "uid=admin,ou=system", "uid=alex,ou=system" );
+ service.getAdminSession().rename(
+ new LdapDN( "uid=admin,ou=system" ),
+ new Rdn( "uid=alex" ),
+ false );
fail( "admin should not be able to rename his account" );
}
catch ( LdapNoPermissionException e )
@@ -111,16 +132,31 @@
public void testModifyOnAdminByNonAdmin() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
- LdapContext rootDSE = getContext( akarasulu.getDn(), service, "" );
+
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
+
+ // Read the entry we just created using the akarasuluSession
+ Entry readEntry = service.getAdminSession().lookup( akarasulu.getDn(), new String[]{ "userPassword"} );
+
+ assertTrue( Arrays.equals( akarasulu.get( "userPassword" ).getBytes(), readEntry.get( "userPassword" ).getBytes() ) );
+
+ EntryAttribute attribute = new DefaultClientAttribute( "userPassword", "replaced" );
- Attributes attributes = new AttributesImpl();
- attributes.put( "userPassword", "replaced" );
+ List<Modification> mods = new ArrayList<Modification>();
+
+ Modification mod = new ClientModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
+ mods.add( mod );
+
+ LdapDN userDn = new LdapDN( "uid=akarasulu,ou=users,ou=system" );
+ userDn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
+ LdapPrincipal principal = new LdapPrincipal( userDn, AuthenticationLevel.SIMPLE );
+ CoreSession akarasuluSession = service.getSession( principal );
- //noinspection EmptyCatchBlock
try
{
- rootDSE.modifyAttributes( "uid=admin,ou=system", DirContext.REPLACE_ATTRIBUTE, attributes );
+ akarasuluSession.modify(
+ new LdapDN( "uid=admin,ou=system" ), mods );
fail( "User 'uid=admin,ou=system' should not be able to modify attributes on admin" );
}
catch ( Exception e )
@@ -138,15 +174,14 @@
public void testNoSearchByNonAdmin() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
- LdapContext rootDSE = getContext( akarasulu.getDn(), service, "" );
-
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
+
try
{
- rootDSE.search( "ou=system", "(objectClass=*)", controls );
+ ExprNode filter = FilterParser.parse( "(objectClass=*)" );
+ service.getAdminSession().search( new LdapDN( "ou=system" ), SearchScope.SUBTREE, filter , AliasDerefMode.DEREF_ALWAYS, null );
}
catch ( LdapNoPermissionException e )
{
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ListIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ListIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ListIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ListIT.java Thu Aug 14 16:12:09 2008
@@ -21,9 +21,9 @@
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.integ.CiRunner;
import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
import org.apache.directory.shared.ldap.ldif.LdifEntry;
@@ -57,9 +57,10 @@
public void testListSystemAsNonAdmin() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
- LdapContext sysRoot = getContext( akarasulu.getDn(), service, "ou=system" );
+ LdapContext sysRoot = getContext( akarasulu.getDn().getUpName(), service, "ou=system" );
HashSet<String> set = new HashSet<String>();
NamingEnumeration<NameClassPair> list = sysRoot.list( "" );
@@ -79,9 +80,10 @@
public void testListUsersAsNonAdmin() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
- LdapContext sysRoot = getContext( akarasulu.getDn(), service, "ou=system" );
+ LdapContext sysRoot = getContext( akarasulu.getDn().getUpName(), service, "ou=system" );
HashSet<String> set = new HashSet<String>();
NamingEnumeration<NameClassPair> list = sysRoot.list( "ou=users" );
@@ -121,7 +123,9 @@
LdapContext sysRoot = getSystemContext( service );
HashSet<String> set = new HashSet<String>();
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
+
NamingEnumeration<NameClassPair> list = sysRoot.list( "ou=users" );
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java Thu Aug 14 16:12:09 2008
@@ -21,8 +21,8 @@
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.integ.CiRunner;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
@@ -67,7 +67,9 @@
protected void createData() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
+
LdapContext sysRoot = getSystemContext( service );
/*
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ObjStateFactoryIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ObjStateFactoryIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ObjStateFactoryIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ObjStateFactoryIT.java Thu Aug 14 16:12:09 2008
@@ -21,10 +21,10 @@
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.integ.CiRunner;
import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.message.AttributesImpl;
import org.apache.directory.shared.ldap.util.ArrayUtils;
@@ -64,7 +64,9 @@
public void testObjectFactory() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
+
LdapContext sysRoot = getSystemContext( service );
sysRoot.addToEnvironment( Context.OBJECT_FACTORIES, PersonObjectFactory.class.getName() );
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java Thu Aug 14 16:12:09 2008
@@ -21,10 +21,10 @@
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.integ.CiRunner;
import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.exception.LdapNamingException;
import org.apache.directory.shared.ldap.ldif.LdifEntry;
@@ -100,7 +100,8 @@
td.rootCtx = getSystemContext( service );
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
// -------------------------------------------------------------------
// Adds a referral entry regardless of referral handling settings
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceIT.java Thu Aug 14 16:12:09 2008
@@ -21,8 +21,8 @@
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.integ.CiRunner;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
import org.apache.directory.shared.ldap.constants.JndiPropertyConstants;
@@ -270,7 +270,8 @@
public void testConfirmNonAdminUserDnIsCreatorsName() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
- getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) );
LdapContext sysRoot = getSystemContext( service );
createData( sysRoot );
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceIT.java Thu Aug 14 16:12:09 2008
@@ -127,6 +127,7 @@
{
LdapDN dn = new LdapDN( getSubschemaSubentryDN() );
Attribute attr = new AttributeImpl( opAttr );
+
for ( String description : descriptions )
{
attr.add( description );
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java Thu Aug 14 16:12:09 2008
@@ -32,6 +32,7 @@
import javax.naming.ldap.LdapContext;
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.integ.CiRunner;
import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
@@ -179,13 +180,15 @@
assertFalse( ldifReader.hasNext() );
// should be fine with unique OID
- LdapContext root = getRootContext( service );
- root.createSubcontext( numberOfGunsAttrEntry.getDn(), numberOfGunsAttrEntry.getAttributes() );
-
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), numberOfGunsAttrEntry.getEntry() ) );
+
// should blow chuncks using same OID
try
{
- root.createSubcontext( shipOCEntry.getDn(), shipOCEntry.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), shipOCEntry.getEntry() ) );
+
fail( "Should not be possible to create two schema entities with the same OID." );
}
catch( NamingException e )
Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java Thu Aug 14 16:12:09 2008
@@ -1095,9 +1095,11 @@
Attributes attrs = getSubschemaSubentryAttributes();
Attribute attrTypes = attrs.get( "attributeTypes" );
AttributeTypeDescription attributeTypeDescription = null;
+
for ( int ii = 0; ii < attrTypes.size(); ii++ )
{
String desc = ( String ) attrTypes.get( ii );
+
if ( desc.indexOf( oid ) != -1 )
{
attributeTypeDescription = ATTRIBUTE_TYPE_DESCRIPTION_SCHEMA_PARSER.parseAttributeTypeDescription( desc );
Modified: directory/apacheds/branches/bigbang/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java (original)
+++ directory/apacheds/branches/bigbang/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java Thu Aug 14 16:12:09 2008
@@ -211,7 +211,8 @@
}
}
- List<Modification> newMods = ServerEntryUtils.toServerModification( modItems,
+ List<Modification> newMods = ServerEntryUtils.convertToServerModification(
+ modItems,
getDirectoryService().getRegistries().getAttributeTypeRegistry() );
try
@@ -285,7 +286,8 @@
public void modifyAttributes( Name name, List<ModificationItemImpl> mods ) throws NamingException
{
List<Modification> newMods = ServerEntryUtils
- .toServerModification( mods, getDirectoryService().getRegistries().getAttributeTypeRegistry() );
+ .convertToServerModification( mods,
+ getDirectoryService().getRegistries().getAttributeTypeRegistry() );
try
{
doModifyOperation( buildTarget( new LdapDN( name ) ), newMods );
Modified: directory/apacheds/branches/bigbang/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java (original)
+++ directory/apacheds/branches/bigbang/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java Thu Aug 14 16:12:09 2008
@@ -25,10 +25,10 @@
import org.apache.directory.server.constants.ServerDNConstants;
import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.shared.ldap.ldif.LdifEntry;
import org.apache.directory.shared.ldap.ldif.LdifReader;
-import org.apache.directory.shared.ldap.name.LdapDN;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,7 +43,6 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
@@ -427,7 +426,8 @@
for ( LdifEntry entry : entries )
{
- rootDSE.createSubcontext( new LdapDN( entry.getDn() ), entry.getAttributes() );
+ service.getAdminSession().add(
+ new DefaultServerEntry( service.getRegistries(), entry.getEntry() ) );
}
}
}
Modified: directory/apacheds/branches/bigbang/core-unit/src/main/java/org/apache/directory/server/core/unit/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-unit/src/main/java/org/apache/directory/server/core/unit/IntegrationUtils.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-unit/src/main/java/org/apache/directory/server/core/unit/IntegrationUtils.java (original)
+++ directory/apacheds/branches/bigbang/core-unit/src/main/java/org/apache/directory/server/core/unit/IntegrationUtils.java Thu Aug 14 16:12:09 2008
@@ -20,16 +20,19 @@
import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.ldif.ChangeType;
import org.apache.directory.shared.ldap.ldif.LdifEntry;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.naming.InvalidNameException;
import javax.naming.NamingException;
-import javax.naming.ldap.LdapContext;
import java.io.File;
import java.io.IOException;
@@ -71,65 +74,65 @@
}
- public static LdifEntry getUserAddLdif() throws InvalidNameException
+ public static LdifEntry getUserAddLdif() throws InvalidNameException, NamingException
{
return getUserAddLdif( "uid=akarasulu,ou=users,ou=system", "test".getBytes(), "Alex Karasulu", "Karasulu" );
}
- public static void apply( LdapContext root, LdifEntry entry ) throws NamingException
+ public static void apply( CoreSession root, LdifEntry entry ) throws Exception
{
LdapDN dn = new LdapDN( entry.getDn() );
switch( entry.getChangeType().getChangeType() )
{
case( ChangeType.ADD_ORDINAL ):
- root.createSubcontext( dn, entry.getAttributes() );
+ root.add(
+ new DefaultServerEntry(
+ root.getDirectoryService().getRegistries(), entry.getEntry() ) );
break;
+
case( ChangeType.DELETE_ORDINAL ):
- root.destroySubcontext( entry.getDn() );
+ root.delete( entry.getDn() );
break;
+
case( ChangeType.MODDN_ORDINAL ):
- LdapDN target = new LdapDN( entry.getNewSuperior() );
- if ( entry.getNewRdn() != null )
- {
- target.add( entry.getNewRdn() );
- }
- else
- {
- target.add( dn.getRdn().toString() );
- }
-
- if ( entry.isDeleteOldRdn() )
- {
- root.addToEnvironment( "java.naming.ldap.deleteRDN", "true" );
- }
- else
- {
- root.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
- }
-
- root.rename( dn, target );
- break;
case( ChangeType.MODRDN_ORDINAL ):
- target = ( LdapDN ) dn.clone();
- target.remove( dn.size() - 1 );
- target.add( entry.getNewRdn() );
-
- if ( entry.isDeleteOldRdn() )
- {
- root.addToEnvironment( "java.naming.ldap.deleteRDN", "true" );
+ Rdn newRdn = new Rdn( entry.getNewRdn() );
+
+ if ( entry.getNewSuperior() != null )
+ {
+ // It's a move. The superior have changed
+ // Let's see if it's a rename too
+ Rdn oldRdn = dn.getRdn();
+ LdapDN newSuperior = new LdapDN( entry.getNewSuperior() );
+
+ if ( dn.size() == 0 )
+ {
+ throw new IllegalStateException( "can't move the root DSE" );
+ }
+ else if ( oldRdn.equals( newRdn ) )
+ {
+ // Same rdn : it's a move
+ root.move( dn, newSuperior );
+ }
+ else
+ {
+ // it's a move and rename
+ root.moveAndRename( dn, newSuperior, newRdn, entry.isDeleteOldRdn() );
+ }
}
else
{
- root.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
+ // it's a rename
+ root.rename( dn, newRdn, entry.isDeleteOldRdn() );
}
-
- root.rename( dn, target );
+
break;
+
case( ChangeType.MODIFY_ORDINAL ):
- root.modifyAttributes( dn, entry.getModificationItemsArray() );
+ root.modify( dn, entry.getModificationItems() );
break;
default:
@@ -139,21 +142,19 @@
public static LdifEntry getUserAddLdif( String dnstr, byte[] password, String cn, String sn )
- throws InvalidNameException
+ throws InvalidNameException, NamingException
{
LdapDN dn = new LdapDN( dnstr );
LdifEntry ldif = new LdifEntry();
ldif.setDn( dnstr );
ldif.setChangeType( ChangeType.Add );
- AttributeImpl attr = new AttributeImpl( "objectClass", "top" );
- attr.add( "person" );
- attr.add( "organizationalPerson" );
- attr.add( "inetOrgPerson" );
+ EntryAttribute attr = new DefaultClientAttribute( "objectClass",
+ "top", "person", "organizationalPerson", "inetOrgPerson" );
+
ldif.addAttribute( attr );
- attr = new AttributeImpl( "ou", "Engineering" );
- attr.add( "People" );
+ attr = new DefaultClientAttribute( "ou", "Engineering", "People" );
ldif.addAttribute( attr );
String uid = ( String ) dn.getRdn().getValue();
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java Thu Aug 14 16:12:09 2008
@@ -21,6 +21,7 @@
import java.net.SocketAddress;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -30,6 +31,7 @@
import org.apache.directory.server.core.authn.LdapPrincipal;
import org.apache.directory.server.core.entry.ClonedServerEntry;
import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.entry.ServerModification;
import org.apache.directory.server.core.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.interceptor.context.CompareOperationContext;
@@ -295,7 +297,19 @@
*/
public void modify( LdapDN dn, List<Modification> mods ) throws Exception
{
- directoryService.getOperationManager().modify( new ModifyOperationContext( this, dn, mods ) );
+ if ( mods == null )
+ {
+ return;
+ }
+
+ List<Modification> serverModifications = new ArrayList<Modification>( mods.size() );
+
+ for ( Modification mod:mods )
+ {
+ serverModifications.add( new ServerModification( directoryService.getRegistries(), mod ) );
+ }
+
+ directoryService.getOperationManager().modify( new ModifyOperationContext( this, dn, serverModifications ) );
}
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Thu Aug 14 16:12:09 2008
@@ -79,6 +79,8 @@
import org.apache.directory.shared.ldap.NotImplementedException;
import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.exception.LdapNamingException;
import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
import org.apache.directory.shared.ldap.ldif.ChangeType;
@@ -633,6 +635,7 @@
}
Tag latest = changeLog.getLatest();
+
if ( null != latest )
{
if ( latest.getRevision() < changeLog.getCurrentRevision() )
@@ -746,26 +749,26 @@
switch( reverse.getChangeType().getChangeType() )
{
case( ChangeType.ADD_ORDINAL ):
- adminSession.add( ServerEntryUtils.toServerEntry( reverse.getAttributes(),
- new LdapDN( reverse.getDn() ), registries ) );
+ adminSession.add(
+ new DefaultServerEntry( registries, reverse.getEntry() ) );
break;
case( ChangeType.DELETE_ORDINAL ):
- adminSession.delete( new LdapDN ( reverse.getDn() ) );
+ adminSession.delete( reverse.getDn() );
break;
case( ChangeType.MODIFY_ORDINAL ):
- adminSession.modify( new LdapDN( reverse.getDn() ),
- ServerEntryUtils.toServerModification( reverse.getModificationItemsArray(),
- registries.getAttributeTypeRegistry() ) );
+ List<Modification> mods = reverse.getModificationItems();
+
+ adminSession.modify( reverse.getDn(), mods );
break;
case( ChangeType.MODDN_ORDINAL ):
// NO BREAK - both ModDN and ModRDN handling is the same
case( ChangeType.MODRDN_ORDINAL ):
- LdapDN forwardDn = new LdapDN( event.getForwardLdif().getDn() );
- LdapDN reverseDn = new LdapDN( event.getReverseLdif().getDn() );
+ LdapDN forwardDn = event.getForwardLdif().getDn();
+ LdapDN reverseDn = event.getReverseLdif().getDn();
moddn( reverseDn, forwardDn, reverse.isDeleteOldRdn() );
@@ -835,7 +838,7 @@
initialize();
showSecurityWarnings();
started = true;
-
+
if ( !testEntries.isEmpty() )
{
createTestEntries();
@@ -1225,13 +1228,14 @@
{
try
{
- LdifEntry entry = testEntry.clone();
- Attributes attributes = entry.getAttributes();
- String dn = entry.getDn();
+ LdifEntry ldifEntry = testEntry.clone();
+ Entry entry = ldifEntry.getEntry();
+ String dn = ldifEntry.getDn().getUpName();
try
{
- getAdminSession().add( ServerEntryUtils.toServerEntry( attributes, new LdapDN( dn ), registries ) );
+ getAdminSession().add(
+ new DefaultServerEntry( registries, entry ) );
}
catch ( Exception e )
{
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authn/LdapPrincipal.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authn/LdapPrincipal.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authn/LdapPrincipal.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authn/LdapPrincipal.java Thu Aug 14 16:12:09 2008
@@ -20,11 +20,15 @@
package org.apache.directory.server.core.authn;
-import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.security.Principal;
import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.LdapDNSerializer;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -35,23 +39,24 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public final class LdapPrincipal implements Principal, Serializable, Cloneable
+public final class LdapPrincipal implements Principal, Cloneable, Externalizable
{
private static final long serialVersionUID = 3906650782395676720L;
/** the normalized distinguished name of the principal */
- private final LdapDN name;
+ private LdapDN name;
/** the no name anonymous user whose DN is the empty String */
public static final LdapPrincipal ANONYMOUS = new LdapPrincipal();
/** the authentication level for this principal */
- private final AuthenticationLevel authenticationLevel;
+ private AuthenticationLevel authenticationLevel;
/** The userPassword
* @todo security risk remove this immediately
+ * The field is transient to avoid being serialized
*/
- private byte[] userPassword;
+ transient private byte[] userPassword;
/**
@@ -175,4 +180,58 @@
return clone;
}
+
+
+ /**
+ * @see Externalizable#readExternal(ObjectInput)
+ *
+ * @param in The stream from which the LdapPrincipal is read
+ * @throws IOException If the stream can't be read
+ * @throws ClassNotFoundException If the LdapPrincipal can't be created
+ */
+ public void readExternal( ObjectInput in ) throws IOException , ClassNotFoundException
+ {
+ // Read the name
+ name = LdapDNSerializer.deserialize( in );
+
+ // read the authentication level
+ int level = in.readInt();
+
+ authenticationLevel = AuthenticationLevel.getLevel( level );
+ }
+
+
+ /**
+ * @see Externalizable#readExternal(ObjectInput)<p>
+ *
+ *@param out The stream in which the LdapPrincipal will be serialized.
+ *The password won't be written !
+ *
+ *@throws IOException If the serialization fail
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException
+ {
+ // Write the name
+ if ( name == null )
+ {
+ LdapDNSerializer.serialize( LdapDN.EMPTY_LDAPDN, out );
+ }
+ else
+ {
+ LdapDNSerializer.serialize( name, out );
+ }
+
+ // write the authentication level
+ if ( authenticationLevel == null )
+ {
+ out.writeInt( AuthenticationLevel.NONE.getLevel() );
+ }
+ else
+ {
+ out.writeInt( authenticationLevel.getLevel() );
+ }
+
+ // and flush the result
+ out.flush();
+ }
}
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java Thu Aug 14 16:12:09 2008
@@ -277,7 +277,16 @@
private void addPerscriptiveAciTuples( OperationContext opContext, Collection<ACITuple> tuples, LdapDN dn,
ServerEntry entry ) throws Exception
{
- EntryAttribute oc = entry.get( objectClassType );
+ EntryAttribute oc = null;
+
+ if ( entry instanceof ClonedServerEntry )
+ {
+ oc = ((ClonedServerEntry)entry).getOriginalEntry().get( objectClassType );
+ }
+ else
+ {
+ oc = entry.get( objectClassType );
+ }
/*
* If the protected entry is a subentry, then the entry being evaluated
@@ -527,7 +536,7 @@
Set<LdapDN> userGroups = groupCache.getGroups( principalDn.toString() );
Collection<ACITuple> tuples = new HashSet<ACITuple>();
- addPerscriptiveAciTuples( deleteContext, tuples, name, entry );
+ addPerscriptiveAciTuples( deleteContext, tuples, name, entry.getOriginalEntry() );
addEntryAciTuples( tuples, entry );
addSubentryAciTuples( deleteContext, tuples, name, entry );
@@ -574,7 +583,7 @@
Set<LdapDN> userGroups = groupCache.getGroups( principalDn.toString() );
Collection<ACITuple> tuples = new HashSet<ACITuple>();
- addPerscriptiveAciTuples( opContext, tuples, name, entry );
+ addPerscriptiveAciTuples( opContext, tuples, name, entry.getOriginalEntry() );
addEntryAciTuples( tuples, entry );
addSubentryAciTuples( opContext, tuples, name, entry );
@@ -792,7 +801,7 @@
{
LdapDN name = renameContext.getDn();
- ServerEntry entry = renameContext.lookup( name, ByPassConstants.LOOKUP_BYPASS );
+ ClonedServerEntry entry = renameContext.lookup( name, ByPassConstants.LOOKUP_BYPASS );
LdapPrincipal principal = renameContext.getSession().getEffectivePrincipal();
LdapDN principalDn = principal.getJndiName();
@@ -824,7 +833,7 @@
Set<LdapDN> userGroups = groupCache.getGroups( principalDn.toString() );
Collection<ACITuple> tuples = new HashSet<ACITuple>();
- addPerscriptiveAciTuples( renameContext, tuples, name, entry );
+ addPerscriptiveAciTuples( renameContext, tuples, name, entry.getOriginalEntry() );
addEntryAciTuples( tuples, entry );
addSubentryAciTuples( renameContext, tuples, name, entry );
@@ -844,7 +853,7 @@
LdapDN oriChildName = moveAndRenameContext.getDn();
LdapDN newParentName = moveAndRenameContext.getParent();
- ServerEntry entry = moveAndRenameContext.lookup( oriChildName, ByPassConstants.LOOKUP_BYPASS );
+ ClonedServerEntry entry = moveAndRenameContext.lookup( oriChildName, ByPassConstants.LOOKUP_BYPASS );
LdapPrincipal principal = moveAndRenameContext.getSession().getEffectivePrincipal();
LdapDN principalDn = principal.getJndiName();
@@ -871,7 +880,7 @@
Set<LdapDN> userGroups = groupCache.getGroups( principalDn.toString() );
Collection<ACITuple> tuples = new HashSet<ACITuple>();
- addPerscriptiveAciTuples( moveAndRenameContext, tuples, oriChildName, entry );
+ addPerscriptiveAciTuples( moveAndRenameContext, tuples, oriChildName, entry.getOriginalEntry() );
addEntryAciTuples( tuples, entry );
addSubentryAciTuples( moveAndRenameContext, tuples, oriChildName, entry );
@@ -923,7 +932,7 @@
LdapDN newParentName = moveContext.getParent();
// Access the principal requesting the operation, and bypass checks if it is the admin
- ServerEntry entry = moveContext.lookup( oriChildName, ByPassConstants.LOOKUP_BYPASS );
+ ClonedServerEntry entry = moveContext.lookup( oriChildName, ByPassConstants.LOOKUP_BYPASS );
LdapDN newName = ( LdapDN ) newParentName.clone();
newName.add( oriChildName.get( oriChildName.size() - 1 ) );
@@ -950,7 +959,7 @@
Set<LdapDN> userGroups = groupCache.getGroups( principalDn.toString() );
Collection<ACITuple> tuples = new HashSet<ACITuple>();
- addPerscriptiveAciTuples( moveContext, tuples, oriChildName, entry );
+ addPerscriptiveAciTuples( moveContext, tuples, oriChildName, entry.getOriginalEntry() );
addEntryAciTuples( tuples, entry );
addSubentryAciTuples( moveContext, tuples, oriChildName, entry );
@@ -1055,7 +1064,7 @@
Set<LdapDN> userGroups = groupCache.getGroups( principalDn.toNormName() );
Collection<ACITuple> tuples = new HashSet<ACITuple>();
- addPerscriptiveAciTuples( opContext, tuples, name, entry );
+ addPerscriptiveAciTuples( opContext, tuples, name, entry.getOriginalEntry() );
addEntryAciTuples( tuples, entry );
addSubentryAciTuples( opContext, tuples, name, entry );
@@ -1082,7 +1091,7 @@
}
// get the present matched name
- ServerEntry entry;
+ ClonedServerEntry entry;
LdapDN matched = next.getMatchedName( opContext );
// check if we have disclose on error permission for the entry at the matched dn
@@ -1094,7 +1103,7 @@
Set<LdapDN> userGroups = groupCache.getGroups( principalDn.toString() );
Collection<ACITuple> tuples = new HashSet<ACITuple>();
- addPerscriptiveAciTuples( opContext, tuples, matched, entry );
+ addPerscriptiveAciTuples( opContext, tuples, matched, entry.getOriginalEntry() );
addEntryAciTuples( tuples, entry );
addSubentryAciTuples( opContext, tuples, matched, entry );