You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Benjamin, Roy" <rb...@ebay.com> on 2010/07/31 03:17:53 UTC

How to add a custom Authenticator using API

Hi,

I'm starting from the example at: http://directory.apache.org/apacheds/1.5/43-embedding-apacheds-as-a-web-application.html

I want to run ApacheDS embedded in Tomcat, finally got that working with this example.

Now, I need to add a custom authenticator.

Being late on Friday I tried:


List<Interceptor> interceptors = directoryService.getInterceptors();
System.out.println(interceptors == null ? "Yikes!" : interceptors.size());
for (Interceptor interceptor:interceptors) {
	System.out.println(interceptor.getName());
	if (interceptor instanceof AuthenticationInterceptor) {
		Set<Authenticator> authenticators = ((AuthenticationInterceptor)interceptor).getAuthenticators();
		if (null == authenticators) {
			authenticators = new HashSet<Authenticator>(0);
			((AuthenticationInterceptor)interceptor).setAuthenticators(authenticators);
		} 
		authenticators.add(new MyAuthenticator("MyAuthenticator"));
		System.out.println("authenticators:" + authenticators);
	}
}

I'm sure this is wrong (see below).  Any help greatly appreciate das usual!

Roy

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.
	org.apache.directory.server.core.RootDseServlet.doGet(RootDseServlet.java:86)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	com.ebay.trading.salestax.vertex.VertexCalFilter.doFilter(VertexCalFilter.java:104)

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.
	org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition.bind(JdbmPartition.java:577)
	org.apache.directory.server.core.partition.DefaultPartitionNexus.bind(DefaultPartitionNexus.java:800)
	org.apache.directory.server.core.interceptor.InterceptorChain$1.bind(InterceptorChain.java:206)
      .....

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Perhaps...

But I've also had the same error when adding an ApacheDS native Authenticator
such as AnonymousAuthenticator...   I'll do more investigating.

Thanks
Roy

-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Tuesday, August 03, 2010 1:05 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

On Wed, Aug 4, 2010 at 1:27 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> You bet!
>
> :-)
>
> public class MembersAuthenticator extends AbstractAuthenticator {
>
>        protected MembersAuthenticator(String type) {
>            super(type);
ahhh, I see, this must be a old version of AbstractAuthenticator, the
new AbstractAuthenticator
(from the 1.5.8-SNAPSHOT) constructor takes a AuthenticationLevel

AbstractAuthenticator( AuthenticationLevel type ) so the above code should be

protected MembersAuthenticator(AuthenticationLevel type) {
            super(type);
....

this is the reason why your authenticator is not recognized. I guess
you must be developing and deploying with different versions.


>            System.out.println("\nMembersAuthenticator() " + type);
>    }
>
>        @Override
>        public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
>                System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
>
>                return null;
>        }
>
>        @Override
>    public String getAuthenticatorType() {
>                System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
>            return super.getAuthenticatorType();
>    }
>
>        @Override
>    public DirectoryService getDirectoryService() {
>                System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
>            return super.getDirectoryService();
>    }
>
> }
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 12:12 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> hi Roy,
>
> On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> Hi Kiran,
>>
>> I've been trying the example.
>>
>> I also thought it possible that the Authenticator I have could be the problem.
>> So I also ran the same example using other built in Authenticators.  Always the
>> same bind problem.
> is it possible to show us the code of your authenticator?
>
> Kiran Ayyagari
>

Kiran Ayyagari

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
You bet!
Thanks
Roy

-----Original Message-----
From: Emmanuel Lecharny [mailto:elecharny@gmail.com] 
Sent: Tuesday, August 03, 2010 4:43 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

  On 8/4/10 12:16 AM, Benjamin, Roy wrote:
> Thank you again Kiran,
>
> In the tortoise browser trunk-with-dependencies looks empty (almost).
> But I see now that it is a link.  It built fine once I had the right
> source tree.
>

yes, trunk-with-deps is the base for ADS? It contains many externals, 
pointing to apacheds, shared, etc.

Compiling apacheds alone will not work, as it will try to get shared 
from the maven repo, but an old version.

I'm not sure that trying to play with trunk is a good idea, as it's 
*very* likely to move a lot in the next few weeks...

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


Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Stefan Seelmann <se...@apache.org>.
> Compiling apacheds alone will not work, as it will try to get shared from
> the maven repo, but an old version.

FYI, I created a Jira about this [1] and Brett is working on it.

Kind Regards,
Stefan

[1] https://issues.apache.org/jira/browse/INFRA-2908

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Emmanuel Lecharny <el...@gmail.com>.
  On 8/4/10 12:16 AM, Benjamin, Roy wrote:
> Thank you again Kiran,
>
> In the tortoise browser trunk-with-dependencies looks empty (almost).
> But I see now that it is a link.  It built fine once I had the right
> source tree.
>

yes, trunk-with-deps is the base for ADS? It contains many externals, 
pointing to apacheds, shared, etc.

Compiling apacheds alone will not work, as it will try to get shared 
from the maven repo, but an old version.

I'm not sure that trying to play with trunk is a good idea, as it's 
*very* likely to move a lot in the next few weeks...

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


RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Thank you again Kiran,

In the tortoise browser trunk-with-dependencies looks empty (almost).
But I see now that it is a link.  It built fine once I had the right
source tree.  

Thanks!
Roy

-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Tuesday, August 03, 2010 1:45 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

On Wed, Aug 4, 2010 at 2:08 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi,
>
> Hmm I must be dense.  I've seen the trunk-with-dependencies directories but not
> understood what was kept there.
>
> I checked out trunk, but it didn't build.
strange, did you try to build whole trunk or just a single module?
anyways to get the trunk build succeed just run the below command from
the root of the project
(i.e the parent directory of the apacheds and shared directories )

mvn clean install -DskipTests

