directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kiran Ayyagari <kayyag...@apache.org>
Subject Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
Date Tue, 03 Aug 2010 19:11:19 GMT
hmmm,

   are you setting the property 'schema.resource.location' with -D flag
   it should be something like

  set JAVA_OPTS="-Dschema.resource.location=c:\\path\\to\apachds-<version>-all.jar"

  am suspecting that this property was not set correctly before.

  P.S:- if you can, then hang onto  #apache-directory , I will be
available for some 30 more
           minutes. Use a web based IRC client to bypass the corporate
proxy hell.

Kiran Ayyagari


On Wed, Aug 4, 2010 at 12:28 AM, Benjamin, Roy <rbenjamin@ebay.com> wrote:
> Thanks Kiran,
>
> The only difference is I'm using Tomcat 5.5.29.
>
> Even if I hard code the ads-data-dir property no schema files are created.
>
> for example:
> <snip>
> String workDirPath = System.getProperty( "ads-data-dir" );
> workDirPath = "C:\\tmp\\ds";
> <snip>
>
> If ds doesn't exist, it and schema are created, but the schema folder is always empty.
>
> Thanks!!
>
> Roy
>
>
>
>
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 9:36 AM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> ahh, forgot to mention the versions,
>
> ApacheDS - 1.5.8-SNAPSHOT
> Tomcat - 6.0.26
>
> note that if you are using the updated maven archetype then it
> automatically generates the webapp with ApacheDS version
> 1.5.8-SNAPSHOT
>
> Kiran Ayyagari
>
>
>
> On Tue, Aug 3, 2010 at 9:59 PM, Benjamin, Roy <rbenjamin@ebay.com> wrote:
>> Hi Kiran,
>>
>> Can you tell me which version of ApacheDS you are using?  The one I'm
>> on doesn't think there is a ctor on AbstractAuthenticator that takes an
>> AuthenticationLevel.
>>
>> Thanks!
>>
>> Roy
>>
>> -----Original Message-----
>> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran
Ayyagari
>> Sent: Tuesday, August 03, 2010 1:03 AM
>> To: Apache Directory Developers List
>> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>>
>> hi Roy,
>>
>>    more inline
>>
>> On Tue, Aug 3, 2010 at 6:28 AM, Benjamin, Roy <rbenjamin@ebay.com> wrote:
>>> I get an error, don't understand why this doesn't work.
>>>
>>>
>>>
>>> in stdout log:
>>>
>>> [17:40:29] ERROR
>>> [org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader]
>>> -
>>> ERR_10004 Expecting to find a schema.ldif file in provided
>>> baseDirectory path
>>> 'C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema\ou=schema.ldif'
>>> but no such file found.
>>>
>>>
>>>
>>> Question:
>>>
>>> 1) Is there really supposed to be a file named: 'ou=schema.ldif' ?
>>>
>>> 2) The path
>>> C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema is
>>> valid,
>>>
>>>    so why can't the default schema be generated successfully ?
>> yes, those LDIF files are required and also we generate the schema during startup
of ApacheDS but it is unable to generate it, cause you are embedding the server in a container
and containers have a different classloading mechanism which prevents generating the schema
files.
>> However if you followed my earlier mails it can be easily circumvented by setting
the  property -Dschema.resource.location
>>
>> <snip/>
>>> My use case will require a custom Authenticator class, but if I try to
>>> add an Authenticator
>>>
>>> even at various places in the code I get an exception.  I've tried
>>> every place, early in the
>>>
>>> code, late in the code, before startup(), pretty much in each place I
>>> could add it.  For each I
>>>
>>> re-check server startup.  Everything is OK, except that I always get
>>> the following exception:
>>>
>>>
>>>
>>> javax.servlet.ServletException: Bind requests only tunnel down into
>>> partitions if there are no authenticators to handle the mechanism.
>>>
>>> Check to see if you have correctly configured authenticators for the server.
>>>
>>> ...
>>>
>>> root cause
>>>
>>> ...
>>>
>>> org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupportedException:
>>> Bind requests only tunnel down into partitions if there are no
>>> authenticators to handle the mechanism.
>>>
>>> Check to see if you have correctly configured authenticators for the server.
>>>
>>>
>>>
>>> I get the exception no matter where I try and add the Authenticator,
>>> or what Authenticator I try to add.
>>>
>>
>> you need to add the authenticator before startup, which I see that you are doing
it (shown in the other mail), but I suspect that you are not initializing that custom authenticator
properly hence the issue, here I am attaching a modified StartStopListener code.
>>
>> note that it also supports an additional property 'ads-data-dir' to specify the working
directory
>>
>> HTH
>>
>> P.S:- appreciate your patience, and sorry if it took long time to solve this. been
held up with other
>>         issues
>>
>> Kiran Ayyagari
>>
>> ============== pasting the code here (in case if attachment gets stripped ) ==============
>> /*
>>  *  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 org.example;
>>
>>
>> import java.io.File;
>> import java.util.HashSet;
>> import java.util.List;
>> import java.util.Set;
>>
>> import javax.servlet.ServletContext;
>> import javax.servlet.ServletContextEvent;
>> import javax.servlet.ServletContextListener;
>>
>> import org.apache.directory.server.constants.ServerDNConstants;
>> import org.apache.directory.server.core.DefaultDirectoryService;
>> import org.apache.directory.server.core.DirectoryService;
>> import org.apache.directory.server.core.LdapPrincipal;
>> import org.apache.directory.server.core.authn.AbstractAuthenticator;
>> import org.apache.directory.server.core.authn.AuthenticationInterceptor;
>> import org.apache.directory.server.core.authn.Authenticator;
>> import org.apache.directory.server.core.authn.SimpleAuthenticator;
>> import org.apache.directory.server.core.factory.JdbmPartitionFactory;
>> import org.apache.directory.server.core.interceptor.context.BindOperationContext;
>> import org.apache.directory.server.core.partition.Partition;
>> import org.apache.directory.server.core.partition.ldif.LdifPartition;
>> import org.apache.directory.server.core.schema.SchemaPartition;
>> import org.apache.directory.server.ldap.LdapServer;
>> import org.apache.directory.server.protocol.shared.transport.TcpTransport;
>> import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
>> import org.apache.directory.shared.ldap.constants.SchemaConstants;
>> import org.apache.directory.shared.ldap.schema.SchemaManager;
>> import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
>> import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
>> import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
>> import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
>> import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
>>
>>
>> /**
>>  * 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
>>        {
>>            ServletContext servletContext = evt.getServletContext();
>>
>>            directoryService = new DefaultDirectoryService();
>>            directoryService.setShutdownHookEnabled( true );
>>
>>            ldapServer = new LdapServer();
>>            ldapServer.setDirectoryService( directoryService );
>>            ldapServer.setAllowAnonymousAccess( true );
>>
>>            // Set LDAP port to 10389
>>            TcpTransport ldapTransport = new TcpTransport( 10389 );
>>            ldapServer.setTransports( ldapTransport );
>>
>>            directoryService.setWorkingDirectory( getWorkingDir( servletContext
) );
>>
>>            initSchema();
>>            initSystemPartition();
>>
>>            AuthenticationInterceptor authInterceptor = ( AuthenticationInterceptor
) directoryService
>>                .getInterceptor( AuthenticationInterceptor.class.getName()
);
>>            Set<Authenticator> authenticators = authInterceptor.getAuthenticators();
>>            if ( authenticators == null )
>>            {
>>                authenticators = new HashSet<Authenticator>();
>>            }
>>
>>            // add your authenticator
>>            authenticators.add( new MyAuthenticator() );
>>
>>            authInterceptor.setAuthenticators( authenticators );
>>
>>            directoryService.startup();
>>            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 );
>>        }
>>    }
>>
>>
>>    /**
>>     * Shutdown ApacheDS embedded.
>>     */
>>    public void contextDestroyed( ServletContextEvent evt )
>>    {
>>        try
>>        {
>>            ldapServer.stop();
>>            directoryService.shutdown();
>>        }
>>        catch ( Exception e )
>>        {
>>            throw new RuntimeException( e );
>>        }
>>    }
>>
>>
>>    /**
>>     * Inits the schema and schema partition.
>>     */
>>    private void initSchema() throws Exception
>>    {
>>        SchemaPartition schemaPartition = directoryService.getSchemaService().getSchemaPartition();
>>
>>        // Init the LdifPartition
>>        LdifPartition ldifPartition = new LdifPartition();
>>        String workingDirectory =
>> directoryService.getWorkingDirectory().getPath();
>>        ldifPartition.setWorkingDirectory( workingDirectory + "/schema" );
>>
>>        // Extract the schema on disk (a brand new one) and load the registries
>>        File serverWorkDirectory = new File( workingDirectory );
>>        File schemaRepository = new File( serverWorkDirectory, "schema" );
>>        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( serverWorkDirectory
);
>>        if ( !schemaRepository.exists() )
>>        {
>>            // extract only if the schema directory is not present
>>            extractor.extractOrCopy();
>>        }
>>        else
>>        {
>>            System.out.println( "schema partition directory exists, skipping
schema extraction" );
>>        }
>>
>>        schemaPartition.setWrappedPartition( ldifPartition );
>>
>>        SchemaLoader loader = new LdifSchemaLoader( schemaRepository );
>>        SchemaManager schemaManager = new DefaultSchemaManager( loader );
>>        directoryService.setSchemaManager( schemaManager );
>>
>>        // We have to load the schema now, otherwise we won't be able
>>        // to initialize the Partitions, as we won't be able to parse
>>        // and normalize their suffix DN
>>        schemaManager.loadAllEnabled();
>>
>>        schemaPartition.setSchemaManager( schemaManager );
>>
>>        List<Throwable> errors = schemaManager.getErrors();
>>
>>        if ( errors.size() != 0 )
>>        {
>>            System.out.println( errors );
>>            throw new RuntimeException( "there were errors while loading schema"
);
>>        }
>>    }
>>
>>
>>    /**
>>     * Inits the system partition.
>>     *
>>     * @throws Exception the exception
>>     */
>>    private void initSystemPartition() throws Exception
>>    {
>>        // change the working directory to something that is unique
>>        // on the system and somewhere either under target directory
>>        // or somewhere in a temp area of the machine.
>>        JdbmPartitionFactory partitionFactory = new JdbmPartitionFactory();
>>
>>        // Inject the System Partition
>>        Partition systemPartition = partitionFactory.createPartition( "system",
ServerDNConstants.SYSTEM_DN, 500,
>>            new File( directoryService.getWorkingDirectory(), "system" ) );
>>        systemPartition.setSchemaManager( directoryService.getSchemaManager()
);
>>
>>        partitionFactory.addIndex( systemPartition, SchemaConstants.OBJECT_CLASS_AT,
100 );
>>
>>        directoryService.setSystemPartition( systemPartition );
>>    }
>>
>>
>>    private File getWorkingDir( ServletContext servletContext )
>>    {
>>        File workingDir = null;
>>
>>        String workDirPath = System.getProperty( "ads-data-dir" );
>>
>>        if ( workDirPath == null )
>>        {
>>            // Determine an appropriate working directory
>>            workingDir = ( File ) servletContext.getAttribute( "javax.servlet.context.tempdir"
);
>>            workingDir = new File( workingDir, "server-work" );
>>            System.out.println( "ads-data-dir property is not set storing the
ldap data in temporary directory "
>>                + workingDir.getAbsolutePath() );
>>        }
>>        else
>>        {
>>            workingDir = new File( workDirPath );
>>            System.out.println( "storing the ldap data in the directory " +
workingDir.getAbsolutePath() );
>>        }
>>
>>        workingDir.mkdirs();
>>
>>        return workingDir;
>>    }
>> }
>>
>> class MyAuthenticator extends AbstractAuthenticator {
>>
>>    private SimpleAuthenticator wrappedAuth;
>>
>>
>>    public MyAuthenticator()
>>    {
>>        super( AuthenticationLevel.SIMPLE );
>>        wrappedAuth = new SimpleAuthenticator();
>>    }
>>
>>
>>    @Override
>>    protected void doInit()
>>    {
>>        try
>>        {
>>            wrappedAuth.init( getDirectoryService() );
>>        }
>>        catch ( Exception e )
>>        {
>>            throw new RuntimeException( e );
>>        }
>>    }
>>
>>
>>    public LdapPrincipal authenticate( BindOperationContext bindContext ) throws
Exception
>>    {
>>        System.out.println( "++++++++++ authenticating using a custome authenticator
'"
>>            + MyAuthenticator.class.getName() + "'" );
>>        return wrappedAuth.authenticate( bindContext );
>>    }
>>
>> }
>>

Mime
View raw message