You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Dan McLaughlin <da...@danshome.net> on 2010/03/17 01:30:23 UTC

Tomcat, ApacheDS & Spring

I followed the documentation to build and deploy ApacheDS as war.  I found
additional documentation on configuring a partition.  Now I see my
partition, but it's read only.

It would be nice if there were some documentation that walked you through
configuring the ApacheDS.war to use Spring to load the server.xml.  Has
anyone seen this done before?

--

Thanks,

Dan McLaughlin

NOTICE: This e-mail message and all attachments transmitted with it are for
the sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized review, use, disclosure or
distribution is strictly prohibited. The contents of this e-mail are
confidential and may be subject to work product privileges. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.

Need to schedule a meeting??? http://www.tungle.me/DanMcLaughlin

Re: Tomcat, ApacheDS & Spring

Posted by Dan McLaughlin <da...@danshome.net>.
I'll try that. Thanks!

This would be helpfull information to add to the documentation on how to
create an ApacheDS war, since the current example isn't very useful without
a partition to get you started.

--

Thanks,

Dan McLaughlin

NOTICE: This e-mail message and all attachments transmitted with it are for
the sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized review, use, disclosure or
distribution is strictly prohibited. The contents of this e-mail are
confidential and may be subject to work product privileges. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.

Need to schedule a meeting??? http://www.tungle.me/DanMcLaughlin


On Wed, Mar 17, 2010 at 9:46 AM, Pierre-Arnaud Marcelot <pa...@marcelot.net>wrote:

> Hi Dan,
>
> On 17 mars 2010, at 15:24, Dan McLaughlin wrote:
>
> > I can see ou=test, but it's read only. Looking at the code in the
> > documentation it's obvious why.
>
> Instead of writing your own custom partition, I think you probably just
> need to instantiate a JDBM partition.
>
> Partition myTestPartition = new JdbmPartition();
> myTestPartition.setId( "test" );
> myTestPartition.setSuffix( "dc=test,dc=com" );
> service.addPartition( myTestPartition );
>
> Hope this helps,
> Pierre-Arnaud

Re: Tomcat, ApacheDS & Spring

Posted by Pierre-Arnaud Marcelot <pa...@marcelot.net>.
Hi Dan,

On 17 mars 2010, at 15:24, Dan McLaughlin wrote:

> I can see ou=test, but it's read only. Looking at the code in the
> documentation it's obvious why.

Instead of writing your own custom partition, I think you probably just need to instantiate a JDBM partition.

Partition myTestPartition = new JdbmPartition();
myTestPartition.setId( "test" );
myTestPartition.setSuffix( "dc=test,dc=com" );
service.addPartition( myTestPartition );

Hope this helps,
Pierre-Arnaud

Re: Tomcat, ApacheDS & Spring

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 3/17/10 6:22 PM, Dan McLaughlin wrote:
> With the following code in the thread below, I get the ERROR "ttributeType
> w/ OID 2.5.4.16 not registered!" during startup...
>    
Don't be afraid. This is a 'normal' error (in fact, t has been removed 
from trunk).

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



Re: Tomcat, ApacheDS & Spring

Posted by Dan McLaughlin <da...@danshome.net>.
With the following code in the thread below, I get the ERROR "ttributeType
w/ OID 2.5.4.16 not registered!" during startup...
...
[11:53:22] INFO [org.apache.directory.server.core.DefaultDirectoryService] -
ApacheDS shutdown hook has been registered with the runtime.
*[11:53:24] ERROR
[org.apache.directory.server.schema.registries.DefaultAttributeTypeRegistry]
- attributeType w/ OID 2.5.4.16 not registered!*
[11:53:26] INFO [org.apache.directory.server.core.event.EventInterceptor] -
Initializing ...
[11:53:26] INFO [org.apache.directory.server.core.event.EventInterceptor] -
Initialization complete.
[11:53:26] INFO [org.apache.directory.server.ldap.LdapServer] - Successful
bind of an LDAP Service (10389) is completed.
[11:53:26] INFO [org.apache.directory.server.ldap.LdapServer] - Ldap service
started.
Mar 17, 2010 11:53:26 AM org.apache.coyote.http11.Http11Protocol start
...



--

Thanks,

Dan McLaughlin


NOTICE: This e-mail message and all attachments transmitted with it are for
the sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized review, use, disclosure or
distribution is strictly prohibited. The contents of this e-mail are
confidential and may be subject to work product privileges. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.

Need to schedule a meeting??? http://www.tungle.me/DanMcLaughlin