(this will avoid bringing latest snapshots from maven repo, they all
get generated locally)
>
> [INFO] ------------------------------------------------------------------------
> [INFO] Building ApacheDS Core API
> [INFO]    task-segment: [install]
> [INFO] ------------------------------------------------------------------------
> [INFO] [remote-resources:process {execution: default}]
> [INFO] snapshot org.apache.directory.shared:shared-ldap:0.9.20-SNAPSHOT: checking for updates from ibiblio.org
> [WARNING] repository metadata for: 'snapshot org.apache.directory.shared:shared-ldap:0.9.20-SNAPSHOT' could not be retrieved from repository: ibiblio.org due to an error: Unsupported Protocol: 'ibiblio Mirror of http': Cannot find wagon which supports the
>
> requested protocol: ibiblio Mirror of http
> [INFO] Repository 'ibiblio.org' will be blacklisted
> [INFO] [resources:resources]
> [INFO] Using 'UTF-8' encoding to copy filtered resources.
> [INFO] skip non existing resourceDirectory D:\DS\apacheds-10-trunks\trunck\core-api\src\main\resources
> [INFO] Copying 3 resources
> [INFO] [compiler:compile]
> [INFO] Compiling 101 source files to D:\DS\apacheds-10-trunks\trunck\core-api\target\classes
> [INFO] -------------------------------------------------------------
> [ERROR] COMPILATION ERROR :
> [INFO] -------------------------------------------------------------
> [ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AutonomousAdministrativePoint.java:[23,47] cannot find symbol
> symbol  : class AdministrativeRole
> location: package org.apache.directory.shared.ldap.subtree
>
> [ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AbstractAdministrativePoint.java:[26,47] cannot find symbol
> symbol  : class AdministrativeRole
> location: package org.apache.directory.shared.ldap.subtree
>
> [ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AutonomousAdministrativePoint.java:[55,11] cannot find symbol
> symbol  : class AdministrativeRole
> location: class org.apache.directory.server.core.administrative.AutonomousAdministrativePoint
>
> [ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AbstractAdministrativePoint.java:[41,14] cannot find symbol
> symbol  : class AdministrativeRole
> location: class org.apache.directory.server.core.administrative.AbstractAdministrativePoint
>
>
>
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 1:25 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> hi Roy,
>
> On Wed, Aug 4, 2010 at 1:44 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> Hi Kiran,
>>
>> I don't see 1.5.8 in svn.
> this is the version number of the latest trunk, not yet released, that
> is why am explicitly mentioning
> 1.5.8*-SNAPSHOT*
>
> here is the svn url
> http://svn.apache.org/repos/asf/directory/apacheds/trunk-with-dependencies
>
>>
>> I see apacheds-1.5.6, apacheds-1.5.7 under branches
>> and
>> 1.0.0 to 1.5.7 under tags..
>>
>> ?
>>
>> Thanks
>> Roy
>>
>> -----Original Message-----
>> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
>> Sent: Tuesday, August 03, 2010 1:05 PM
>> To: Apache Directory Developers List
>> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>>
>> On Wed, Aug 4, 2010 at 1:27 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>>> You bet!
>>>
>>> :-)
>>>
>>> public class MembersAuthenticator extends AbstractAuthenticator {
>>>
>>>        protected MembersAuthenticator(String type) {
>>>            super(type);
>> ahhh, I see, this must be a old version of AbstractAuthenticator, the
>> new AbstractAuthenticator
>> (from the 1.5.8-SNAPSHOT) constructor takes a AuthenticationLevel
>>
>> AbstractAuthenticator( AuthenticationLevel type ) so the above code should be
>>
>> protected MembersAuthenticator(AuthenticationLevel type) {
>>            super(type);
>> ....
>>
>> this is the reason why your authenticator is not recognized. I guess
>> you must be developing and deploying with different versions.
>>
>>
>>>            System.out.println("\nMembersAuthenticator() " + type);
>>>    }
>>>
>>>        @Override
>>>        public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
>>>                System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
>>>
>>>                return null;
>>>        }
>>>
>>>        @Override
>>>    public String getAuthenticatorType() {
>>>                System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
>>>            return super.getAuthenticatorType();
>>>    }
>>>
>>>        @Override
>>>    public DirectoryService getDirectoryService() {
>>>                System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
>>>            return super.getDirectoryService();
>>>    }
>>>
>>> }
>>>
>>> -----Original Message-----
>>> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
>>> Sent: Tuesday, August 03, 2010 12:12 PM
>>> To: Apache Directory Developers List
>>> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>>>
>>> hi Roy,
>>>
>>> On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>>>> Hi Kiran,
>>>>
>>>> I've been trying the example.
>>>>
>>>> I also thought it possible that the Authenticator I have could be the problem.
>>>> So I also ran the same example using other built in Authenticators.  Always the
>>>> same bind problem.
>>> is it possible to show us the code of your authenticator?
>>>
>>> Kiran Ayyagari
>>>
>>
>> Kiran Ayyagari
>>
>
>
>
> --
> Kiran Ayyagari
>



-- 
Kiran Ayyagari

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
On Wed, Aug 4, 2010 at 2:08 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi,
>
> Hmm I must be dense.  I've seen the trunk-with-dependencies directories but not
> understood what was kept there.
>
> I checked out trunk, but it didn't build.
strange, did you try to build whole trunk or just a single module?
anyways to get the trunk build succeed just run the below command from
the root of the project
(i.e the parent directory of the apacheds and shared directories )

mvn clean install -DskipTests

(this will avoid bringing latest snapshots from maven repo, they all
get generated locally)
>
> [INFO] ------------------------------------------------------------------------
> [INFO] Building ApacheDS Core API
> [INFO]    task-segment: [install]
> [INFO] ------------------------------------------------------------------------
> [INFO] [remote-resources:process {execution: default}]
> [INFO] snapshot org.apache.directory.shared:shared-ldap:0.9.20-SNAPSHOT: checking for updates from ibiblio.org
> [WARNING] repository metadata for: 'snapshot org.apache.directory.shared:shared-ldap:0.9.20-SNAPSHOT' could not be retrieved from repository: ibiblio.org due to an error: Unsupported Protocol: 'ibiblio Mirror of http': Cannot find wagon which supports the
>
> requested protocol: ibiblio Mirror of http
> [INFO] Repository 'ibiblio.org' will be blacklisted
> [INFO] [resources:resources]
> [INFO] Using 'UTF-8' encoding to copy filtered resources.
> [INFO] skip non existing resourceDirectory D:\DS\apacheds-10-trunks\trunck\core-api\src\main\resources
> [INFO] Copying 3 resources
> [INFO] [compiler:compile]
> [INFO] Compiling 101 source files to D:\DS\apacheds-10-trunks\trunck\core-api\target\classes
> [INFO] -------------------------------------------------------------
> [ERROR] COMPILATION ERROR :
> [INFO] -------------------------------------------------------------
> [ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AutonomousAdministrativePoint.java:[23,47] cannot find symbol
> symbol  : class AdministrativeRole
> location: package org.apache.directory.shared.ldap.subtree
>
> [ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AbstractAdministrativePoint.java:[26,47] cannot find symbol
> symbol  : class AdministrativeRole
> location: package org.apache.directory.shared.ldap.subtree
>
> [ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AutonomousAdministrativePoint.java:[55,11] cannot find symbol
> symbol  : class AdministrativeRole
> location: class org.apache.directory.server.core.administrative.AutonomousAdministrativePoint
>
> [ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AbstractAdministrativePoint.java:[41,14] cannot find symbol
> symbol  : class AdministrativeRole
> location: class org.apache.directory.server.core.administrative.AbstractAdministrativePoint
>
>
>
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 1:25 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> hi Roy,
>
> On Wed, Aug 4, 2010 at 1:44 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> Hi Kiran,
>>
>> I don't see 1.5.8 in svn.
> this is the version number of the latest trunk, not yet released, that
> is why am explicitly mentioning
> 1.5.8*-SNAPSHOT*
>
> here is the svn url
> http://svn.apache.org/repos/asf/directory/apacheds/trunk-with-dependencies
>
>>
>> I see apacheds-1.5.6, apacheds-1.5.7 under branches
>> and
>> 1.0.0 to 1.5.7 under tags..
>>
>> ?
>>
>> Thanks
>> Roy
>>
>> -----Original Message-----
>> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
>> Sent: Tuesday, August 03, 2010 1:05 PM
>> To: Apache Directory Developers List
>> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>>
>> On Wed, Aug 4, 2010 at 1:27 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>>> You bet!
>>>
>>> :-)
>>>
>>> public class MembersAuthenticator extends AbstractAuthenticator {
>>>
>>>        protected MembersAuthenticator(String type) {
>>>            super(type);
>> ahhh, I see, this must be a old version of AbstractAuthenticator, the
>> new AbstractAuthenticator
>> (from the 1.5.8-SNAPSHOT) constructor takes a AuthenticationLevel
>>
>> AbstractAuthenticator( AuthenticationLevel type ) so the above code should be
>>
>> protected MembersAuthenticator(AuthenticationLevel type) {
>>            super(type);
>> ....
>>
>> this is the reason why your authenticator is not recognized. I guess
>> you must be developing and deploying with different versions.
>>
>>
>>>            System.out.println("\nMembersAuthenticator() " + type);
>>>    }
>>>
>>>        @Override
>>>        public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
>>>                System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
>>>
>>>                return null;
>>>        }
>>>
>>>        @Override
>>>    public String getAuthenticatorType() {
>>>                System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
>>>            return super.getAuthenticatorType();
>>>    }
>>>
>>>        @Override
>>>    public DirectoryService getDirectoryService() {
>>>                System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
>>>            return super.getDirectoryService();
>>>    }
>>>
>>> }
>>>
>>> -----Original Message-----
>>> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
>>> Sent: Tuesday, August 03, 2010 12:12 PM
>>> To: Apache Directory Developers List
>>> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>>>
>>> hi Roy,
>>>
>>> On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>>>> Hi Kiran,
>>>>
>>>> I've been trying the example.
>>>>
>>>> I also thought it possible that the Authenticator I have could be the problem.
>>>> So I also ran the same example using other built in Authenticators.  Always the
>>>> same bind problem.
>>> is it possible to show us the code of your authenticator?
>>>
>>> Kiran Ayyagari
>>>
>>
>> Kiran Ayyagari
>>
>
>
>
> --
> Kiran Ayyagari
>



-- 
Kiran Ayyagari

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi,

Hmm I must be dense.  I've seen the trunk-with-dependencies directories but not
understood what was kept there.

I checked out trunk, but it didn't build.

[INFO] ------------------------------------------------------------------------
[INFO] Building ApacheDS Core API
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [remote-resources:process {execution: default}]
[INFO] snapshot org.apache.directory.shared:shared-ldap:0.9.20-SNAPSHOT: checking for updates from ibiblio.org
[WARNING] repository metadata for: 'snapshot org.apache.directory.shared:shared-ldap:0.9.20-SNAPSHOT' could not be retrieved from repository: ibiblio.org due to an error: Unsupported Protocol: 'ibiblio Mirror of http': Cannot find wagon which supports the

requested protocol: ibiblio Mirror of http
[INFO] Repository 'ibiblio.org' will be blacklisted
[INFO] [resources:resources]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\DS\apacheds-10-trunks\trunck\core-api\src\main\resources
[INFO] Copying 3 resources
[INFO] [compiler:compile]
[INFO] Compiling 101 source files to D:\DS\apacheds-10-trunks\trunck\core-api\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AutonomousAdministrativePoint.java:[23,47] cannot find symbol
symbol  : class AdministrativeRole
location: package org.apache.directory.shared.ldap.subtree

[ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AbstractAdministrativePoint.java:[26,47] cannot find symbol
symbol  : class AdministrativeRole
location: package org.apache.directory.shared.ldap.subtree

[ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AutonomousAdministrativePoint.java:[55,11] cannot find symbol
symbol  : class AdministrativeRole
location: class org.apache.directory.server.core.administrative.AutonomousAdministrativePoint

[ERROR] \DS\apacheds-10-trunks\trunck\core-api\src\main\java\org\apache\directory\server\core\administrative\AbstractAdministrativePoint.java:[41,14] cannot find symbol
symbol  : class AdministrativeRole
location: class org.apache.directory.server.core.administrative.AbstractAdministrativePoint




-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Tuesday, August 03, 2010 1:25 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

hi Roy,

On Wed, Aug 4, 2010 at 1:44 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi Kiran,
>
> I don't see 1.5.8 in svn.
this is the version number of the latest trunk, not yet released, that
is why am explicitly mentioning
1.5.8*-SNAPSHOT*

here is the svn url
http://svn.apache.org/repos/asf/directory/apacheds/trunk-with-dependencies

>
> I see apacheds-1.5.6, apacheds-1.5.7 under branches
> and
> 1.0.0 to 1.5.7 under tags..
>
> ?
>
> Thanks
> Roy
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 1:05 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> On Wed, Aug 4, 2010 at 1:27 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> You bet!
>>
>> :-)
>>
>> public class MembersAuthenticator extends AbstractAuthenticator {
>>
>>        protected MembersAuthenticator(String type) {
>>            super(type);
> ahhh, I see, this must be a old version of AbstractAuthenticator, the
> new AbstractAuthenticator
> (from the 1.5.8-SNAPSHOT) constructor takes a AuthenticationLevel
>
> AbstractAuthenticator( AuthenticationLevel type ) so the above code should be
>
> protected MembersAuthenticator(AuthenticationLevel type) {
>            super(type);
> ....
>
> this is the reason why your authenticator is not recognized. I guess
> you must be developing and deploying with different versions.
>
>
>>            System.out.println("\nMembersAuthenticator() " + type);
>>    }
>>
>>        @Override
>>        public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
>>                System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
>>
>>                return null;
>>        }
>>
>>        @Override
>>    public String getAuthenticatorType() {
>>                System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
>>            return super.getAuthenticatorType();
>>    }
>>
>>        @Override
>>    public DirectoryService getDirectoryService() {
>>                System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
>>            return super.getDirectoryService();
>>    }
>>
>> }
>>
>> -----Original Message-----
>> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
>> Sent: Tuesday, August 03, 2010 12:12 PM
>> To: Apache Directory Developers List
>> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>>
>> hi Roy,
>>
>> On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>>> Hi Kiran,
>>>
>>> I've been trying the example.
>>>
>>> I also thought it possible that the Authenticator I have could be the problem.
>>> So I also ran the same example using other built in Authenticators.  Always the
>>> same bind problem.
>> is it possible to show us the code of your authenticator?
>>
>> Kiran Ayyagari
>>
>
> Kiran Ayyagari
>



-- 
Kiran Ayyagari

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
hi Roy,

On Wed, Aug 4, 2010 at 1:44 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi Kiran,
>
> I don't see 1.5.8 in svn.
this is the version number of the latest trunk, not yet released, that
is why am explicitly mentioning
1.5.8*-SNAPSHOT*

here is the svn url
http://svn.apache.org/repos/asf/directory/apacheds/trunk-with-dependencies

>
> I see apacheds-1.5.6, apacheds-1.5.7 under branches
> and
> 1.0.0 to 1.5.7 under tags..
>
> ?
>
> Thanks
> Roy
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 1:05 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> On Wed, Aug 4, 2010 at 1:27 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> You bet!
>>
>> :-)
>>
>> public class MembersAuthenticator extends AbstractAuthenticator {
>>
>>        protected MembersAuthenticator(String type) {
>>            super(type);
> ahhh, I see, this must be a old version of AbstractAuthenticator, the
> new AbstractAuthenticator
> (from the 1.5.8-SNAPSHOT) constructor takes a AuthenticationLevel
>
> AbstractAuthenticator( AuthenticationLevel type ) so the above code should be
>
> protected MembersAuthenticator(AuthenticationLevel type) {
>            super(type);
> ....
>
> this is the reason why your authenticator is not recognized. I guess
> you must be developing and deploying with different versions.
>
>
>>            System.out.println("\nMembersAuthenticator() " + type);
>>    }
>>
>>        @Override
>>        public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
>>                System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
>>
>>                return null;
>>        }
>>
>>        @Override
>>    public String getAuthenticatorType() {
>>                System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
>>            return super.getAuthenticatorType();
>>    }
>>
>>        @Override
>>    public DirectoryService getDirectoryService() {
>>                System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
>>            return super.getDirectoryService();
>>    }
>>
>> }
>>
>> -----Original Message-----
>> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
>> Sent: Tuesday, August 03, 2010 12:12 PM
>> To: Apache Directory Developers List
>> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>>
>> hi Roy,
>>
>> On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>>> Hi Kiran,
>>>
>>> I've been trying the example.
>>>
>>> I also thought it possible that the Authenticator I have could be the problem.
>>> So I also ran the same example using other built in Authenticators.  Always the
>>> same bind problem.
>> is it possible to show us the code of your authenticator?
>>
>> Kiran Ayyagari
>>
>
> Kiran Ayyagari
>



-- 
Kiran Ayyagari

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Answered my own question, trunk is currently 1.5.8, right?

-----Original Message-----
From: Benjamin, Roy [mailto:rbenjamin@ebay.com] 
Sent: Tuesday, August 03, 2010 1:14 PM
To: Apache Directory Developers List
Subject: RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Hi Kiran,

I don't see 1.5.8 in svn.   

I see apacheds-1.5.6, apacheds-1.5.7 under branches
and
1.0.0 to 1.5.7 under tags..

?

Thanks
Roy

-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Tuesday, August 03, 2010 1:05 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

On Wed, Aug 4, 2010 at 1:27 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> You bet!
>
> :-)
>
> public class MembersAuthenticator extends AbstractAuthenticator {
>
>        protected MembersAuthenticator(String type) {
>            super(type);
ahhh, I see, this must be a old version of AbstractAuthenticator, the
new AbstractAuthenticator
(from the 1.5.8-SNAPSHOT) constructor takes a AuthenticationLevel

AbstractAuthenticator( AuthenticationLevel type ) so the above code should be

protected MembersAuthenticator(AuthenticationLevel type) {
            super(type);
....

this is the reason why your authenticator is not recognized. I guess
you must be developing and deploying with different versions.


>            System.out.println("\nMembersAuthenticator() " + type);
>    }
>
>        @Override
>        public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
>                System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
>
>                return null;
>        }
>
>        @Override
>    public String getAuthenticatorType() {
>                System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
>            return super.getAuthenticatorType();
>    }
>
>        @Override
>    public DirectoryService getDirectoryService() {
>                System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
>            return super.getDirectoryService();
>    }
>
> }
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 12:12 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> hi Roy,
>
> On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> Hi Kiran,
>>
>> I've been trying the example.
>>
>> I also thought it possible that the Authenticator I have could be the problem.
>> So I also ran the same example using other built in Authenticators.  Always the
>> same bind problem.
> is it possible to show us the code of your authenticator?
>
> Kiran Ayyagari
>

Kiran Ayyagari

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi Kiran,

I don't see 1.5.8 in svn.   

I see apacheds-1.5.6, apacheds-1.5.7 under branches
and
1.0.0 to 1.5.7 under tags..

?

Thanks
Roy

-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Tuesday, August 03, 2010 1:05 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

On Wed, Aug 4, 2010 at 1:27 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> You bet!
>
> :-)
>
> public class MembersAuthenticator extends AbstractAuthenticator {
>
>        protected MembersAuthenticator(String type) {
>            super(type);
ahhh, I see, this must be a old version of AbstractAuthenticator, the
new AbstractAuthenticator
(from the 1.5.8-SNAPSHOT) constructor takes a AuthenticationLevel

AbstractAuthenticator( AuthenticationLevel type ) so the above code should be

protected MembersAuthenticator(AuthenticationLevel type) {
            super(type);
....

this is the reason why your authenticator is not recognized. I guess
you must be developing and deploying with different versions.


>            System.out.println("\nMembersAuthenticator() " + type);
>    }
>
>        @Override
>        public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
>                System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
>
>                return null;
>        }
>
>        @Override
>    public String getAuthenticatorType() {
>                System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
>            return super.getAuthenticatorType();
>    }
>
>        @Override
>    public DirectoryService getDirectoryService() {
>                System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
>            return super.getDirectoryService();
>    }
>
> }
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 12:12 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> hi Roy,
>
> On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> Hi Kiran,
>>
>> I've been trying the example.
>>
>> I also thought it possible that the Authenticator I have could be the problem.
>> So I also ran the same example using other built in Authenticators.  Always the
>> same bind problem.
> is it possible to show us the code of your authenticator?
>
> Kiran Ayyagari
>

Kiran Ayyagari

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
On Wed, Aug 4, 2010 at 1:27 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> You bet!
>
> :-)
>
> public class MembersAuthenticator extends AbstractAuthenticator {
>
>        protected MembersAuthenticator(String type) {
>            super(type);
ahhh, I see, this must be a old version of AbstractAuthenticator, the
new AbstractAuthenticator
(from the 1.5.8-SNAPSHOT) constructor takes a AuthenticationLevel

AbstractAuthenticator( AuthenticationLevel type ) so the above code should be

protected MembersAuthenticator(AuthenticationLevel type) {
            super(type);
....

this is the reason why your authenticator is not recognized. I guess
you must be developing and deploying with different versions.


>            System.out.println("\nMembersAuthenticator() " + type);
>    }
>
>        @Override
>        public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
>                System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
>
>                return null;
>        }
>
>        @Override
>    public String getAuthenticatorType() {
>                System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
>            return super.getAuthenticatorType();
>    }
>
>        @Override
>    public DirectoryService getDirectoryService() {
>                System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
>            return super.getDirectoryService();
>    }
>
> }
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 12:12 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> hi Roy,
>
> On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> Hi Kiran,
>>
>> I've been trying the example.
>>
>> I also thought it possible that the Authenticator I have could be the problem.
>> So I also ran the same example using other built in Authenticators.  Always the
>> same bind problem.
> is it possible to show us the code of your authenticator?
>
> Kiran Ayyagari
>

Kiran Ayyagari

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
You bet!

:-)

public class MembersAuthenticator extends AbstractAuthenticator {

	protected MembersAuthenticator(String type) {
	    super(type);
	    System.out.println("\nMembersAuthenticator() " + type);
    }

	@Override
	public LdapPrincipal authenticate(BindOperationContext bindOperationContext) throws Exception {
		System.out.println("\nMembersAuthenticator.authenticate() " + bindOperationContext.getName());
		
		return null;
	}

	@Override
    public String getAuthenticatorType() {
		System.out.println("\nMembersAuthenticator.getAuthenticatorType() " + super.getAuthenticatorType());
	    return super.getAuthenticatorType();
    }

	@Override
    public DirectoryService getDirectoryService() {
		System.out.println("\nMembersAuthenticator.getDirectoryService() " + super.getDirectoryService());
	    return super.getDirectoryService();
    }

}

-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Tuesday, August 03, 2010 12:12 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

hi Roy,

On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi Kiran,
>
> I've been trying the example.
>
> I also thought it possible that the Authenticator I have could be the problem.
> So I also ran the same example using other built in Authenticators.  Always the
> same bind problem.
is it possible to show us the code of your authenticator?

Kiran Ayyagari

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
hi Roy,

On Wed, Aug 4, 2010 at 12:31 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi Kiran,
>
> I've been trying the example.
>
> I also thought it possible that the Authenticator I have could be the problem.
> So I also ran the same example using other built in Authenticators.  Always the
> same bind problem.
is it possible to show us the code of your authenticator?

Kiran Ayyagari

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi Kiran,

I've been trying the example.

I also thought it possible that the Authenticator I have could be the problem.
So I also ran the same example using other built in Authenticators.  Always the
same bind problem.

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 <rb...@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 );
    }

}

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi Kiran,

