You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Stefan Zoerner <st...@labeo.de> on 2008/10/04 23:58:40 UTC
Connecting the embedded way via JNDI: Cannot find directory service
in environment
Hi all,
currently I try to update the example on how to embedd ApacheDS in a WebApp
http://directory.apache.org/apacheds/1.5/embedding-apacheds-as-a-web-application.html
in order to let it work with ApacheDS 1.5.4. The API has been changed
since 1.5.1 (for which the example has been created for), hence the
source code examples do not work anymore.
My web app is already able to start and stop a 1.5.4 ApacheDS server via
a ServletContextListener.
Now I have a question regarding an embedded client. In the example, a
servlet connects to the server without wire protocol (embedded). It uses
JNDI for that. The old cfg does not seem to work. An env like this
---
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(Context.PROVIDER_URL, "");
env.put(Context.INITIAL_CONTEXT_FACTORY,
CoreContextFactory.class.getName() );
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "secret");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
---
causes an error, if the InitialContext is created:
javax.naming.ConfigurationException: Cannot find directory service in
environment:
{java.naming.factory.initial=org.apache.directory.server.core.jndi.CoreContextFactory,
java.naming.provider.url=,
java.naming.factory.url.pkgs=org.apache.naming,
java.naming.security.authentication=simple,
java.naming.security.principal=uid=admin,ou=system,
java.naming.security.credentials=[B@1b6634c}
---
It seems that I have to do something like this:
env.put( DirectoryService.JNDI_KEY, directoryService );
as in AbstractServerTest. Is this right? In this case, I have to
remember the DirectoryService instance somewhere. Solvable, but the old
way was easier ... Or am I totally wrong?
Thanks in advance,
Stefan
Re: Connecting the embedded way via JNDI: Cannot find directory service in environment
Posted by Alex Karasulu <ak...@apache.org>.
On Sat, Oct 4, 2008 at 6:54 PM, Stefan Zoerner <st...@labeo.de> wrote:
> Alex Karasulu wrote:
>
>> Thanks Stefan and sorry for the trouble after these changes.
>>
>
> No need to worry. The code to start and stop the server without JNDI is so
> much easier now. It is definitely worth a little trouble.
>
That's good to hear. Guess we're going in the right direction with these
changes.
Alex
Re: Connecting the embedded way via JNDI: Cannot find directory service
in environment
Posted by Emmanuel Lecharny <el...@gmail.com>.
Stefan Zoerner wrote:
> Alex Karasulu wrote:
>> Thanks Stefan and sorry for the trouble after these changes.
>
> No need to worry. The code to start and stop the server without JNDI
> is so much easier now. It is definitely worth a little trouble.
I think something valuable would be to do the very same thing (embedding
the server) _without_ using JNDI. The Core API is way easier than JNDI.
We have to write a quick sample in this area.
Thanks Stefan for the update, and thanks Alex for the clarifications !
nn guys !
PS : Stefan, I think that with the new Referral handling, we may fix a
lot of the Vsldap errors we had (Standard). It's not finished yet, but
will be soon.
--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org
Re: Connecting the embedded way via JNDI: Cannot find directory service
in environment
Posted by Stefan Zoerner <st...@labeo.de>.
Alex Karasulu wrote:
> Thanks Stefan and sorry for the trouble after these changes.
No need to worry. The code to start and stop the server without JNDI is
so much easier now. It is definitely worth a little trouble.
Good night,
Stefan
Re: Connecting the embedded way via JNDI: Cannot find directory service in environment
Posted by Alex Karasulu <ak...@apache.org>.
Thanks Stefan and sorry for the trouble after these changes.
Alex
On Sat, Oct 4, 2008 at 6:47 PM, Stefan Zoerner <st...@labeo.de> wrote:
> Alex Karasulu wrote:
>
>> No need to come back to the previous version. The CoreContextFactory can
>> still be used ask you saw Stefan but now with the DirectoryService provided.
>> ...
>>
>
> Thanks for clarification, Alex. My code does work now. I haven't expected
> anything else after your hints though :-)
>
> I will update the confluence docs with the example tomorrow.
>
> Thanks again, to Emmanuel as well, Stefan
>
>
Re: Connecting the embedded way via JNDI: Cannot find directory service
in environment
Posted by Stefan Zoerner <st...@labeo.de>.
Alex Karasulu wrote:
> No need to come back to the previous version. The CoreContextFactory
> can still be used ask you saw Stefan but now with the DirectoryService
> provided. ...
Thanks for clarification, Alex. My code does work now. I haven't
expected anything else after your hints though :-)
I will update the confluence docs with the example tomorrow.
Thanks again, to Emmanuel as well, Stefan
Re: Connecting the embedded way via JNDI: Cannot find directory service in environment
Posted by Alex Karasulu <ak...@apache.org>.
No need to come back to the previous version. The CoreContextFactory can
still be used ask you saw Stefan but now with the DirectoryService provided.
To shed some light on what has happened: The initialization of the server no
longer occurs through JNDI via the CoreContextFactory. This was one of the
aims of refactoring the server to remove JNDI. JNDI is simply used in the
solid state to manipulate entries as a simple wrapper around our internal
APIs.
Now you can just add the directoryService to the environment and rely on
JNDI infrastructure to invoke the CoreContextFactory or you can bypass this
by just creating your own LdapServerContext using on of the existing
constructors. Don't know if this is the "right thing to do" according to
JNDI but it works.
Regards,
Alex
On Sat, Oct 4, 2008 at 6:13 PM, Emmanuel Lecharny <el...@gmail.com>wrote:
> Stefan Zoerner wrote:
>
>> Hi all,
>>
>> currently I try to update the example on how to embedd ApacheDS in a
>> WebApp
>>
>>
>> http://directory.apache.org/apacheds/1.5/embedding-apacheds-as-a-web-application.html
>>
>> in order to let it work with ApacheDS 1.5.4. The API has been changed
>> since 1.5.1 (for which the example has been created for), hence the source
>> code examples do not work anymore.
>>
>> My web app is already able to start and stop a 1.5.4 ApacheDS server via a
>> ServletContextListener.
>>
>> Now I have a question regarding an embedded client. In the example, a
>> servlet connects to the server without wire protocol (embedded). It uses
>> JNDI for that. The old cfg does not seem to work. An env like this
>>
>> ---
>>
>> Hashtable<Object, Object> env = new Hashtable<Object, Object>();
>> env.put(Context.PROVIDER_URL, "");
>> env.put(Context.INITIAL_CONTEXT_FACTORY,
>> CoreContextFactory.class.getName() );
>> env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
>> env.put(Context.SECURITY_CREDENTIALS, "secret");
>> env.put(Context.SECURITY_AUTHENTICATION, "simple");
>>
>> ---
>>
>> causes an error, if the InitialContext is created:
>>
>> javax.naming.ConfigurationException: Cannot find directory service in
>> environment:
>> {java.naming.factory.initial=org.apache.directory.server.core.jndi.CoreContextFactory,
>> java.naming.provider.url=, java.naming.factory.url.pkgs=org.apache.naming,
>> java.naming.security.authentication=simple,
>> java.naming.security.principal=uid=admin,ou=system,
>> java.naming.security.credentials=[B@1b6634c}
>>
>> ---
>>
>> It seems that I have to do something like this:
>>
>> env.put( DirectoryService.JNDI_KEY, directoryService );
>>
>
> yes, this is it.
>
>>
>> as in AbstractServerTest. Is this right? In this case, I have to remember
>> the DirectoryService instance somewhere. Solvable, but the old way was
>> easier ...
>>
> The problem is that the DirectoryService is not known by the JNDI layer at
> this point. I don't exactly remember how it was before, maybe Alex can give
> you some good reason why it's not any more the case.
>
> Maybe we have to come back to the previous version...
>
> --
> --
> cordialement, regards,
> Emmanuel Lécharny
> www.iktek.com
> directory.apache.org
>
>
>
Re: Connecting the embedded way via JNDI: Cannot find directory service
in environment
Posted by Stefan Zoerner <st...@labeo.de>.
Emmanuel Lecharny wrote:
>> It seems that I have to do something like this:
>>
>> env.put( DirectoryService.JNDI_KEY, directoryService );
>
> yes, this is it.
>>
>> as in AbstractServerTest. Is this right? In this case, I have to
>> remember the DirectoryService instance somewhere. Solvable, but the
>> old way was easier ...
> The problem is that the DirectoryService is not known by the JNDI layer
> at this point. I don't exactly remember how it was before, maybe Alex
> can give you some good reason why it's not any more the case.
I have thought about it -- giving the DirectoryService in the nev makes
sens, because there might be more than one of it. Thanks for the
feedback. I will ler you you know whether it works for my example.
Greetings, Stefan
Re: Connecting the embedded way via JNDI: Cannot find directory service
in environment
Posted by Emmanuel Lecharny <el...@gmail.com>.
Stefan Zoerner wrote:
> Hi all,
>
> currently I try to update the example on how to embedd ApacheDS in a
> WebApp
>
> http://directory.apache.org/apacheds/1.5/embedding-apacheds-as-a-web-application.html
>
>
> in order to let it work with ApacheDS 1.5.4. The API has been changed
> since 1.5.1 (for which the example has been created for), hence the
> source code examples do not work anymore.
>
> My web app is already able to start and stop a 1.5.4 ApacheDS server
> via a ServletContextListener.
>
> Now I have a question regarding an embedded client. In the example, a
> servlet connects to the server without wire protocol (embedded). It
> uses JNDI for that. The old cfg does not seem to work. An env like this
>
> ---
>
> Hashtable<Object, Object> env = new Hashtable<Object, Object>();
> env.put(Context.PROVIDER_URL, "");
> env.put(Context.INITIAL_CONTEXT_FACTORY,
> CoreContextFactory.class.getName() );
> env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
> env.put(Context.SECURITY_CREDENTIALS, "secret");
> env.put(Context.SECURITY_AUTHENTICATION, "simple");
>
> ---
>
> causes an error, if the InitialContext is created:
>
> javax.naming.ConfigurationException: Cannot find directory service in
> environment:
> {java.naming.factory.initial=org.apache.directory.server.core.jndi.CoreContextFactory,
> java.naming.provider.url=,
> java.naming.factory.url.pkgs=org.apache.naming,
> java.naming.security.authentication=simple,
> java.naming.security.principal=uid=admin,ou=system,
> java.naming.security.credentials=[B@1b6634c}
>
> ---
>
> It seems that I have to do something like this:
>
> env.put( DirectoryService.JNDI_KEY, directoryService );
yes, this is it.
>
> as in AbstractServerTest. Is this right? In this case, I have to
> remember the DirectoryService instance somewhere. Solvable, but the
> old way was easier ...
The problem is that the DirectoryService is not known by the JNDI layer
at this point. I don't exactly remember how it was before, maybe Alex
can give you some good reason why it's not any more the case.
Maybe we have to come back to the previous version...
--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org