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/05/01 02:06:46 UTC
svn commit: r652410 [7/14] - in /directory: apacheds/branches/bigbang/
apacheds/branches/bigbang/apacheds-jdbm/
apacheds/branches/bigbang/apacheds-jdbm/src/
apacheds/branches/bigbang/apacheds-jdbm/src/etc/
apacheds/branches/bigbang/apacheds-jdbm/src/ex...
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java Wed Apr 30 17:06:41 2008
@@ -19,36 +19,55 @@
*/
package org.apache.directory.server.core.entry;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
+import java.io.ObjectInputStream;
import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
import javax.naming.NamingException;
+import jdbm.helper.Serializer;
+
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.name.LdapDNSerializer;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class ServerEntrySerializer
+public class ServerEntrySerializer implements Serializer
{
+ public static final long serialVersionUID = 1L;
+
+ /** the logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( ServerEntrySerializer.class );
+
+ /**
+ * Speedup for logs
+ */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
/** The registries reference */
- private Registries registries;
+ private transient Registries registries;
/** Flag used for ServerStringValue */
- private static final boolean HR_VALUE = true;
-
+ private transient static final boolean HR_VALUE = true;
+
/** Flag used for streamed values */
- private static final boolean STREAMED_VALUE = true;
+ private transient static final boolean STREAMED_VALUE = true;
+
-
/**
* Creates a new instance of ServerEntrySerializer.
*
@@ -58,7 +77,8 @@
{
this.registries = registries;
}
-
+
+
/**
* @see Externalizable#writeExternal(ObjectOutput)
* <p>
@@ -79,8 +99,13 @@
* </li>
* We have to store the UPid, and all the values, if any.
*/
- public void serialize( ServerEntry entry, ObjectOutput out ) throws IOException, NamingException
+ public byte[] serialize( Object object ) throws IOException
{
+ ServerEntry entry = ( ServerEntry ) object;
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
// First, the DN
if ( entry.getDn() == null )
{
@@ -92,39 +117,54 @@
// Write the DN
LdapDNSerializer.serialize( entry.getDn(), out );
}
-
+
// Then the attributes.
out.writeInt( entry.size() );
-
+
// Iterate through the attrbutes. We store the Attribute
// here, to be able to restore it in the readExternal :
// we need access to the registries, which are not available
// in the ServerAttribute class.
- for ( EntryAttribute attribute:entry )
+ for ( EntryAttribute attribute : entry )
{
// We store the OID, as the AttributeType might have no name
- out.writeUTF( ((ServerAttribute)attribute).getAttributeType().getOid() );
-
+ out.writeUTF( ( ( ServerAttribute ) attribute ).getAttributeType().getOid() );
+
// And store the attribute.
// Store the UP id
out.writeUTF( attribute.getUpId() );
-
+
// The number of values
out.writeInt( attribute.size() );
- for ( Value<?> value:attribute )
+ for ( Value<?> value : attribute )
{
- serializeValue( value, out );
+ try
+ {
+ serializeValue( value, out );
+ }
+ catch ( NamingException ne )
+ {
+ // TODO Handle this exception
+ }
}
}
// Note : we don't store the ObjectClassAttribute. I has already
// been stored as an attribute.
-
+
out.flush();
+
+ if ( IS_DEBUG )
+ {
+ System.out.println( ">------------------------------------------------" );
+ System.out.println( "Serialize " + entry );
+ }
+
+ return baos.toByteArray();
}
-
-
+
+
/**
* We will write the value and the normalized value, only
* if the normalized value is different.
@@ -140,12 +180,12 @@
private void serializeValue( Value<?> value, ObjectOutput out ) throws IOException, NamingException
{
out.writeBoolean( value.isValid() );
-
+
if ( value instanceof ServerStringValue )
{
out.writeBoolean( HR_VALUE );
out.writeBoolean( !STREAMED_VALUE );
- ServerStringValue ssv = (ServerStringValue)value;
+ ServerStringValue ssv = ( ServerStringValue ) value;
if ( ssv.get() == null )
{
@@ -165,35 +205,35 @@
{
out.writeBoolean( !HR_VALUE );
out.writeBoolean( !STREAMED_VALUE );
- ServerBinaryValue sbv = (ServerBinaryValue)value;
-
+ ServerBinaryValue sbv = ( ServerBinaryValue ) value;
+
if ( sbv.get() == null )
{
out.writeInt( 0 );
- out.writeInt( 0 );
+ out.writeInt( 0 );
}
else
{
// Save the UP value and the normalized value if !=
out.writeInt( sbv.get().length );
out.write( sbv.get() );
-
+
out.writeBoolean( sbv.isSame() );
-
+
if ( !sbv.isSame() )
{
sbv.normalize();
-
+
out.writeInt( sbv.getNormalizedValueReference().length );
out.write( sbv.getNormalizedValueReference() );
}
}
}
-
+
out.flush();
}
-
+
/**
* We will write the value and the normalized value, only
* if the normalized value is different.
@@ -206,33 +246,33 @@
* [UP value]
* [Norm value] (will be null if normValue == upValue)
*/
- private Value<?> deserializeValue( ObjectInput in, AttributeType attributeType ) throws IOException, NamingException
+ private Value<?> deserializeValue( ObjectInput in, AttributeType attributeType ) throws IOException,
+ NamingException
{
boolean isValid = in.readBoolean();
boolean isHR = in.readBoolean();
boolean isStreamed = in.readBoolean();
-
+
if ( isHR )
{
if ( !isStreamed )
{
String value = in.readUTF();
-
+
if ( value.length() == 0 )
{
value = null;
}
-
+
String normalized = in.readUTF();
-
+
if ( normalized.length() == 0 )
{
normalized = null;
}
-
-
+
Value<?> ssv = new ServerStringValue( attributeType, value, normalized, isValid );
-
+
return ssv;
}
else
@@ -245,36 +285,36 @@
if ( !isStreamed )
{
int length = in.readInt();
-
+
byte[] value = new byte[length];
-
+
if ( length != 0 )
{
in.read( value );
}
-
+
byte[] normalized = null;
boolean same = in.readBoolean();
-
+
// Now, if the normalized value is different from the wrapped value,
// read the normalized value.
if ( !same )
{
length = in.readInt();
-
+
normalized = new byte[length];
- if ( length != 0 )
- {
- in.read( normalized );
- }
+ if ( length != 0 )
+ {
+ in.read( normalized );
+ }
}
else
{
normalized = value;
}
-
+
Value<?> sbv = new ServerBinaryValue( attributeType, value, normalized, same, isValid );
-
+
return sbv;
}
else
@@ -284,45 +324,66 @@
}
}
-
+
/**
* Deserialize a ServerEntry
*/
- public ServerEntry deserialize( ObjectInput in ) throws IOException, NamingException, ClassNotFoundException
+ public Object deserialize( byte[] bytes ) throws IOException
{
- // First, read the DN
- LdapDN dn = LdapDNSerializer.deserialize( in );
-
- // Read the number of attributes
- int nbAttrs = in.readInt();
-
- ServerEntry serverEntry = new DefaultServerEntry( registries, dn );
-
- // Read all the attributes
- for ( int i = 0; i < nbAttrs; i++ )
- {
- // The oid
- String oid = in.readUTF();
-
- AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( oid );
-
- // The UP id
- String upId = in.readUTF();
-
- // The number of values
- int nbValues = in.readInt();
-
- ServerAttribute serverAttribute = new DefaultServerAttribute( upId, attributeType );
-
- for ( int j = 0; j < nbValues; j++ )
+ ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( bytes ) );
+
+ try
+ {
+ // First, read the DN
+ LdapDN dn = LdapDNSerializer.deserialize( in );
+
+ // Read the number of attributes
+ int nbAttrs = in.readInt();
+
+ ServerEntry serverEntry = new DefaultServerEntry( registries, dn );
+
+ // Read all the attributes
+ for ( int i = 0; i < nbAttrs; i++ )
+ {
+ // The oid
+ String oid = in.readUTF();
+
+ AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( oid );
+
+ // The UP id
+ String upId = in.readUTF();
+
+ // The number of values
+ int nbValues = in.readInt();
+
+ ServerAttribute serverAttribute = new DefaultServerAttribute( upId, attributeType );
+
+ for ( int j = 0; j < nbValues; j++ )
+ {
+ Value<?> value = deserializeValue( in, attributeType );
+ serverAttribute.add( value );
+ }
+
+ serverEntry.put( serverAttribute );
+ }
+
+ if ( IS_DEBUG )
{
- Value<?> value = deserializeValue( in, attributeType );
- serverAttribute.add( value );
+ System.out.println( "<------------------------------------------------" );
+ System.out.println( "Deserialize " + serverEntry );
}
-
- serverEntry.put( serverAttribute );
+
+ return serverEntry;
+ }
+ catch ( ClassNotFoundException cnfe )
+ {
+ // TODO Handle this exception
+ return null;
+ }
+ catch ( NamingException ne )
+ {
+ // TODO Handle this exception
+ return null;
}
-
- return serverEntry;
}
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java Wed Apr 30 17:06:41 2008
@@ -109,10 +109,18 @@
public ServerStringValue( AttributeType attributeType )
{
super();
- assert checkAttributeType( attributeType ) == null : logAssert( checkAttributeType( attributeType ) );
+ if ( attributeType == null )
+ {
+ throw new IllegalArgumentException( "The AttributeType parameter should not be null" );
+ }
try
{
+ if ( attributeType.getSyntax() == null )
+ {
+ throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
+ }
+
if ( ! attributeType.getSyntax().isHumanReadable() )
{
LOG.warn( "Treating a value of a binary attribute {} as a String: " +
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java Wed Apr 30 17:06:41 2008
@@ -1476,7 +1476,7 @@
assertEquals( " CommonName: ''\n", attr.toString() );
attr.put( "a", "b" );
- assertEquals( " CommonName: 'a'\n CommonName: 'b'\n", attr.toString() );
+ assertEquals( " CommonName: a\n CommonName: b\n", attr.toString() );
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java Wed Apr 30 17:06:41 2008
@@ -3921,8 +3921,8 @@
String expected =
"ServerEntry\n" +
" dn: dc=example,dc=com\n" +
- " ObjectClass: 'top'\n" +
- " ObjectClass: 'person'\n" +
+ " ObjectClass: top\n" +
+ " ObjectClass: person\n" +
" ObjectClass: ''\n" +
" UserPassword: '0x61 0x62 '\n" +
" UserPassword: '0x62 '\n" +
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.java Wed Apr 30 17:06:41 2008
@@ -120,7 +120,7 @@
new ServerBinaryValue( null );
fail();
}
- catch ( AssertionError ae )
+ catch ( IllegalArgumentException iae )
{
// Expected...
}
@@ -133,7 +133,7 @@
new ServerBinaryValue( at );
fail();
}
- catch ( AssertionError ae )
+ catch ( IllegalArgumentException ae )
{
// Expected...
}
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=652410&r1=652409&r2=652410&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 Wed Apr 30 17:06:41 2008
@@ -19,11 +19,7 @@
*/
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.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -114,15 +110,9 @@
ServerEntrySerializer ses = new ServerEntrySerializer( registries );
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( baos );
-
- ses.serialize( entry, out );
-
- byte[] data = baos.toByteArray();
- ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+ byte[] data = ses.serialize( entry );
- ServerEntry result = ses.deserialize( in );
+ ServerEntry result = (ServerEntry)ses.deserialize( data );
assertEquals( entry, result );
}
@@ -136,15 +126,9 @@
ServerEntrySerializer ses = new ServerEntrySerializer( registries );
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( baos );
-
- ses.serialize( entry, out );
-
- byte[] data = baos.toByteArray();
- ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+ byte[] data = ses.serialize( entry );
- ServerEntry result = ses.deserialize( in );
+ ServerEntry result = (ServerEntry)ses.deserialize( data );
assertEquals( entry, result );
}
@@ -159,16 +143,10 @@
entry.add( "objectClass", "top", "person", "inetOrgPerson", "organizationalPerson" );
ServerEntrySerializer ses = new ServerEntrySerializer( registries );
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( baos );
- ses.serialize( entry, out );
-
- byte[] data = baos.toByteArray();
- ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+ byte[] data = ses.serialize( entry );
- ServerEntry result = ses.deserialize( in );
+ ServerEntry result = (ServerEntry)ses.deserialize( data );
assertEquals( entry, result );
}
@@ -187,15 +165,9 @@
ServerEntrySerializer ses = new ServerEntrySerializer( registries );
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( baos );
-
- ses.serialize( entry, out );
-
- byte[] data = baos.toByteArray();
- ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+ byte[] data = ses.serialize( entry );
- ServerEntry result = ses.deserialize( in );
+ 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/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=652410&r1=652409&r2=652410&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 Wed Apr 30 17:06:41 2008
@@ -254,7 +254,7 @@
new ServerStringValue( null );
fail();
}
- catch ( AssertionError ae )
+ catch ( IllegalArgumentException iae )
{
// Expected...
}
@@ -267,7 +267,7 @@
new ServerStringValue( at );
fail();
}
- catch ( AssertionError ae )
+ catch ( IllegalArgumentException iae )
{
// Expected...
}
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=652410&r1=652409&r2=652410&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 Wed Apr 30 17:06:41 2008
@@ -58,13 +58,11 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-@RunWith ( CiRunner.class )
+@RunWith(CiRunner.class)
public class SchemaPersistenceIT
{
private static final String SUBSCHEMA_SUBENTRY = "subschemaSubentry";
- private static final AttributeTypeDescriptionSchemaParser ATTRIBUTE_TYPE_DESCRIPTION_SCHEMA_PARSER =
- new AttributeTypeDescriptionSchemaParser();
-
+ private static final AttributeTypeDescriptionSchemaParser ATTRIBUTE_TYPE_DESCRIPTION_SCHEMA_PARSER = new AttributeTypeDescriptionSchemaParser();
public static DirectoryService service;
@@ -78,48 +76,52 @@
@Test
public void testAddAttributeTypePersistence() throws Exception
{
- enableSchema( "nis" );
- List<String> descriptions = new ArrayList<String>();
+ try
+ {
+ enableSchema( "nis" );
+ List<String> descriptions = new ArrayList<String>();
- // -------------------------------------------------------------------
- // test successful add with everything
- // -------------------------------------------------------------------
+ // -------------------------------------------------------------------
+ // test successful add with everything
+ // -------------------------------------------------------------------
+
+ descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'type0' " + "OBSOLETE SUP 2.5.4.41 "
+ + "EQUALITY caseExactIA5Match " + "ORDERING octetStringOrderingMatch "
+ + "SUBSTR caseExactIA5SubstringsMatch COLLECTIVE " + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
+ + "SINGLE-VALUE USAGE userApplications X-SCHEMA 'nis' )" );
+ descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'type1' 'altName' ) "
+ + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 "
+ + "NO-USER-MODIFICATION USAGE directoryOperation X-SCHEMA 'nis' )" );
+
+ modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+
+ checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+ checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+
+ // sync operation happens anyway on shutdowns but just to make sure we can do it again
+ service.sync();
- descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'type0' " +
- "OBSOLETE SUP 2.5.4.41 " +
- "EQUALITY caseExactIA5Match " +
- "ORDERING octetStringOrderingMatch " +
- "SUBSTR caseExactIA5SubstringsMatch COLLECTIVE " +
- "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 " +
- "SINGLE-VALUE USAGE userApplications X-SCHEMA 'nis' )" );
- descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'type1' 'altName' ) " +
- "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 " +
- "NO-USER-MODIFICATION USAGE directoryOperation X-SCHEMA 'nis' )" );
-
- modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
-
- checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
- checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
-
- // sync operation happens anyway on shutdowns but just to make sure we can do it again
- service.sync();
-
- service.shutdown();
- service.startup();
-
- AttributesImpl attrs = new AttributesImpl( "objectClass", "metaSchema" );
- attrs.put( "cn", "blah" );
- getSchemaContext( service ).createSubcontext( "cn=blah", attrs );
-
- checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
- checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+ service.shutdown();
+ service.startup();
+
+ AttributesImpl attrs = new AttributesImpl( "objectClass", "metaSchema" );
+ attrs.put( "cn", "blah" );
+ getSchemaContext( service ).createSubcontext( "cn=blah", attrs );
+
+ checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+ checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
-
+
// -----------------------------------------------------------------------
// Private Utility Methods
// -----------------------------------------------------------------------
-
private void modify( int op, List<String> descriptions, String opAttr ) throws Exception
{
@@ -129,14 +131,14 @@
{
attr.add( description );
}
-
+
Attributes mods = new AttributesImpl();
mods.put( attr );
-
+
getRootContext( service ).modifyAttributes( dn, op, mods );
}
-
-
+
+
private void enableSchema( String schemaName ) throws NamingException
{
// now enable the test schema
@@ -145,8 +147,8 @@
mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
getSchemaContext( service ).modifyAttributes( "cn=" + schemaName, mods );
}
-
-
+
+
/**
* Get's the subschemaSubentry attribute value from the rootDSE.
*
@@ -157,8 +159,9 @@
{
SearchControls controls = new SearchControls();
controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- controls.setReturningAttributes( new String[]{ SUBSCHEMA_SUBENTRY } );
-
+ controls.setReturningAttributes( new String[]
+ { SUBSCHEMA_SUBENTRY } );
+
NamingEnumeration<SearchResult> results = getRootContext( service ).search( "", "(objectClass=*)", controls );
SearchResult result = results.next();
results.close();
@@ -166,7 +169,7 @@
return ( String ) subschemaSubentry.get();
}
-
+
/**
* Gets the subschemaSubentry attributes for the global schema.
*
@@ -177,8 +180,9 @@
{
SearchControls controls = new SearchControls();
controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- controls.setReturningAttributes( new String[]{ "+", "*" } );
-
+ controls.setReturningAttributes( new String[]
+ { "+", "*" } );
+
NamingEnumeration<SearchResult> results = getRootContext( service ).search( getSubschemaSubentryDN(),
"(objectClass=*)", controls );
SearchResult result = results.next();
@@ -192,20 +196,21 @@
// -------------------------------------------------------------------
// check first to see if it is present in the subschemaSubentry
// -------------------------------------------------------------------
-
+
Attributes attrs = getSubschemaSubentryAttributes();
Attribute attrTypes = attrs.get( "attributeTypes" );
- AttributeTypeDescription attributeTypeDescription = null;
+ 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 );
+ attributeTypeDescription = ATTRIBUTE_TYPE_DESCRIPTION_SCHEMA_PARSER
+ .parseAttributeTypeDescription( desc );
break;
}
}
-
+
if ( isPresent )
{
assertNotNull( attributeTypeDescription );
@@ -219,9 +224,9 @@
// -------------------------------------------------------------------
// check next to see if it is present in the schema partition
// -------------------------------------------------------------------
-
+
attrs = null;
-
+
if ( isPresent )
{
attrs = getSchemaContext( service ).getAttributes( "m-oid=" + oid + ",ou=attributeTypes,cn=" + schemaName );
@@ -232,21 +237,22 @@
//noinspection EmptyCatchBlock
try
{
- attrs = getSchemaContext( service ).getAttributes( "m-oid=" + oid + ",ou=attributeTypes,cn=" + schemaName );
+ attrs = getSchemaContext( service ).getAttributes(
+ "m-oid=" + oid + ",ou=attributeTypes,cn=" + schemaName );
fail( "should never get here" );
}
- catch( NamingException e )
+ catch ( NamingException e )
{
}
assertNull( attrs );
}
-
+
// -------------------------------------------------------------------
// check to see if it is present in the attributeTypeRegistry
// -------------------------------------------------------------------
-
- if ( isPresent )
- {
+
+ if ( isPresent )
+ {
assertTrue( service.getRegistries().getAttributeTypeRegistry().hasAttributeType( oid ) );
}
else
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=652410&r1=652409&r2=652410&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 Wed Apr 30 17:06:41 2008
@@ -994,7 +994,7 @@
serverEntry.put( SchemaConstants.DISPLAY_NAME_AT, "Directory Superuser" );
TlsKeyGenerator.addKeyPair( serverEntry );
- partitionNexus.add( new AddOperationContext( registries, PartitionNexus.getAdminName(), serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
}
// -------------------------------------------------------------------
@@ -1019,7 +1019,7 @@
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- partitionNexus.add( new AddOperationContext( registries, userDn, serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
}
// -------------------------------------------------------------------
@@ -1033,7 +1033,7 @@
{
firstStart = true;
- ServerEntry serverEntry = new DefaultServerEntry( registries, userDn );
+ ServerEntry serverEntry = new DefaultServerEntry( registries, groupDn );
serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
SchemaConstants.TOP_OC,
@@ -1043,7 +1043,7 @@
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- partitionNexus.add( new AddOperationContext( registries, groupDn, serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
}
// -------------------------------------------------------------------
@@ -1057,7 +1057,7 @@
{
firstStart = true;
- ServerEntry serverEntry = new DefaultServerEntry( registries, userDn );
+ ServerEntry serverEntry = new DefaultServerEntry( registries, name );
serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
SchemaConstants.TOP_OC,
@@ -1068,7 +1068,7 @@
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- partitionNexus.add( new AddOperationContext( registries, name, serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
Interceptor authzInterceptor = interceptorChain.get( AciAuthorizationInterceptor.class.getName() );
@@ -1109,7 +1109,7 @@
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- partitionNexus.add( new AddOperationContext( registries, configurationDn, serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
}
// -------------------------------------------------------------------
@@ -1130,7 +1130,7 @@
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- partitionNexus.add( new AddOperationContext( registries, partitionsDn, serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
}
// -------------------------------------------------------------------
@@ -1151,7 +1151,7 @@
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- partitionNexus.add( new AddOperationContext( registries, servicesDn, serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
}
// -------------------------------------------------------------------
@@ -1172,7 +1172,7 @@
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- partitionNexus.add( new AddOperationContext( registries, interceptorsDn, serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
}
// -------------------------------------------------------------------
@@ -1196,7 +1196,7 @@
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- partitionNexus.add( new AddOperationContext( registries, sysPrefRootDn, serverEntry ) );
+ partitionNexus.add( new AddOperationContext( registries, serverEntry ) );
}
return firstStart;
@@ -1493,7 +1493,7 @@
}
catch ( Exception e )
{
- LOG.error( "Cannot build an entry for '{}' and this DN :'{}'", ldif, dn );
+ LOG.error( "Cannot build an entry for '{}' and this DN :'{}'", ldif, dn );
// do nothing
return null;
}
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java Wed Apr 30 17:06:41 2008
@@ -19,6 +19,7 @@
*/
package org.apache.directory.server.core.authz;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -40,6 +41,7 @@
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.filter.BranchNode;
import org.apache.directory.shared.ldap.filter.EqualityNode;
import org.apache.directory.shared.ldap.filter.OrNode;
@@ -71,10 +73,10 @@
/** String key for the DN of a group to a Set (HashSet) for the Strings of member DNs */
private final Map<String, Set<String>> groups = new HashMap<String, Set<String>>();
-
+
/** a handle on the partition nexus */
private final PartitionNexus nexus;
-
+
/** A storage for the member attributeType */
private AttributeType memberAT;
@@ -85,12 +87,13 @@
* The OIDs normalizer map
*/
private Map<String, OidNormalizer> normalizerMap;
-
+
/** the normalized dn of the administrators group */
private LdapDN administratorsGroupDn;
-
+
private static final Set<LdapDN> EMPTY_GROUPS = new HashSet<LdapDN>();
-
+
+
/**
* Creates a static group cache.
*
@@ -99,11 +102,11 @@
*/
public GroupCache( DirectoryService directoryService ) throws NamingException
{
- normalizerMap = directoryService.getRegistries().getAttributeTypeRegistry().getNormalizerMapping();
+ normalizerMap = directoryService.getRegistries().getAttributeTypeRegistry().getNormalizerMapping();
nexus = directoryService.getPartitionNexus();
AttributeTypeRegistry attributeTypeRegistry = directoryService.getRegistries().getAttributeTypeRegistry();
-
- memberAT = attributeTypeRegistry.lookup( SchemaConstants.MEMBER_AT_OID );
+
+ memberAT = attributeTypeRegistry.lookup( SchemaConstants.MEMBER_AT_OID );
uniqueMemberAT = attributeTypeRegistry.lookup( SchemaConstants.UNIQUE_MEMBER_AT_OID );
// stuff for dealing with the admin group
@@ -127,23 +130,25 @@
// normalized sets of members to cache within the map
BranchNode filter = new OrNode();
- filter.addNode( new EqualityNode( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.GROUP_OF_NAMES_OC ) );
- filter.addNode( new EqualityNode( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC) );
+ filter.addNode( new EqualityNode( SchemaConstants.OBJECT_CLASS_AT, new ClientStringValue(
+ SchemaConstants.GROUP_OF_NAMES_OC ) ) );
+ filter.addNode( new EqualityNode( SchemaConstants.OBJECT_CLASS_AT, new ClientStringValue(
+ SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC ) ) );
Iterator<String> suffixes = nexus.listSuffixes( null );
-
+
while ( suffixes.hasNext() )
{
String suffix = suffixes.next();
LdapDN baseDn = new LdapDN( suffix );
SearchControls ctls = new SearchControls();
ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
- NamingEnumeration<ServerSearchResult> results = nexus.search(
- new SearchOperationContext( registries, baseDn, AliasDerefMode.DEREF_ALWAYS, filter, ctls ) );
+ NamingEnumeration<ServerSearchResult> results = nexus.search( new SearchOperationContext( registries,
+ baseDn, AliasDerefMode.DEREF_ALWAYS, filter, ctls ) );
while ( results.hasMore() )
{
- ServerSearchResult result = results.next();
+ ServerSearchResult result = results.next();
LdapDN groupDn = result.getDn().normalize( normalizerMap );
EntryAttribute members = getMemberAttribute( result.getServerEntry() );
@@ -158,7 +163,7 @@
LOG.warn( "Found group '{}' without any member or uniqueMember attributes", groupDn.getUpName() );
}
}
-
+
results.close();
}
@@ -183,14 +188,14 @@
if ( oc == null )
{
EntryAttribute member = entry.get( memberAT );
-
+
if ( member != null )
{
return member;
}
EntryAttribute uniqueMember = entry.get( uniqueMemberAT );
-
+
if ( uniqueMember != null )
{
return uniqueMember;
@@ -199,14 +204,13 @@
return null;
}
- if ( oc.contains( SchemaConstants.GROUP_OF_NAMES_OC ) ||
- oc.contains( SchemaConstants.GROUP_OF_NAMES_OC_OID ) )
+ if ( oc.contains( SchemaConstants.GROUP_OF_NAMES_OC ) || oc.contains( SchemaConstants.GROUP_OF_NAMES_OC_OID ) )
{
return entry.get( memberAT );
}
- if ( oc.contains( SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC ) ||
- oc.contains( SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC_OID ))
+ if ( oc.contains( SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC )
+ || oc.contains( SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC_OID ) )
{
return entry.get( uniqueMemberAT );
}
@@ -224,11 +228,11 @@
*/
private void addMembers( Set<String> memberSet, EntryAttribute members ) throws NamingException
{
- for ( Value<?> value:members )
+ for ( Value<?> value : members )
{
// get and normalize the DN of the member
- String memberDn = (String)value.get();
+ String memberDn = ( String ) value.get();
try
{
@@ -253,10 +257,10 @@
*/
private void removeMembers( Set<String> memberSet, EntryAttribute members ) throws NamingException
{
- for ( Value<?> value:members )
+ for ( Value<?> value : members )
{
// get and normalize the DN of the member
- String memberDn = (String)value.get();
+ String memberDn = ( String ) value.get();
try
{
@@ -292,7 +296,7 @@
Set<String> memberSet = new HashSet<String>( members.size() );
addMembers( memberSet, members );
groups.put( name.getNormName(), memberSet );
-
+
if ( IS_DEBUG )
{
LOG.debug( "group cache contents after adding '{}' :\n {}", name.getUpName(), groups );
@@ -317,7 +321,7 @@
}
groups.remove( name.getNormName() );
-
+
if ( IS_DEBUG )
{
LOG.debug( "group cache contents after deleting '{}' :\n {}", name.getUpName(), groups );
@@ -334,28 +338,29 @@
* @param members the members being added, removed or replaced
* @throws NamingException if there are problems accessing attribute values
*/
- private void modify( Set<String> memberSet, ModificationOperation modOp, EntryAttribute members ) throws NamingException
+ private void modify( Set<String> memberSet, ModificationOperation modOp, EntryAttribute members )
+ throws NamingException
{
switch ( modOp )
{
- case ADD_ATTRIBUTE :
+ case ADD_ATTRIBUTE:
addMembers( memberSet, members );
break;
-
- case REPLACE_ATTRIBUTE :
+
+ case REPLACE_ATTRIBUTE:
if ( members.size() > 0 )
{
memberSet.clear();
addMembers( memberSet, members );
}
-
+
break;
-
- case REMOVE_ATTRIBUTE :
+
+ case REMOVE_ATTRIBUTE:
removeMembers( memberSet, members );
break;
-
+
default:
throw new InternalError( "Undefined modify operation value of " + modOp );
}
@@ -371,7 +376,8 @@
* @param entry the group entry being modified
* @throws NamingException if there are problems accessing attribute values
*/
- public void groupModified( LdapDN name, List<Modification> mods, ServerEntry entry, Registries registries ) throws NamingException
+ public void groupModified( LdapDN name, List<Modification> mods, ServerEntry entry, Registries registries )
+ throws NamingException
{
EntryAttribute members = null;
String memberAttrId = null;
@@ -394,24 +400,21 @@
return;
}
- for ( Modification modification:mods )
+ for ( Modification modification : mods )
{
if ( memberAttrId.equalsIgnoreCase( modification.getAttribute().getId() ) )
{
Set<String> memberSet = groups.get( name.getNormName() );
-
+
if ( memberSet != null )
{
- modify(
- memberSet,
- modification.getOperation(),
- (ServerAttribute)modification.getAttribute() );
+ modify( memberSet, modification.getOperation(), ( ServerAttribute ) modification.getAttribute() );
}
-
+
break;
}
}
-
+
if ( IS_DEBUG )
{
LOG.debug( "group cache contents after modifying '{}' :\n {}", name.getUpName(), groups );
@@ -438,19 +441,19 @@
}
Set<String> memberSet = groups.get( name.getNormName() );
-
+
if ( memberSet != null )
{
modify( memberSet, modOp, members );
}
-
+
if ( IS_DEBUG )
{
LOG.debug( "group cache contents after modifying '{}' :\n {}", name.getUpName(), groups );
}
}
-
+
/**
* An optimization. By having this method here we can directly access the group
* membership information and lookup to see if the principalDn is contained within.
@@ -464,18 +467,18 @@
{
return true;
}
-
+
Set<String> members = groups.get( administratorsGroupDn.getNormName() );
-
+
if ( members == null )
{
LOG.warn( "What do you mean there is no administrators group? This is bad news." );
return false;
}
-
+
return members.contains( principalDn.toNormName() );
}
-
+
/**
* Gets the set of groups a user is a member of. The groups are returned
@@ -487,21 +490,24 @@
*/
public Set<LdapDN> getGroups( String member ) throws NamingException
{
- LdapDN normMember;
-
+ LdapDN normMember;
+
try
{
- normMember = parseNormalized( member );
+ normMember = parseNormalized( member );
}
catch ( NamingException e )
{
- LOG.warn( "Malformed member DN. Could not find groups for member '{}' in GroupCache. Returning empty set for groups!", member, e );
+ LOG
+ .warn(
+ "Malformed member DN. Could not find groups for member '{}' in GroupCache. Returning empty set for groups!",
+ member, e );
return EMPTY_GROUPS;
}
Set<LdapDN> memberGroups = null;
- for ( String group:groups.keySet() )
+ for ( String group : groups.keySet() )
{
Set<String> members = groups.get( group );
@@ -537,15 +543,15 @@
if ( members != null )
{
groups.put( newName.getNormName(), members );
-
+
if ( IS_DEBUG )
{
LOG.debug( "group cache contents after renaming '{}' :\n{}", oldName.getUpName(), groups );
}
-
+
return true;
}
-
+
return false;
}
}
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java Wed Apr 30 17:06:41 2008
@@ -19,6 +19,7 @@
*/
package org.apache.directory.server.core.authz;
+
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.entry.ServerAttribute;
import org.apache.directory.server.core.entry.ServerEntry;
@@ -36,6 +37,7 @@
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
import org.apache.directory.shared.ldap.filter.EqualityNode;
import org.apache.directory.shared.ldap.filter.ExprNode;
@@ -74,22 +76,23 @@
private static final Logger LOG = LoggerFactory.getLogger( TupleCache.class );
/** a map of strings to ACITuple collections */
- private final Map<String,List<ACITuple>> tuples = new HashMap<String,List<ACITuple>>();
-
+ private final Map<String, List<ACITuple>> tuples = new HashMap<String, List<ACITuple>>();
+
/** a handle on the partition nexus */
private final PartitionNexus nexus;
-
+
/** a normalizing ACIItem parser */
private final ACIItemParser aciParser;
/** A starage for the PrescriptiveACI attributeType */
private AttributeType prescriptiveAciAT;
-
+
/**
* The OIDs normalizer map
*/
private Map<String, OidNormalizer> normalizerMap;
+
/**
* Creates a ACITuple cache.
*
@@ -98,7 +101,7 @@
*/
public TupleCache( DirectoryService directoryService ) throws NamingException
{
- normalizerMap = directoryService.getRegistries().getAttributeTypeRegistry().getNormalizerMapping();
+ normalizerMap = directoryService.getRegistries().getAttributeTypeRegistry().getNormalizerMapping();
this.nexus = directoryService.getPartitionNexus();
AttributeTypeRegistry attributeTypeRegistry = directoryService.getRegistries().getAttributeTypeRegistry();
OidRegistry oidRegistry = directoryService.getRegistries().getOidRegistry();
@@ -108,7 +111,7 @@
initialize( directoryService.getRegistries() );
}
-
+
private LdapDN parseNormalized( String name ) throws NamingException
{
LdapDN dn = new LdapDN( name );
@@ -123,36 +126,35 @@
// generate ACITuple Arrays for each subentry
// add that subentry to the hash
Iterator<String> suffixes = nexus.listSuffixes( null );
-
+
while ( suffixes.hasNext() )
{
String suffix = suffixes.next();
LdapDN baseDn = parseNormalized( suffix );
- ExprNode filter = new EqualityNode( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.ACCESS_CONTROL_SUBENTRY_OC );
+ ExprNode filter = new EqualityNode( SchemaConstants.OBJECT_CLASS_AT, new ClientStringValue(
+ SchemaConstants.ACCESS_CONTROL_SUBENTRY_OC ) );
SearchControls ctls = new SearchControls();
ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
- NamingEnumeration<ServerSearchResult> results = nexus.search(
- new SearchOperationContext( registries, baseDn,
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, ctls ) );
-
+ NamingEnumeration<ServerSearchResult> results = nexus.search( new SearchOperationContext( registries,
+ baseDn, AliasDerefMode.NEVER_DEREF_ALIASES, filter, ctls ) );
+
while ( results.hasMore() )
{
- ServerSearchResult result = results.next();
+ ServerSearchResult result = results.next();
LdapDN subentryDn = result.getDn().normalize( normalizerMap );
ServerEntry serverEntry = result.getServerEntry();
EntryAttribute aci = serverEntry.get( prescriptiveAciAT );
-
+
if ( aci == null )
{
- LOG.warn( "Found accessControlSubentry '" + subentryDn
- + "' without any " + SchemaConstants.PRESCRIPTIVE_ACI_AT );
+ LOG.warn( "Found accessControlSubentry '" + subentryDn + "' without any "
+ + SchemaConstants.PRESCRIPTIVE_ACI_AT );
continue;
}
subentryAdded( subentryDn, serverEntry );
}
-
+
results.close();
}
}
@@ -165,8 +167,8 @@
if ( aci == null )
{
- if ( entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ACCESS_CONTROL_SUBENTRY_OC ) ||
- entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ACCESS_CONTROL_SUBENTRY_OC_OID ) )
+ if ( entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ACCESS_CONTROL_SUBENTRY_OC )
+ || entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ACCESS_CONTROL_SUBENTRY_OC_OID ) )
{
// should not be necessary because of schema interceptor but schema checking
// can be turned off and in this case we must protect against being able to
@@ -178,7 +180,7 @@
return false;
}
}
-
+
return true;
}
@@ -187,17 +189,17 @@
{
// only do something if the entry contains prescriptiveACI
EntryAttribute aciAttr = entry.get( prescriptiveAciAT );
-
+
if ( !hasPrescriptiveACI( entry ) )
{
return;
}
List<ACITuple> entryTuples = new ArrayList<ACITuple>();
-
- for ( Value<?> value:aciAttr )
+
+ for ( Value<?> value : aciAttr )
{
- String aci = (String)value.get();
+ String aci = ( String ) value.get();
ACIItem item = null;
try
@@ -207,24 +209,24 @@
}
catch ( ParseException e )
{
- String msg = "ACIItem parser failure on \n'" + item + "'\ndue to syntax error. " +
- "Cannnot add ACITuples to TupleCache.\n" +
- "Check that the syntax of the ACI item is correct. \nUntil this error " +
- "is fixed your security settings will not be as expected.";
+ String msg = "ACIItem parser failure on \n'" + item + "'\ndue to syntax error. "
+ + "Cannnot add ACITuples to TupleCache.\n"
+ + "Check that the syntax of the ACI item is correct. \nUntil this error "
+ + "is fixed your security settings will not be as expected.";
LOG.error( msg, e );
-
+
// do not process this ACI Item because it will be null
// continue on to process the next ACI item in the entry
}
}
-
+
tuples.put( normName.toNormName(), entryTuples );
}
public void subentryDeleted( LdapDN normName, ServerEntry entry ) throws NamingException
{
- if ( !hasPrescriptiveACI(entry ) )
+ if ( !hasPrescriptiveACI( entry ) )
{
return;
}
@@ -242,7 +244,7 @@
for ( Modification mod : mods )
{
- if ( ((ServerAttribute)mod.getAttribute()).instanceOf( SchemaConstants.PRESCRIPTIVE_ACI_AT ) )
+ if ( ( ( ServerAttribute ) mod.getAttribute() ).instanceOf( SchemaConstants.PRESCRIPTIVE_ACI_AT ) )
{
subentryDeleted( normName, entry );
subentryAdded( normName, entry );
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java Wed Apr 30 17:06:41 2008
@@ -84,14 +84,14 @@
public class EventInterceptor extends BaseInterceptor
{
private static Logger log = LoggerFactory.getLogger( EventInterceptor.class );
-
+
private PartitionNexus nexus;
private Map<NamingListener, Object> sources = new HashMap<NamingListener, Object>();
private Evaluator evaluator;
private AttributeTypeRegistry attributeRegistry;
private NormalizingVisitor visitor;
-
+
public void init( DirectoryService directoryService ) throws NamingException
{
super.init( directoryService );
@@ -101,7 +101,7 @@
evaluator = new ExpressionEvaluator( oidRegistry, attributeRegistry );
nexus = directoryService.getPartitionNexus();
NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( attributeRegistry, oidRegistry );
- visitor = new NormalizingVisitor( ncn, directoryService.getRegistries().getOidRegistry() );
+ visitor = new NormalizingVisitor( ncn, directoryService.getRegistries() );
}
@@ -120,7 +120,7 @@
{
LdapDN normalizedBaseDn = new LdapDN( name );
normalizedBaseDn.normalize( attributeRegistry.getNormalizerMapping() );
-
+
// -------------------------------------------------------------------
// must normalize the filter here: need to handle special cases
// -------------------------------------------------------------------
@@ -128,7 +128,7 @@
if ( filter.isLeaf() )
{
LeafNode ln = ( LeafNode ) filter;
-
+
if ( !attributeRegistry.hasAttributeType( ln.getAttribute() ) )
{
StringBuffer buf = new StringBuffer();
@@ -143,32 +143,31 @@
filter.accept( visitor );
}
}
- else
+ else
{
filter.accept( visitor );
-
+
// Check that after pruning/normalization we have a valid branch node at the top
BranchNode child = ( BranchNode ) filter;
// If the remaining filter branch node has no children set filter to null
if ( child.getChildren().size() == 0 )
{
- log.warn( "Undefined branchnode filter without child nodes not evaluted at all. " +
- "Only using scope node." );
+ log.warn( "Undefined branchnode filter without child nodes not evaluted at all. "
+ + "Only using scope node." );
filter = null;
}
// Now for AND & OR nodes with a single child left replace them with their child
- if ( child.getChildren().size() == 1 && ! ( child instanceof NotNode ) )
+ if ( child.getChildren().size() == 1 && !( child instanceof NotNode ) )
{
filter = child.getFirstChild();
}
}
-
-
+
ScopeNode scope = new ScopeNode( AliasDerefMode.NEVER_DEREF_ALIASES, normalizedBaseDn.toNormName(),
searchControls.getSearchScope() );
-
+
if ( filter != null )
{
BranchNode and = new AndNode();
@@ -180,7 +179,7 @@
{
filter = scope;
}
-
+
EventSourceRecord rec = new EventSourceRecord( name, filter, ctx, searchControls, namingListener );
Object obj = sources.get( namingListener );
@@ -198,7 +197,7 @@
else if ( obj instanceof List )
{
//noinspection unchecked
- List<Object> list = (List<Object>) obj;
+ List<Object> list = ( List<Object> ) obj;
list.add( rec );
}
}
@@ -223,7 +222,7 @@
for ( int ii = 0; ii < list.size(); ii++ )
{
- EventSourceRecord rec = list.get( ii );
+ EventSourceRecord rec = list.get( ii );
if ( rec.getEventContext() == ctx )
{
list.remove( ii );
@@ -241,21 +240,21 @@
public void add( NextInterceptor next, AddOperationContext opContext ) throws NamingException
{
- next.add( opContext );
+ next.add( opContext );
//super.add( next, opContext );
-
- LdapDN name = opContext.getDn();
+
+ LdapDN name = opContext.getDn();
ServerEntry entry = opContext.getEntry();
-
+
Set<EventSourceRecord> selecting = getSelectingSources( name, entry );
-
+
if ( selecting.isEmpty() )
{
return;
}
Iterator<EventSourceRecord> list = selecting.iterator();
-
+
while ( list.hasNext() )
{
EventSourceRecord rec = list.next();
@@ -274,14 +273,14 @@
public void delete( NextInterceptor next, DeleteOperationContext opContext ) throws NamingException
{
- LdapDN name = opContext.getDn();
- ServerEntry entry = nexus.lookup( new LookupOperationContext( opContext.getRegistries(), name ) );
+ LdapDN name = opContext.getDn();
+ ServerEntry entry = nexus.lookup( new LookupOperationContext( opContext.getRegistries(), name ) );
next.delete( opContext );
//super.delete( next, opContext );
-
+
Set<EventSourceRecord> selecting = getSelectingSources( name, entry );
-
+
if ( selecting.isEmpty() )
{
return;
@@ -305,21 +304,22 @@
}
- private void notifyOnModify( Registries registries, LdapDN name, List<Modification> mods, ServerEntry oriEntry ) throws NamingException
+ private void notifyOnModify( Registries registries, LdapDN name, List<Modification> mods, ServerEntry oriEntry )
+ throws NamingException
{
ServerEntry entry = nexus.lookup( new LookupOperationContext( registries, name ) );
Set<EventSourceRecord> selecting = getSelectingSources( name, entry );
-
+
if ( selecting.isEmpty() )
{
return;
}
Iterator<EventSourceRecord> list = selecting.iterator();
-
+
while ( list.hasNext() )
{
- EventSourceRecord rec =list.next();
+ EventSourceRecord rec = list.next();
NamingListener listener = rec.getNamingListener();
if ( listener instanceof ObjectChangeListener )
@@ -338,8 +338,10 @@
{
Invocation invocation = InvocationStack.getInstance().peek();
PartitionNexusProxy proxy = invocation.getProxy();
- ServerEntry oriEntry = proxy.lookup( new LookupOperationContext( opContext.getRegistries(), opContext.getDn() ), PartitionNexusProxy.LOOKUP_BYPASS );
-
+ ServerEntry oriEntry = proxy.lookup(
+ new LookupOperationContext( opContext.getRegistries(), opContext.getDn() ),
+ PartitionNexusProxy.LOOKUP_BYPASS );
+
next.modify( opContext );
notifyOnModify( opContext.getRegistries(), opContext.getDn(), opContext.getModItems(), oriEntry );
@@ -350,14 +352,14 @@
{
ServerEntry entry = nexus.lookup( new LookupOperationContext( registries, newName ) );
Set<EventSourceRecord> selecting = getSelectingSources( oldName, entry );
-
+
if ( selecting.isEmpty() )
{
return;
}
Iterator<EventSourceRecord> list = selecting.iterator();
-
+
while ( list.hasNext() )
{
EventSourceRecord rec = list.next();
@@ -377,10 +379,10 @@
public void rename( NextInterceptor next, RenameOperationContext opContext ) throws NamingException
{
- next.rename( opContext );
+ next.rename( opContext );
//super.rename( next, opContext );
-
- LdapDN newName = ( LdapDN ) opContext.getDn().clone();
+
+ LdapDN newName = ( LdapDN ) opContext.getDn().clone();
newName.remove( newName.size() - 1 );
newName.add( opContext.getNewRdn() );
newName.normalize( attributeRegistry.getNormalizerMapping() );
@@ -388,10 +390,9 @@
}
- public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext )
- throws NamingException
+ public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext ) throws NamingException
{
- next.moveAndRename( opContext );
+ next.moveAndRename( opContext );
//super.moveAndRename( next, opContext );
LdapDN newName = ( LdapDN ) opContext.getParent().clone();
@@ -402,11 +403,11 @@
public void move( NextInterceptor next, MoveOperationContext opContext ) throws NamingException
{
- next.move( opContext );
+ next.move( opContext );
//super.move( next, opContext );
LdapDN oriChildName = opContext.getDn();
-
+
LdapDN newName = ( LdapDN ) opContext.getParent().clone();
newName.add( oriChildName.get( oriChildName.size() - 1 ) );
notifyOnNameChange( opContext.getRegistries(), oriChildName, newName );
@@ -422,15 +423,15 @@
Set<EventSourceRecord> selecting = new HashSet<EventSourceRecord>();
Iterator<Object> list = sources.values().iterator();
-
+
while ( list.hasNext() )
{
Object obj = list.next();
-
+
if ( obj instanceof EventSourceRecord )
{
EventSourceRecord rec = ( EventSourceRecord ) obj;
-
+
if ( evaluator.evaluate( rec.getFilter(), name.toNormName(), entry ) )
{
selecting.add( rec );
@@ -439,8 +440,8 @@
else if ( obj instanceof List )
{
List<EventSourceRecord> records = ( List<EventSourceRecord> ) obj;
-
- for ( EventSourceRecord rec:records )
+
+ for ( EventSourceRecord rec : records )
{
if ( evaluator.evaluate( rec.getFilter(), name.toNormName(), entry ) )
{
@@ -467,7 +468,7 @@
public EventSourceRecord( LdapDN base, ExprNode filter, EventContext context, SearchControls controls,
- NamingListener listener)
+ NamingListener listener )
{
this.filter = filter;
this.context = context;
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java Wed Apr 30 17:06:41 2008
@@ -68,7 +68,7 @@
private SubstringEvaluator substringEvaluator;
/** ScopeNode evaluator we depend on */
private ScopeEvaluator scopeEvaluator;
-
+
/** Constants used for comparisons */
private static final boolean COMPARE_GREATER = true;
private static final boolean COMPARE_LESSER = false;
@@ -113,32 +113,32 @@
if ( node instanceof PresenceNode )
{
- String attrId = ((PresenceNode)node).getAttribute();
+ String attrId = ( ( PresenceNode ) node ).getAttribute();
return evalPresence( attrId, entry );
}
else if ( ( node instanceof EqualityNode ) || ( node instanceof ApproximateNode ) )
{
- return evalEquality( ( EqualityNode ) node, entry );
+ return evalEquality( ( EqualityNode ) node, entry );
}
else if ( node instanceof GreaterEqNode )
{
- return evalGreaterOrLesser( ( GreaterEqNode ) node, entry, COMPARE_GREATER );
+ return evalGreaterOrLesser( ( GreaterEqNode ) node, entry, COMPARE_GREATER );
}
else if ( node instanceof LessEqNode )
{
- return evalGreaterOrLesser( ( LessEqNode ) node, entry, COMPARE_LESSER );
+ return evalGreaterOrLesser( ( LessEqNode ) node, entry, COMPARE_LESSER );
}
else if ( node instanceof SubstringNode )
{
- return substringEvaluator.evaluate( node, dn, entry );
+ return substringEvaluator.evaluate( node, dn, entry );
}
else if ( node instanceof ExtensibleNode )
{
- throw new NotImplementedException();
+ throw new NotImplementedException();
}
else
{
- throw new NamingException( "Unrecognized leaf node type: " + node );
+ throw new NamingException( "Unrecognized leaf node type: " + node );
}
}
@@ -154,7 +154,8 @@
* @return the ava evaluation on the perspective candidate
* @throws javax.naming.NamingException if there is a database access failure
*/
- private boolean evalGreaterOrLesser( SimpleNode node, ServerEntry entry, boolean isGreaterOrLesser ) throws NamingException
+ private boolean evalGreaterOrLesser( SimpleNode node, ServerEntry entry, boolean isGreaterOrLesser )
+ throws NamingException
{
String attrId = node.getAttribute();
@@ -182,7 +183,7 @@
*/
if ( isGreaterOrLesser == COMPARE_GREATER )
{
- for ( Value<?> value:attr )
+ for ( Value<?> value : attr )
{
Object normValue = normalizer.normalize( value );
@@ -195,7 +196,7 @@
}
else
{
- for ( Value<?> value:attr )
+ for ( Value<?> value : attr )
{
Object normValue = normalizer.normalize( value );
@@ -255,42 +256,33 @@
}
// check if AVA value exists in attribute
- if ( node.getValue() instanceof String )
- {
- if ( attr.contains( (String)node.getValue() ) )
- {
- return true;
- }
- }
- else if ( attr.contains( (byte[])node.getValue() ) )
+ if ( attr.contains( node.getValue() ) )
{
return true;
}
// get the normalized AVA filter value
- Object filterValue = normalizer.normalize( node.getValue() );
+ Object filterValue = normalizer.normalize( node.getValue().get() );
// check if the normalized value is present
- if ( filterValue instanceof String)
+ if ( filterValue instanceof String )
{
- if ( attr.contains( (String)filterValue ) )
+ if ( attr.contains( ( String ) filterValue ) )
{
return true;
}
}
- else if ( attr.contains( (byte[])filterValue ) )
+ else if ( attr.contains( ( byte[] ) filterValue ) )
{
return true;
}
-
-
/*
* We need to now iterate through all values because we could not get
* a lookup to work. For each value we normalize and use the comparator
* to determine if a match exists.
*/
- for( Value<?> value:attr )
+ for ( Value<?> value : attr )
{
Object normValue = normalizer.normalize( value.get() );
@@ -351,15 +343,15 @@
case ( EQUALITY_MATCH ):
mrule = type.getEquality();
break;
-
+
case ( SUBSTRING_MATCH ):
mrule = type.getSubstr();
break;
-
+
case ( ORDERING_MATCH ):
mrule = type.getOrdering();
break;
-
+
default:
throw new NamingException( "Unknown match type: " + matchType );
}
Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java?rev=652410&r1=652409&r2=652410&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java Wed Apr 30 17:06:41 2008
@@ -24,6 +24,7 @@
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.shared.ldap.name.LdapDN;
+
/**
* A Add context used for Interceptors. It contains all the informations
* needed for the add operation, and used by all the interceptors
@@ -35,14 +36,14 @@
{
/** The added entry */
private ServerEntry entry;
-
+
/**
* Creates a new instance of AddOperationContext.
*/
public AddOperationContext( Registries registries )
{
- super( registries );
+ super( registries );
}
@@ -58,9 +59,9 @@
/**
* Creates a new instance of ModifyOperationContext.
*/
- public AddOperationContext( Registries registries, LdapDN dn, ServerEntry entry )
+ public AddOperationContext( Registries registries, ServerEntry entry )
{
- super( registries, dn );
+ super( registries, entry.getDn() );
this.entry = entry;
}
@@ -72,7 +73,7 @@
*/
public AddOperationContext( Registries registries, boolean collateralOperation )
{
- super( registries, collateralOperation );
+ super( registries, collateralOperation );
}
@@ -97,34 +98,35 @@
*/
public AddOperationContext( Registries registries, LdapDN dn, ServerEntry entry, boolean collateralOperation )
{
- super( registries, dn, collateralOperation );
+ super( registries, dn, collateralOperation );
this.entry = entry;
}
/**
- * @return The added attributes
- */
- public ServerEntry getEntry()
- {
- return entry;
- }
-
- /**
- * Set the added attributes
- * @param entry The added attributes
- */
- public void setEntry( ServerEntry entry )
- {
- this.entry = entry;
- }
+ * @return The added attributes
+ */
+ public ServerEntry getEntry()
+ {
+ return entry;
+ }
- /**
+
+ /**
+ * Set the added attributes
+ * @param entry The added attributes
+ */
+ public void setEntry( ServerEntry entry )
+ {
+ this.entry = entry;
+ }
+
+
+ /**
* @see Object#toString()
*/
public String toString()
{
- return "AddContext for DN '" + getDn().getUpName() + "'" +
- ", added entry: " + entry;
+ return "AddContext for DN '" + getDn().getUpName() + "'" + ", added entry: " + entry;
}
}