Thank you very much for getting back to me.  I must have misunderstood what value to
use for -Dschema.resource.location.

In your original mail you had it pointing to the full path of the ApacheDS'all' jar file.
For me this is in the lib dir of the web application, so the results didn't seem any
different.  I tried hard-coding the absolute path from the root as well.

I'll look at your example, attached to the next email.

Thanks again!

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 <rb...@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 );
    }

}

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi,

You bet, I can always just stop the service and run using startup.bat.
It was the first thing I tried.  I added the -D inside the script to be
sure.

I am I right to assume it points to the jar because the jar contains the needed files ?

Thanks
Roy

-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Tuesday, August 03, 2010 1:14 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

On Wed, Aug 4, 2010 at 1:30 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi,
>
> I usually run as a service, so added:
>
> -Dschema.resource.location=C:\Tomcat_5_5\webapps\ApacheDSXX\WEB-INF\lib\apacheds-all-1.5.8-SNAPSHOT.jar
>
> in the Java tab, Java Options.
hmm, its been many years since I worked on a windows machine, so can't
really say whats going on there, can you install tomcat from a zip
archive and run from the command line and see?
(for get not to set the JAVA_OPTS env variable with the above value)
>
> Thanks
> Roy
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 12:11 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> 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 <rb...@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 <rb...@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 <rb...@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 );
>>>    }
>>>
>>> }
>>>
>