On Wed, Mar 17, 2010 at 11:56 AM, Dan McLaughlin <da...@danshome.net> wrote:

> Nice!  Now I have it working.   Code that finally worked below.  Any
> documentation with examples on setting up StartTLS/SSL and Replication?
>
> /*
>  *  Licensed to the Apache Software Foundation (ASF) under one
>  *  or more contributor license agreements.  See the NOTICE file
>  *  distributed with this work for additional information
>  *  regarding copyright ownership.  The ASF licenses this file
>  *  to you under the Apache License, Version 2.0 (the
>  *  "License"); you may not use this file except in compliance
>  *  with the License.  You may obtain a copy of the License at
>  *
>  *    http://www.apache.org/licenses/LICENSE-2.0
>  *
>  *  Unless required by applicable law or agreed to in writing,
>  *  software distributed under the License is distributed on an
>  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>  *  KIND, either express or implied.  See the License for the
>  *  specific language governing permissions and limitations
>  *  under the License.
>  *
>  */
> package com.txdot.cris.directory;
>
>
> import java.io.File;
> import java.util.HashSet;
>
> import javax.servlet.ServletContext;
> import javax.servlet.ServletContextEvent;
> import javax.servlet.ServletContextListener;
>
> import org.apache.directory.server.core.DefaultDirectoryService;
> import org.apache.directory.server.core.DirectoryService;
> import org.apache.directory.server.core.entry.ServerEntry;
> import org.apache.directory.server.core.partition.Partition;
> import
> org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
> import
> org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
> import org.apache.directory.server.ldap.LdapServer;
> import org.apache.directory.server.protocol.shared.transport.TcpTransport;
> import org.apache.directory.server.xdbm.Index;
> import
> org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
> import org.apache.directory.shared.ldap.name.LdapDN;
>
>
>
>
>
> /**
>  * A Servlet context listener to start and stop ApacheDS.
>  *
>  * @author <a href="mailto:dev@directory.apache.org">Apache Directory
>  *         Project</a>
>  */
> public class StartStopListener implements ServletContextListener
> {
>
>     private DirectoryService directoryService;
>
>     private LdapServer ldapServer;
>
>
>     /**
>      * Startup ApacheDS embedded.
>      */
>     public void contextInitialized( ServletContextEvent evt )
>     {
>
>         try
>         {
>             directoryService = new DefaultDirectoryService();
>             directoryService.setShutdownHookEnabled( true );
>
>          // Disable the ChangeLog system
>             directoryService.getChangeLog().setEnabled( false );
>             directoryService.setDenormalizeOpAttrsEnabled( true );
>
>             ldapServer = new LdapServer();
>             ldapServer.setDirectoryService( directoryService );
>             ldapServer.setAllowAnonymousAccess( true );
>
>              // Set LDAP port to 10389
>             TcpTransport ldapTransport = new TcpTransport( 10389 );
>             ldapServer.setTransports( ldapTransport );
>
>             // Determine an appropriate working directory
>             ServletContext servletContext = evt.getServletContext();
>             File workingDir = ( File ) servletContext.getAttribute(
> "javax.servlet.context.tempdir" );
>             directoryService.setWorkingDirectory( workingDir );
>
>             // Create some new partitions named 'foo', 'bar' and 'CRIS'.
>             // Partition fooPartition = addPartition( "foo",
> "dc=foo,dc=com" );
>             // Partition barPartition = addPartition( "bar",
> "dc=bar,dc=com" );
>             Partition crisPartition = addPartition( "CRIS", "ou=CRIS" );
>
>             // Index some attributes on the CRIS partition
>             addIndex( crisPartition, "objectClass", "ou", "uid" );
>
>             // And start the service
>             directoryService.startup();
>
>             // Inject the CRIS root entry
>             try
>             {
>              directoryService.getAdminSession().lookup(
> crisPartition.getSuffixDn() );
>             }
>             catch ( LdapNameNotFoundException lnnfe )
>             {
>                 LdapDN dnCRIS = new LdapDN( "ou=CRIS" );
>                 ServerEntry entryCRIS = directoryService.newEntry( dnCRIS
> );
>                 entryCRIS.add( "objectClass", "top", "organizationalUnit"
> );
>                 entryCRIS.add( "ou", "CRIS" );
>                 directoryService.getAdminSession().add( entryCRIS );
>             }
>
>             ldapServer.start();
>
>             // Store directoryService in context to provide it to servlets
> etc.
>             servletContext.setAttribute( DirectoryService.JNDI_KEY,
> directoryService );
>         }
>         catch ( Exception e )
>         {
>             throw new RuntimeException( e );
>         }
>     }
>
>     /**
>      * Add a new partition to the server
>      *
>      * @param partitionId The partition Id
>      * @param partitionDn The partition DN
>      * @return The newly added partition
>      * @throws Exception If the partition can't be added
>      */
>     private Partition addPartition( String partitionId, String partitionDn
> ) throws Exception
>     {
>         // Create a new partition named 'foo'.
>         Partition partition = new JdbmPartition();
>         partition.setId( partitionId );
>         partition.setSuffix( partitionDn );
>         directoryService.addPartition( partition );
>
>         return partition;
>     }
>
>
>     /**
>      * Add a new set of index on the given attributes
>      *
>      * @param partition The partition on which we want to add index
>      * @param attrs The list of attributes to index
>      */
>     private void addIndex( Partition partition, String... attrs )
>     {
>         // Index some attributes on the apache partition
>         HashSet<Index<?, ServerEntry>> indexedAttributes = new
> HashSet<Index<?, ServerEntry>>();
>
>         for ( String attribute:attrs )
>         {
>             indexedAttributes.add( new JdbmIndex<String,ServerEntry>(
> attribute ) );
>         }
>
>         ((JdbmPartition)partition).setIndexedAttributes( indexedAttributes
> );
>     }
>
>     /**
>      * Shutdown ApacheDS embedded.
>      */
>     public void contextDestroyed( ServletContextEvent evt )
>     {
>         try
>          {
>             ldapServer.stop();
>             directoryService.shutdown();
>         }
>         catch ( Exception e )
>         {
>             throw new RuntimeException( e );
>          }
>     }
> }
>
> --
>
> Thanks,
>
> Dan McLaughlin
>
>
> NOTICE: This e-mail message and all attachments transmitted with it are for
> the sole use of the intended recipient(s) and may contain confidential and
> privileged information. Any unauthorized review, use, disclosure or
> distribution is strictly prohibited. The contents of this e-mail are
> confidential and may be subject to work product privileges. If you are not
> the intended recipient, please contact the sender by reply e-mail and
> destroy all copies of the original message.
>
> Need to schedule a meeting??? http://www.tungle.me/DanMcLaughlin
>
>
> On Wed, Mar 17, 2010 at 9:55 AM, Stefan Zoerner <st...@labeo.de> wrote:
>
>> Dan McLaughlin wrote:
>>
>>> I followed this documentation to create the war
>>>
>>> http://cwiki.apache.org/DIRxSRVx11/43-embedding-apacheds-as-a-web-application.html
>>>
>>> Then I followed this documentation to create a partition ou=test
>>>
>>> http://cwiki.apache.org/DIRxSRVx11/61-how-to-write-a-simple-custom-partition-for-apacheds.html
>>>
>>> I can see ou=test, but it's read only. Looking at the code in the
>>> documentation it's obvious why.
>>>
>>
>> Ah, now I see. Yes it is obvious why, but it was not necessary to
>> implement a custom partition. Simply use the default implementation, which
>> is writable.
>>
>> A source code on how to accomplish this is here:
>>
>>
>> http://cwiki.apache.org/DIRxSRVx11/41-embedding-apacheds-into-an-application.html
>>
>> the method addPartition uses a JdbmPartition as implementation.
>>
>> hope this helps.
>>
>> For your question regarding reading the server.xml in order to setup the
>> server: I don't think there is a sample in the docs. But at least it is
>> possible to check the source code of the server itself to get inspired.
>>
>>
>> http://svn.apache.org/repos/asf/directory/installers/trunk/apacheds-noarch/src/main/java/org/apache/directory/server/Service.java
>>
>> Hope this helps as well.
>>
>> Greetings from Hamburg,
>>    StefanZ
>>
>>
>>
>

