Re: [Apache DS] creating a domain partition.

2012-12-12 Thread Emmanuel Lécharny
Le 12/12/12 10:45 PM, Jonathan Russell a écrit :
> I'm using an embedded Apache DS 1.5

> (so I have no server.xml, as far as 
> I'm aware), and I'm trying to programmatically add a domain to my root 
> partition. I've seen the instructions here:
> http://directory.apache.org/apacheds/1.5/144-adding-your-own-partition-resp-suffix.html
>
> They have an end result that I'm looking for "dc=example, dc=com", but 
> they don't explain how that's created.
>
> I see the instructions for adding a partition: 
>
> JdbmPartition sevenseasPartition = new JdbmPartition();
> sevenseasPartition.setId("sevenseas");
> sevenseasPartition.setSuffix("o=sevenseas");
> sevenseasPartition.setCacheSize(1000);
> sevenseasPartition.init(directoryService);
>
> // Create some indices (optional)
> Set> indexedAttrs = new HashSet ServerEntry>>();
> indexedAttrs.add( new JdbmIndex("objectClass"));
> indexedAttrs.add( new JdbmIndex("o"));
> sevenseasPartition.setIndexedAttributes( indexedAttrs );
>
> //Add partition to the directory service
> directoryService.addPartition(sevenseasPartition);
>
> // start the directory service
> directoryService.startup();
>
> // create the context entry
> ServerEntry entry = new DefaultServerEntry( 
> directoryService.getRegistries(), new LdapDN( "o=sevenseas") );
> entry.put( "objectClass",  "top", "organization" );
> entry.put("o","sevenseas");
>
> // add the context entry
> AddContextPartitionOperationContext adOpContext = new 
> AddContextPartitionOperationContext( directoryService.getAdminSession(), 
> sevenseasPartition );
> adOpContext.add( entry, null );
> directoryService.getPartitionNexus().addContextPartition( adOpContext );

So far so good.


>
> However, simply changing "o" to "dc" doesn't create a domain of 
> "sevenseas" as I expected. If I run this code:
>JdbmPartition sevenseasPartition = new JdbmPartition ();
> sevenseasPartition.setId ("sevenseas");
> sevenseasPartition.setSuffix ("dc=sevenseas");
> sevenseasPartition.setCacheSize (1000);
> sevenseasPartition.init (service);
>
> // Create some indices (optional)
> Set> indexedAttrs = new HashSet ServerEntry>> ();
> indexedAttrs.add (new JdbmIndex (
> "objectClass"));
> indexedAttrs.add (new JdbmIndex ("dc"));
> sevenseasPartition.setIndexedAttributes (indexedAttrs);
>
> //Add partition to the directory service
> service.addPartition (sevenseasPartition);
>
> // start the directory service
> service.startup ();
>
> // create the context entry
> ServerEntry entry = new DefaultServerEntry (service
> .getRegistries () , new LdapDN ("dc=sevenseas"));
> entry.put ("objectClass", "top", "organization");
> entry.put ("dc", "sevenseas");
> // add the context entry
> /*
>  * AddContextPartitionOperationContext adOpContext = new
>  * AddContextPartitionOperationContext 
> (service.getAdminSession () ,
>  * sevenseasPartition); adOpContext.add (entry, null);
>  * service.getPartitionNexus ().addContextPartition 
> (adOpContext);
>  */
>
> than I get a naming context created in my root, as I expect. But when I 
> uncomment out the bottom part (thus adding the context entry), I get an 
> exception:


Plain normal. You can't add the 'dc' Attribute if the ObjectClass does
not allow that. So far, you have declared 'top' and 'oganization' as
ObjectClasses for teh added entry, you then can't inject a 'dc'
attribute. You must add the 'dcObject' if you want to be able to add the
'dc' Attribute. Or you can also use 'domain' instead of 'organization'
> Seeing that 2.5.4.10 is the "o" that was used in the example, I added it 
> back in: 
> ServerEntry entry = new DefaultServerEntry (service
> .getRegistries () , new LdapDN ("dc=sevenseas"));
> entry.put ("objectClass", "top", "organization");
> entry.put ("dc", "sevenseas");
> entry.put ("o", "something");

See above.
>


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 



[Apache DS] creating a domain partition.

2012-12-12 Thread Jonathan Russell
I'm using an embedded Apache DS 1.5 (so I have no server.xml, as far as 
I'm aware), and I'm trying to programmatically add a domain to my root 
partition. I've seen the instructions here:
http://directory.apache.org/apacheds/1.5/144-adding-your-own-partition-resp-suffix.html

They have an end result that I'm looking for "dc=example, dc=com", but 
they don't explain how that's created.

I see the instructions for adding a partition: 

JdbmPartition sevenseasPartition = new JdbmPartition();
sevenseasPartition.setId("sevenseas");
sevenseasPartition.setSuffix("o=sevenseas");
sevenseasPartition.setCacheSize(1000);
sevenseasPartition.init(directoryService);

// Create some indices (optional)
Set> indexedAttrs = new HashSet>();
indexedAttrs.add( new JdbmIndex("objectClass"));
indexedAttrs.add( new JdbmIndex("o"));
sevenseasPartition.setIndexedAttributes( indexedAttrs );

//Add partition to the directory service
directoryService.addPartition(sevenseasPartition);

// start the directory service
directoryService.startup();

// create the context entry
ServerEntry entry = new DefaultServerEntry( 
directoryService.getRegistries(), new LdapDN( "o=sevenseas") );
entry.put( "objectClass",  "top", "organization" );
entry.put("o","sevenseas");

// add the context entry
AddContextPartitionOperationContext adOpContext = new 
AddContextPartitionOperationContext( directoryService.getAdminSession(), 
sevenseasPartition );
adOpContext.add( entry, null );
directoryService.getPartitionNexus().addContextPartition( adOpContext );

However, simply changing "o" to "dc" doesn't create a domain of 
"sevenseas" as I expected. If I run this code:
   JdbmPartition sevenseasPartition = new JdbmPartition ();
sevenseasPartition.setId ("sevenseas");
sevenseasPartition.setSuffix ("dc=sevenseas");
sevenseasPartition.setCacheSize (1000);
sevenseasPartition.init (service);

// Create some indices (optional)
Set> indexedAttrs = new HashSet> ();
indexedAttrs.add (new JdbmIndex (
"objectClass"));
indexedAttrs.add (new JdbmIndex ("dc"));
sevenseasPartition.setIndexedAttributes (indexedAttrs);

//Add partition to the directory service
service.addPartition (sevenseasPartition);

// start the directory service
service.startup ();

// create the context entry
ServerEntry entry = new DefaultServerEntry (service
.getRegistries () , new LdapDN ("dc=sevenseas"));
entry.put ("objectClass", "top", "organization");
entry.put ("dc", "sevenseas");
// add the context entry
/*
 * AddContextPartitionOperationContext adOpContext = new
 * AddContextPartitionOperationContext 
(service.getAdminSession () ,
 * sevenseasPartition); adOpContext.add (entry, null);
 * service.getPartitionNexus ().addContextPartition 
(adOpContext);
 */

than I get a naming context created in my root, as I expect. But when I 
uncomment out the bottom part (thus adding the context entry), I get an 
exception:
org.apache.directory.shared.ldap.exception.LdapSchemaViolationException: 
Required attributes [2.5.4.10] not found within entry dc=sevenseas
at 
org.apache.directory.server.core.schema.SchemaInterceptor.assertRequiredAttributesPresent(SchemaInterceptor.java:2199)
at 
org.apache.directory.server.core.schema.SchemaInterceptor.check(SchemaInterceptor.java:1965)
at 
org.apache.directory.server.core.schema.SchemaInterceptor.add(SchemaInterceptor.java:2054)
at 
org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1196)
at 
org.apache.directory.server.core.operational.OperationalAttributeInterceptor.add(OperationalAttributeInterceptor.java:202)
at 
org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1196)
at 
org.apache.directory.server.core.changelog.ChangeLogInterceptor.add(ChangeLogInterceptor.java:109)
at 
org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1196)
at 
org.apache.directory.server.core.exception.ExceptionInterceptor.add(ExceptionInterceptor.java:167)
at 
org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1196)
at 
org.apache.directory.server.core.interceptor.BaseInterceptor.add(BaseInterceptor.java:129)
at 
org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1196)
at 
org.apache.directory.server.core.authz.AciAuthorizationInterceptor.add(AciAuthorizationInterceptor.java:455)
at 
org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1196)
at 
org.apache.directory.server.core.referral.ReferralInterceptor.add(Referr