--
Kiran Ayyagari

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
On Wed, Aug 4, 2010 at 1:30 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi,
>
> I usually run as a service, so added:
>
> -Dschema.resource.location=C:\Tomcat_5_5\webapps\ApacheDSXX\WEB-INF\lib\apacheds-all-1.5.8-SNAPSHOT.jar
>
> in the Java tab, Java Options.
hmm, its been many years since I worked on a windows machine, so can't
really say whats going on there, can you install tomcat from a zip
archive and run from the command line and see?
(for get not to set the JAVA_OPTS env variable with the above value)
>
> Thanks
> Roy
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Tuesday, August 03, 2010 12:11 PM
> To: Apache Directory Developers List
> Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype
>
> 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 <rb...@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 <rb...@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 <rb...@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 );
>>>    }
>>>
>>> }
>>>
>



-- 
Kiran Ayyagari

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi,

I usually run as a service, so added:

-Dschema.resource.location=C:\Tomcat_5_5\webapps\ApacheDSXX\WEB-INF\lib\apacheds-all-1.5.8-SNAPSHOT.jar

in the Java tab, Java Options.

Thanks
Roy

-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Tuesday, August 03, 2010 12:11 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

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 <rb...@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 <rb...@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 <rb...@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 );
>>    }
>>
>> }
>>

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
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 <rb...@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 <rb...@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 <rb...@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 );
>>    }
>>
>> }
>>

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
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 <rb...@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 <rb...@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 );
>    }
>
> }
>

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
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 <rb...@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 <rb...@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 );
>    }
>
> }
>

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
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 <rb...@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 );
    }

}

Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
hi Roy,

    more inline