Re: Tomcat, ApacheDS & Spring

Posted by Dan McLaughlin <da...@danshome.net>.
Nice!  Now I have it working.   Code that finally worked below.  Any
documentation with examples on setting up StartTLS/SSL and Replication?

/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *
 */
package com.txdot.cris.directory;


import java.io.File;
import java.util.HashSet;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.partition.Partition;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
import
org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.server.protocol.shared.transport.TcpTransport;
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
import org.apache.directory.shared.ldap.name.LdapDN;





/**
 * A Servlet context listener to start and stop ApacheDS.
 *
 * @author <a href="mailto:dev@directory.apache.org">Apache Directory
 *         Project</a>
 */
public class StartStopListener implements ServletContextListener
{

    private DirectoryService directoryService;

    private LdapServer ldapServer;


    /**
     * Startup ApacheDS embedded.
     */
    public void contextInitialized( ServletContextEvent evt )
    {

        try
        {
            directoryService = new DefaultDirectoryService();
            directoryService.setShutdownHookEnabled( true );

         // Disable the ChangeLog system
            directoryService.getChangeLog().setEnabled( false );
            directoryService.setDenormalizeOpAttrsEnabled( true );

            ldapServer = new LdapServer();
            ldapServer.setDirectoryService( directoryService );
            ldapServer.setAllowAnonymousAccess( true );

            // Set LDAP port to 10389
            TcpTransport ldapTransport = new TcpTransport( 10389 );
            ldapServer.setTransports( ldapTransport );

            // Determine an appropriate working directory
            ServletContext servletContext = evt.getServletContext();
            File workingDir = ( File ) servletContext.getAttribute(
"javax.servlet.context.tempdir" );
            directoryService.setWorkingDirectory( workingDir );

            // Create some new partitions named 'foo', 'bar' and 'CRIS'.
            // Partition fooPartition = addPartition( "foo", "dc=foo,dc=com"
);
            // Partition barPartition = addPartition( "bar", "dc=bar,dc=com"
);
            Partition crisPartition = addPartition( "CRIS", "ou=CRIS" );

