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: [email protected] [mailto:[email protected]] 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 <[email protected]> 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)
> .....
>