On Tue, Aug 3, 2010 at 6:28 AM, Benjamin, Roy <rb...@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 );
    }

}

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
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 ?



If I copy example.ldif from a binary ApacheDS installation to:

   C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema



I actually need two ldif files in order to correct the exceptions, I need both 'schema.ldif' -and-

'ou=schema.ldif', to make this work I copy the example.ldif twice to both names.



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.



I appreciate any assistance immensely,



Thanks

Roy



RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi,

You bet, I have to deal with a large corporate environment; it made maven
difficult to deal with.  Most developers work within the approved jar framework
and never hot an external repository at all.  I actually had to remove my local
repository, settings, xml, etc.. and start over.

I can't seem to get IRC working, not sure what's wrong but unable to contact any
servers.  I think possibly it's blocked.

I was initially very encouraged because there are several examples for embedded
server.  Well documented on an HTML page and all.  After I got them built I've
not been able to run them.   Actually, one of them runs unless I try to add an
Authenticator.  The others fail to run for various reasons related files and
configuration I guess.  There is also a standalone example, I can't tell if it's
working or not because it's impossible to discover what port it's using; not
a known or standard one I guess.  There also doesn't seem to be any API to set
the port before starting the server.

Some of the embedded examples are documented as working with a previous version,
so I've finally got four different versions built and should be able to get an
example working.  I'm a reasonably competent maven user but no expert for sure,
the maven versioning within each of these source trees seems really inconsistent 
though.  Still I can build, and start an embedded server, it's just not possible
to programmatically add an Authenticator I guess.  I wouldn't have worked on this
as long as I have except that I don't have a viable 'Plan B' right now.  I really
do appreciate the open source community; it's about the only source for quality
software now days.  In this case it's been more frustrating than I had possibly
imagined.

Thanks!
Roy



-----Original Message-----
From: Emmanuel Lecharny [mailto:elecharny@gmail.com] 
Sent: Monday, August 02, 2010 5:14 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

  On 8/2/10 11:16 PM, Benjamin, Roy wrote:
> Thank Kiran,
>
> Still not working but I'll keep trying for a while.   I've been working for ten days
> now trying to get at least one of the provided embedded examples working.   I appreciate
> all the work contributors do but I must say in thirty years I've never had this much
> trouble getting an Apache example to work.

Yeah, but you must admit that many of the problem you faced so far 
weren't ADS related (I'm thinking about Maven issues you had, for instance.)

Plus this is not simply as if you were installing ADS alone : you are 
trying to embed it in a tomcat server, with all the classloaders problem 
and file protections that come with ...

May I suggest you move forward step by step instead of tying all together ?

PS : I very much understand your feeling, btw. I too am a old fart who 
fumes when testing an open source program and don't succeed after a few 
steps... yuk, that's life ! :)

