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/02/28 16:10:47 UTC
svn commit: r631992 - in /directory/apacheds/branches/bigbang:
core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java
Author: elecharny
Date: Thu Feb 28 07:10:44 2008
New Revision: 631992
URL: http://svn.apache.org/viewvc?rev=631992&view=rev
Log:
Handling ;binary and any kind of options for AttributeTypes. The options are just dropped, so that the attribute can be handled correctly inside the server.
This is a quick workaround to allow requests such AddRequest or SearchRequest with attributes like userCertificate;binary to be accepted.
Added a test to check that the server is accepting such requests
Modified:
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java?rev=631992&r1=631991&r2=631992&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java Thu Feb 28 07:10:44 2008
@@ -19,9 +19,12 @@
package org.apache.directory.server.core.entry;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
+import java.util.Set;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -44,6 +47,7 @@
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.util.EmptyEnumeration;
+import org.apache.directory.shared.ldap.util.StringTools;
/**
* A helper class used to manipulate Entries, Attributes and Values.
@@ -170,7 +174,11 @@
{
Attribute attr = attrs.nextElement();
- AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( attr.getID() );
+ String attributeId = attr.getID();
+ String id = stripOptions( attributeId );
+ Set<String> options = getOptions( attributeId );
+ // TODO : handle options.
+ AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( id );
ServerAttribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType );
if ( serverAttribute != null )
@@ -450,7 +458,11 @@
for ( ModificationItem modification: modifications )
{
- AttributeType attributeType = atRegistry.lookup( modification.getAttribute().getID() );
+ String attributeId = modification.getAttribute().getID();
+ String id = stripOptions( attributeId );
+ Set<String> options = getOptions( attributeId );
+ // TODO : handle options
+ AttributeType attributeType = atRegistry.lookup( id );
modificationsList.add( toModification( (ModificationItemImpl)modification, attributeType ) );
}
@@ -587,5 +599,63 @@
}
}
};
+ }
+
+
+ /**
+ * Remove the options from the attributeType, and returns the ID.
+ *
+ * RFC 4512 :
+ * attributedescription = attributetype options
+ * attributetype = oid
+ * options = *( SEMI option )
+ * option = 1*keychar
+ */
+ private static String stripOptions( String attributeId )
+ {
+ int optionsPos = attributeId.indexOf( ";" );
+
+ if ( optionsPos != -1 )
+ {
+ return attributeId.substring( 0, optionsPos );
+ }
+ else
+ {
+ return attributeId;
+ }
+ }
+
+ /**
+ * Get the options from the attributeType.
+ *
+ * For instance, given :
+ * jpegphoto;binary;lang=jp
+ *
+ * your get back a set containing { "binary", "lang=jp" }
+ */
+ private static Set<String> getOptions( String attributeId )
+ {
+ int optionsPos = attributeId.indexOf( ";" );
+
+ if ( optionsPos != -1 )
+ {
+ Set<String> options = new HashSet<String>();
+
+ String[] res = attributeId.substring( optionsPos + 1 ).split( ";" );
+
+ for ( String option:res )
+ {
+ if ( !StringTools.isEmpty( option ) )
+ {
+ options.add( option );
+ }
+ }
+
+ return options;
+ }
+ else
+ {
+ return null;
+ }
}
}
Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java?rev=631992&r1=631991&r2=631992&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java (original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java Thu Feb 28 07:10:44 2008
@@ -71,6 +71,8 @@
Attribute attribute = new AttributeImpl( "objectClass" );
attribute.add( "top" );
attribute.add( "person" );
+ attribute.add( "organizationalperson" );
+ attribute.add( "inetorgperson" );
attributes.put( attribute );
attributes.put( "cn", cn );
attributes.put( "sn", sn );
@@ -331,7 +333,7 @@
// Check, whether attribute objectClass is unchanged
Attributes attrs = ctx.getAttributes( RDN_TORI_AMOS );
ocls = attrs.get( "objectClass" );
- assertEquals( ocls.size(), 2 );
+ assertEquals( ocls.size(), 4 );
assertTrue( ocls.contains( "top" ) );
assertTrue( ocls.contains( "person" ) );
}
@@ -582,5 +584,26 @@
{
}
+ }
+
+
+ /**
+ * Add a new attribute to a person entry.
+ *
+ * @throws NamingException
+ */
+ public void testAddNewBinaryAttributeValue() throws NamingException
+ {
+ // Add a binary attribute
+ byte[] newValue = new byte[]{0x00, 0x01, 0x02, 0x03};
+ Attributes attrs = new AttributesImpl( "userCertificate;binary", newValue );
+ ctx.modifyAttributes( RDN_TORI_AMOS, DirContext.ADD_ATTRIBUTE, attrs );
+
+ // Verify, that attribute value is added
+ attrs = ctx.getAttributes( RDN_TORI_AMOS );
+ Attribute attr = attrs.get( "userCertificate" );
+ assertNotNull( attr );
+ assertTrue( attr.contains( newValue ) );
+ assertEquals( 1, attr.size() );
}
}