            // Index some attributes on the CRIS partition
            addIndex( crisPartition, "objectClass", "ou", "uid" );

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

            // Inject the CRIS root entry
            try
            {
             directoryService.getAdminSession().lookup(
crisPartition.getSuffixDn() );
            }
            catch ( LdapNameNotFoundException lnnfe )
            {
                LdapDN dnCRIS = new LdapDN( "ou=CRIS" );
                ServerEntry entryCRIS = directoryService.newEntry( dnCRIS );
                entryCRIS.add( "objectClass", "top", "organizationalUnit" );
                entryCRIS.add( "ou", "CRIS" );
                directoryService.getAdminSession().add( entryCRIS );
            }

            ldapServer.start();

            // Store directoryService in context to provide it to servlets
etc.
            servletContext.setAttribute( DirectoryService.JNDI_KEY,
directoryService );
        }
        catch ( Exception e )
        {
            throw new RuntimeException( e );
        }
    }

    /**
     * Add a new partition to the server
     *
     * @param partitionId The partition Id
     * @param partitionDn The partition DN
     * @return The newly added partition
     * @throws Exception If the partition can't be added
     */
    private Partition addPartition( String partitionId, String partitionDn )
throws Exception
    {
        // Create a new partition named 'foo'.
        Partition partition = new JdbmPartition();
        partition.setId( partitionId );
        partition.setSuffix( partitionDn );
        directoryService.addPartition( partition );

        return partition;
    }


    /**
     * Add a new set of index on the given attributes
     *
     * @param partition The partition on which we want to add index
     * @param attrs The list of attributes to index
     */
    private void addIndex( Partition partition, String... attrs )
    {
        // Index some attributes on the apache partition
        HashSet<Index<?, ServerEntry>> indexedAttributes = new
HashSet<Index<?, ServerEntry>>();

        for ( String attribute:attrs )
        {
            indexedAttributes.add( new JdbmIndex<String,ServerEntry>(
attribute ) );
        }

        ((JdbmPartition)partition).setIndexedAttributes( indexedAttributes
);
    }

    /**
     * Shutdown ApacheDS embedded.
     */
    public void contextDestroyed( ServletContextEvent evt )
    {
        try
        {
            ldapServer.stop();
            directoryService.shutdown();
        }
        catch ( Exception e )
        {
            throw new RuntimeException( e );
        }
    }
}

--

Thanks,

Dan McLaughlin


NOTICE: This e-mail message and all attachments transmitted with it are for
the sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized review, use, disclosure or
distribution is strictly prohibited. The contents of this e-mail are
confidential and may be subject to work product privileges. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.

Need to schedule a meeting??? http://www.tungle.me/DanMcLaughlin


On Wed, Mar 17, 2010 at 9:55 AM, Stefan Zoerner <st...@labeo.de> wrote:

> Dan McLaughlin wrote:
>
>> I followed this documentation to create the war
>>
>> http://cwiki.apache.org/DIRxSRVx11/43-embedding-apacheds-as-a-web-application.html
>>
>> Then I followed this documentation to create a partition ou=test
>>
>> http://cwiki.apache.org/DIRxSRVx11/61-how-to-write-a-simple-custom-partition-for-apacheds.html
>>
>> I can see ou=test, but it's read only. Looking at the code in the
>> documentation it's obvious why.
>>
>
> Ah, now I see. Yes it is obvious why, but it was not necessary to implement
> a custom partition. Simply use the default implementation, which is
> writable.
>
> A source code on how to accomplish this is here:
>
>
> http://cwiki.apache.org/DIRxSRVx11/41-embedding-apacheds-into-an-application.html
>
> the method addPartition uses a JdbmPartition as implementation.
>
> hope this helps.
>
> For your question regarding reading the server.xml in order to setup the
> server: I don't think there is a sample in the docs. But at least it is
> possible to check the source code of the server itself to get inspired.
>
>
> http://svn.apache.org/repos/asf/directory/installers/trunk/apacheds-noarch/src/main/java/org/apache/directory/server/Service.java
>
> Hope this helps as well.
>
> Greetings from Hamburg,
>    StefanZ
>
>
>

Re: Tomcat, ApacheDS & Spring

Posted by Stefan Zoerner <st...@labeo.de>.
Dan McLaughlin wrote:
> I followed this documentation to create the war
> http://cwiki.apache.org/DIRxSRVx11/43-embedding-apacheds-as-a-web-application.html
> 
> Then I followed this documentation to create a partition ou=test
> http://cwiki.apache.org/DIRxSRVx11/61-how-to-write-a-simple-custom-partition-for-apacheds.html
> 
> I can see ou=test, but it's read only. Looking at the code in the
> documentation it's obvious why.

Ah, now I see. Yes it is obvious why, but it was not necessary to 
implement a custom partition. Simply use the default implementation, 
which is writable.

A source code on how to accomplish this is here:

http://cwiki.apache.org/DIRxSRVx11/41-embedding-apacheds-into-an-application.html

the method addPartition uses a JdbmPartition as implementation.

hope this helps.

For your question regarding reading the server.xml in order to setup the 
server: I don't think there is a sample in the docs. But at least it is 
possible to check the source code of the server itself to get inspired.

http://svn.apache.org/repos/asf/directory/installers/trunk/apacheds-noarch/src/main/java/org/apache/directory/server/Service.java

Hope this helps as well.

Greetings from Hamburg,
     StefanZ



Re: Tomcat, ApacheDS & Spring

Posted by Dan McLaughlin <da...@danshome.net>.
I followed this documentation to create the war
http://cwiki.apache.org/DIRxSRVx11/43-embedding-apacheds-as-a-web-application.html

Then I followed this documentation to create a partition ou=test
http://cwiki.apache.org/DIRxSRVx11/61-how-to-write-a-simple-custom-partition-for-apacheds.html

I can see ou=test, but it's read only. Looking at the code in the
documentation it's obvious why.

It would be nice to just be able to load the ApacheDS server.xml using
Spring so you don't have to write custom code just to configure a partition,
replication, etc....

--

Thanks,

Dan McLaughlin

NOTICE: This e-mail message and all attachments transmitted with it are for
the sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized review, use, disclosure or
distribution is strictly prohibited. The contents of this e-mail are
confidential and may be subject to work product privileges. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.

Need to schedule a meeting??? http://www.tungle.me/DanMcLaughlin


On Wed, Mar 17, 2010 at 2:31 AM, Stefan Zoerner <st...@labeo.de> wrote:

> Hi Dan!
>
>
> Dan McLaughlin wrote:
>
>> I followed the documentation to build and deploy ApacheDS as war.  I found
>> additional documentation on configuring a partition.  Now I see my
>> partition, but it's read only.
>>
>
> How do you know it is read only? It should normally be possible to write
> entries to it ... Do you log on to the server with Studio? If yes, which
> user? Anonymous?
>
> Greetings from Hamburg,
>    StefanZ
>
>
>

Re: Tomcat, ApacheDS & Spring

Posted by Stefan Zoerner <st...@labeo.de>.
Hi Dan!

Dan McLaughlin wrote:
> I followed the documentation to build and deploy ApacheDS as war.  I found
> additional documentation on configuring a partition.  Now I see my
> partition, but it's read only.

How do you know it is read only? It should normally be possible to write 
entries to it ... Do you log on to the server with Studio? If yes, which 
user? Anonymous?

Greetings from Hamburg,
     StefanZ