Btw, if you need more interactive directions, try to join us on IRC 
(#apache-directory).

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


Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

Posted by Emmanuel Lecharny <el...@gmail.com>.
  On 8/2/10 11:16 PM, Benjamin, Roy wrote:
> Thank Kiran,
>
> Still not working but I'll keep trying for a while.   I've been working for ten days
> now trying to get at least one of the provided embedded examples working.   I appreciate
> all the work contributors do but I must say in thirty years I've never had this much
> trouble getting an Apache example to work.

Yeah, but you must admit that many of the problem you faced so far 
weren't ADS related (I'm thinking about Maven issues you had, for instance.)

Plus this is not simply as if you were installing ADS alone : you are 
trying to embed it in a tomcat server, with all the classloaders problem 
and file protections that come with ...

May I suggest you move forward step by step instead of tying all together ?

PS : I very much understand your feeling, btw. I too am a old fart who 
fumes when testing an open source program and don't succeed after a few 
steps... yuk, that's life ! :)

Btw, if you need more interactive directions, try to join us on IRC 
(#apache-directory).

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


Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

Posted by Stefan Zoerner <st...@labeo.de>.
Stefan Seelmann wrote:
> On Tue, Aug 3, 2010 at 10:35 AM, Stefan Zoerner <st...@labeo.de> wrote:
>> I have originally created the example and the documentation for embedding
>> the server within a web application.
>>
>> Unfortunately, I had to readjust it several times due to changes in the
>> ApacheDS API. Various minor version broke the example code.
>>
>> I plan to revisited the examples for the 2.0 RC, and hopefully the API for
>> embedding the server, and the way how to configure it programmatically will
>> stabilize then.
> 
> To add my 2 cents: To achieve this we should add all samples to svn,
> add tests for the samples if possible, and include the samples to the
> ApacheDS build. Then hopefully the samples and the core code can be
> kept in sync.

+1

First I will determine which examples should be included.
AFAIK the are in svn already, but not in the build. Some interesting 
ones are located in the sandbox, like these:

http://svn.apache.org/repos/asf/directory/sandbox/szoerner/helloWorldPartition/
http://svn.apache.org/repos/asf/directory/sandbox/szoerner/passwordHashInterceptor/
http://svn.apache.org/repos/asf/directory/sandbox/szoerner/apacheds-tomcatrealm/

Perhaps we use

http://svn.apache.org/repos/asf/directory/samples/

as a starting point.

At least helloWorldPartition and passwordHashInterceptor are good 
candidates to move to that point as is.

For the important embedding example in

http://svn.apache.org/repos/asf/directory/samples/trunk/apacheds-archetype-webapp

the archetype approach is oversized from my point of view. It would do 
if it is organized like helloWorldPartition, emitting a WAR file at the end.

Greetings from Hamburg,
     StefanZ




Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
On Tue, Aug 3, 2010 at 2:20 PM, Stefan Seelmann <se...@apache.org> wrote:
> On Tue, Aug 3, 2010 at 10:35 AM, Stefan Zoerner <st...@labeo.de> wrote:
>> I have originally created the example and the documentation for embedding
>> the server within a web application.
>>
>> Unfortunately, I had to readjust it several times due to changes in the
>> ApacheDS API. Various minor version broke the example code.
>>
>> I plan to revisited the examples for the 2.0 RC, and hopefully the API for
>> embedding the server, and the way how to configure it programmatically will
>> stabilize then.
>
> To add my 2 cents: To achieve this we should add all samples to svn,
> add tests for the samples if possible, and include the samples to the
> ApacheDS build. Then hopefully the samples and the core code can be
> kept in sync.
a big +1, samples are in the svn but we need to add them to the CI
build if not to our dev build

Kiran Ayyagari

Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

Posted by Stefan Seelmann <se...@apache.org>.
On Tue, Aug 3, 2010 at 10:35 AM, Stefan Zoerner <st...@labeo.de> wrote:
> I have originally created the example and the documentation for embedding
> the server within a web application.
>
> Unfortunately, I had to readjust it several times due to changes in the
> ApacheDS API. Various minor version broke the example code.
>
> I plan to revisited the examples for the 2.0 RC, and hopefully the API for
> embedding the server, and the way how to configure it programmatically will
> stabilize then.

To add my 2 cents: To achieve this we should add all samples to svn,
add tests for the samples if possible, and include the samples to the
ApacheDS build. Then hopefully the samples and the core code can be
kept in sync.

Kind Regards,
Stefan

RE: Startup Error for Embedded ApacheDS Created by ApacheDS archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi Stefanz,

It's a well documented example and I appreciate your work.

Hamburg is one of my favorite cities in Germany, especially in the
summer.

Thanks again!
Roy

-----Original Message-----
From: Stefan Zoerner [mailto:stefan@labeo.de] 
Sent: Tuesday, August 03, 2010 1:35 AM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

Hi Benjamin!

Benjamin, Roy wrote:
> Still not working but I'll keep trying for a while.   I've been working for ten days
> now trying to get at least one of the provided embedded examples working.   I appreciate
> all the work contributors do but I must say in thirty years I've never had this much
> trouble getting an Apache example to work.

I have originally created the example and the documentation for 
embedding the server within a web application.

Unfortunately, I had to readjust it several times due to changes in the 
ApacheDS API. Various minor version broke the example code.

I plan to revisited the examples for the 2.0 RC, and hopefully the API 
for embedding the server, and the way how to configure it 
programmatically will stabilize then.

Sorry for the inconvenience and Greetings from Hamburg,
     StefanZ



Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

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

Benjamin, Roy wrote:
> Still not working but I'll keep trying for a while.   I've been working for ten days
> now trying to get at least one of the provided embedded examples working.   I appreciate
> all the work contributors do but I must say in thirty years I've never had this much
> trouble getting an Apache example to work.

I have originally created the example and the documentation for 
embedding the server within a web application.

Unfortunately, I had to readjust it several times due to changes in the 
ApacheDS API. Various minor version broke the example code.

I plan to revisited the examples for the 2.0 RC, and hopefully the API 
for embedding the server, and the way how to configure it 
programmatically will stabilize then.

Sorry for the inconvenience and Greetings from Hamburg,
     StefanZ



RE: Startup Error for Embedded ApacheDS Created by apacheds archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Thank Kiran,

Still not working but I'll keep trying for a while.   I've been working for ten days
now trying to get at least one of the provided embedded examples working.   I appreciate
all the work contributors do but I must say in thirty years I've never had this much
trouble getting an Apache example to work.

Cheers and Thanks again for the tips.

Roy



-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Monday, August 02, 2010 1:37 PM
To: Apache Directory Developers List
Subject: Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

hi Roy,

    the example webapp stores the data in the tomcat servercontext's temporary
    location, you need to tweak the app to change the working directory of the
    directory service.

    Another important thing is to start tomcat with the VM option
-Dschema.resource.location=<complete-path-to>/apacheds-all-<version>.jar

this is required to setup if the directoryservice's working directory
doesn't contain a
schema folder.

P.S:- Note that the only way to retain this schema and the
workingdirectory data is to
        give a non-temporary location

HTH
Kiran Ayyagari

On Tue, Aug 3, 2010 at 2:00 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi,
>
> Very new to DS.  I got the maven archetype working, but have a File Not Found Exception.
>
> The cause is obvious, but I'm not sure what the intent of the archetype is.
>
> The message: Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema
>
> seems especially odd...
>
> What is the intent?  Should we point to another directory outside of Tomcat or what ?
>
> I just need a simple working embedded ApacheDS for my use case.
>
> Thanks
> Roy
>
>
>
> Aug 2, 2010 1:20:49 PM org.apache.catalina.core.StandardContext listenerStart
> SEVERE: Exception sending context initialized event to listener instance of class org.example.StartStopListener
> Throwable occurred: java.lang.RuntimeException: java.io.IOException: ERR_08001 Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema
>        at org.example.StartStopListener.contextInitialized(StartStopListener.java:90)
>        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3795)
>        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
>        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
>        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
>        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
>        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:884)
>        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:737)
>        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
>        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1203)
>        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)
>        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
>        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
>        at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
>        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
>        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>        at org.apache.catalina.core.StandardService.start(StandardService.java:448)
>        at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
>        at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
>        at java.lang.reflect.Method.invoke(Method.java:599)
>        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
>        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
> Caused by: java.io.IOException: ERR_08001 Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema
>        at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.extractOrCopy(DefaultSchemaLdifExtractor.java:141)
>        at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.extractOrCopy(DefaultSchemaLdifExtractor.java:171)
>        at org.example.StartStopListener.initSchema(StartStopListener.java:122)
>        at org.example.StartStopListener.contextInitialized(StartStopListener.java:81)
>        ... 24 more
>

Re: Startup Error for Embedded ApacheDS Created by apacheds archetype

Posted by Kiran Ayyagari <ka...@apache.org>.
hi Roy,

    the example webapp stores the data in the tomcat servercontext's temporary
    location, you need to tweak the app to change the working directory of the
    directory service.

    Another important thing is to start tomcat with the VM option
-Dschema.resource.location=<complete-path-to>/apacheds-all-<version>.jar

this is required to setup if the directoryservice's working directory
doesn't contain a
schema folder.

P.S:- Note that the only way to retain this schema and the
workingdirectory data is to
        give a non-temporary location

HTH
Kiran Ayyagari

On Tue, Aug 3, 2010 at 2:00 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi,
>
> Very new to DS.  I got the maven archetype working, but have a File Not Found Exception.
>
> The cause is obvious, but I'm not sure what the intent of the archetype is.
>
> The message: Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema
>
> seems especially odd...
>
> What is the intent?  Should we point to another directory outside of Tomcat or what ?
>
> I just need a simple working embedded ApacheDS for my use case.
>
> Thanks
> Roy
>
>
>
> Aug 2, 2010 1:20:49 PM org.apache.catalina.core.StandardContext listenerStart
> SEVERE: Exception sending context initialized event to listener instance of class org.example.StartStopListener
> Throwable occurred: java.lang.RuntimeException: java.io.IOException: ERR_08001 Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema
>        at org.example.StartStopListener.contextInitialized(StartStopListener.java:90)
>        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3795)
>        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
>        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
>        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
>        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
>        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:884)
>        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:737)
>        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
>        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1203)
>        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)
>        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
>        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
>        at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
>        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
>        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>        at org.apache.catalina.core.StandardService.start(StandardService.java:448)
>        at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
>        at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
>        at java.lang.reflect.Method.invoke(Method.java:599)
>        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
>        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
> Caused by: java.io.IOException: ERR_08001 Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema
>        at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.extractOrCopy(DefaultSchemaLdifExtractor.java:141)
>        at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.extractOrCopy(DefaultSchemaLdifExtractor.java:171)
>        at org.example.StartStopListener.initSchema(StartStopListener.java:122)
>        at org.example.StartStopListener.contextInitialized(StartStopListener.java:81)
>        ... 24 more
>

Startup Error for Embedded ApacheDS Created by apacheds archetype

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Hi,

Very new to DS.  I got the maven archetype working, but have a File Not Found Exception.

The cause is obvious, but I'm not sure what the intent of the archetype is.  

The message: Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema

seems especially odd... 

What is the intent?  Should we point to another directory outside of Tomcat or what ?

I just need a simple working embedded ApacheDS for my use case.

Thanks
Roy



Aug 2, 2010 1:20:49 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.example.StartStopListener
Throwable occurred: java.lang.RuntimeException: java.io.IOException: ERR_08001 Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema
	at org.example.StartStopListener.contextInitialized(StartStopListener.java:90)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3795)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:884)
	at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:737)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1203)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:448)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:599)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: java.io.IOException: ERR_08001 Cannot overwrite yet schema output directory already exists: C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema
	at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.extractOrCopy(DefaultSchemaLdifExtractor.java:141)
	at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.extractOrCopy(DefaultSchemaLdifExtractor.java:171)
	at org.example.StartStopListener.initSchema(StartStopListener.java:122)
	at org.example.StartStopListener.contextInitialized(StartStopListener.java:81)
	... 24 more

Re: How to add a custom Authenticator using API

Posted by Kiran Ayyagari <ka...@apache.org>.
On Mon, Aug 2, 2010 at 10:02 PM, Benjamin, Roy <rb...@ebay.com> wrote:
> Thanks Kiran,
>
> How can I start an embedded server that uses an apacheds.conf file ?
nope there is currently no way to configure an embedded server through
conf file.

Kiran Ayyagari

>
> Thanks
> Roy
>
> -----Original Message-----
> From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
> Sent: Saturday, July 31, 2010 12:19 AM
> To: Apache Directory Developers List
> Subject: Re: How to add a custom Authenticator using API
>
> hi Roy,
>
>    You have to do that before starting up the directory service
>    e.x
>
>            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("MyAuthenticator"));
>
>       authInterceptor.setAuthenticators( authenticators );
>
>      // finally start the directoryService
>      directoryService.startup();
>
>
> Kiran Ayyagari
>
>
> On Sat, Jul 31, 2010 at 6:47 AM, Benjamin, Roy <rb...@ebay.com> wrote:
>> Hi,
>>
>> I'm starting from the example at: http://directory.apache.org/apacheds/1.5/43-embedding-apacheds-as-a-web-application.html
>>
>> I want to run ApacheDS embedded in Tomcat, finally got that working with this example.
>>
>> Now, I need to add a custom authenticator.
>>
>> Being late on Friday I tried:
>>
>>
>> List<Interceptor> interceptors = directoryService.getInterceptors();
>> System.out.println(interceptors == null ? "Yikes!" : interceptors.size());
>> for (Interceptor interceptor:interceptors) {
>>        System.out.println(interceptor.getName());
>>        if (interceptor instanceof AuthenticationInterceptor) {
>>                Set<Authenticator> authenticators = ((AuthenticationInterceptor)interceptor).getAuthenticators();
>>                if (null == authenticators) {
>>                        authenticators = new HashSet<Authenticator>(0);
>>                        ((AuthenticationInterceptor)interceptor).setAuthenticators(authenticators);
>>                }
>>                authenticators.add(new MyAuthenticator("MyAuthenticator"));
>>                System.out.println("authenticators:" + authenticators);
>>        }
>> }
>>
>> I'm sure this is wrong (see below).  Any help greatly appreciate das usual!
>>
>> Roy
>>
>> 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.
>>        org.apache.directory.server.core.RootDseServlet.doGet(RootDseServlet.java:86)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
>>        com.ebay.trading.salestax.vertex.VertexCalFilter.doFilter(VertexCalFilter.java:104)
>>
>> 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.
>>        org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition.bind(JdbmPartition.java:577)
>>        org.apache.directory.server.core.partition.DefaultPartitionNexus.bind(DefaultPartitionNexus.java:800)
>>        org.apache.directory.server.core.interceptor.InterceptorChain$1.bind(InterceptorChain.java:206)
>>      .....
>>
>

RE: How to add a custom Authenticator using API

Posted by "Benjamin, Roy" <rb...@ebay.com>.
Thanks Kiran,

Here is the full un-snipped text of my ContextInitialized() method:

public void contextInitialized(ServletContextEvent evt) {
		System.out.println("StartStopListener.contextInitialized() " + evt.getServletContext().getServerInfo());
		try {
			directoryService = new DefaultDirectoryService();
			directoryService.setShutdownHookEnabled(true);

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

			// Set LDAP port to 10389
			TcpTransport[] ldapTransports = new TcpTransport[1];
			ldapTransports[0] = new TcpTransport(10389);
			ldapServer.setTransports(ldapTransports);

			// Determine an appropriate working directory
			ServletContext servletContext = evt.getServletContext();
			File workingDir = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
			directoryService.setWorkingDirectory(workingDir);
			
			//////////////////////////
			List<Interceptor> interceptors = directoryService.getInterceptors();
			System.out.println(interceptors == null ? "Yikes!" : interceptors.size());
			for (Interceptor interceptor:interceptors) {
				System.out.println(interceptor.getName());
				if (interceptor instanceof AuthenticationInterceptor) {
					Set<Authenticator> authenticators = ((AuthenticationInterceptor)interceptor).getAuthenticators();
					if (null == authenticators) {
						authenticators = new HashSet<Authenticator>(0);
						((AuthenticationInterceptor)interceptor).setAuthenticators(authenticators);
					} 
					authenticators.add(new MembersAuthenticator("MembersAuthenticator"));
					System.out.println("authenticators:" + authenticators);
				}
			}
			///////////////////////////////
			
			directoryService.startup();
			ldapServer.start();

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


I'm getting the exception before starting the server.

Any ideas ?

How can I start an embedded server that uses an apacheds.conf file ?

Thanks
Roy

-----Original Message-----
From: ayyagarikiran@gmail.com [mailto:ayyagarikiran@gmail.com] On Behalf Of Kiran Ayyagari
Sent: Saturday, July 31, 2010 12:19 AM
To: Apache Directory Developers List
Subject: Re: How to add a custom Authenticator using API

hi Roy,

    You have to do that before starting up the directory service
    e.x

            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("MyAuthenticator"));

       authInterceptor.setAuthenticators( authenticators );

      // finally start the directoryService
      directoryService.startup();


Kiran Ayyagari


On Sat, Jul 31, 2010 at 6:47 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi,
>
> I'm starting from the example at: http://directory.apache.org/apacheds/1.5/43-embedding-apacheds-as-a-web-application.html
>
> I want to run ApacheDS embedded in Tomcat, finally got that working with this example.
>
> Now, I need to add a custom authenticator.
>
> Being late on Friday I tried:
>
>
> List<Interceptor> interceptors = directoryService.getInterceptors();
> System.out.println(interceptors == null ? "Yikes!" : interceptors.size());
> for (Interceptor interceptor:interceptors) {
>        System.out.println(interceptor.getName());
>        if (interceptor instanceof AuthenticationInterceptor) {
>                Set<Authenticator> authenticators = ((AuthenticationInterceptor)interceptor).getAuthenticators();
>                if (null == authenticators) {
>                        authenticators = new HashSet<Authenticator>(0);
>                        ((AuthenticationInterceptor)interceptor).setAuthenticators(authenticators);
>                }
>                authenticators.add(new MyAuthenticator("MyAuthenticator"));
>                System.out.println("authenticators:" + authenticators);
>        }
> }
>
> I'm sure this is wrong (see below).  Any help greatly appreciate das usual!
>
> Roy
>
> 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.
>        org.apache.directory.server.core.RootDseServlet.doGet(RootDseServlet.java:86)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
>        com.ebay.trading.salestax.vertex.VertexCalFilter.doFilter(VertexCalFilter.java:104)
>
> 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.
>        org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition.bind(JdbmPartition.java:577)
>        org.apache.directory.server.core.partition.DefaultPartitionNexus.bind(DefaultPartitionNexus.java:800)
>        org.apache.directory.server.core.interceptor.InterceptorChain$1.bind(InterceptorChain.java:206)
>      .....
>

Re: How to add a custom Authenticator using API

Posted by Kiran Ayyagari <ka...@apache.org>.
hi Roy,

    You have to do that before starting up the directory service
    e.x

            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("MyAuthenticator"));

       authInterceptor.setAuthenticators( authenticators );

      // finally start the directoryService
      directoryService.startup();


Kiran Ayyagari


On Sat, Jul 31, 2010 at 6:47 AM, Benjamin, Roy <rb...@ebay.com> wrote:
> Hi,
>
> I'm starting from the example at: http://directory.apache.org/apacheds/1.5/43-embedding-apacheds-as-a-web-application.html
>
> I want to run ApacheDS embedded in Tomcat, finally got that working with this example.
>
> Now, I need to add a custom authenticator.
>
> Being late on Friday I tried:
>
>
> List<Interceptor> interceptors = directoryService.getInterceptors();
> System.out.println(interceptors == null ? "Yikes!" : interceptors.size());
> for (Interceptor interceptor:interceptors) {
>        System.out.println(interceptor.getName());
>        if (interceptor instanceof AuthenticationInterceptor) {
>                Set<Authenticator> authenticators = ((AuthenticationInterceptor)interceptor).getAuthenticators();
>                if (null == authenticators) {
>                        authenticators = new HashSet<Authenticator>(0);
>                        ((AuthenticationInterceptor)interceptor).setAuthenticators(authenticators);
>                }
>                authenticators.add(new MyAuthenticator("MyAuthenticator"));
>                System.out.println("authenticators:" + authenticators);
>        }
> }
>
> I'm sure this is wrong (see below).  Any help greatly appreciate das usual!
>
> Roy
>
> 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.
>        org.apache.directory.server.core.RootDseServlet.doGet(RootDseServlet.java:86)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
>        com.ebay.trading.salestax.vertex.VertexCalFilter.doFilter(VertexCalFilter.java:104)
>
> 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.
>        org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition.bind(JdbmPartition.java:577)
>        org.apache.directory.server.core.partition.DefaultPartitionNexus.bind(DefaultPartitionNexus.java:800)
>        org.apache.directory.server.core.interceptor.InterceptorChain$1.bind(InterceptorChain.java:206)
>      .....
>