From dev-return-34649-apmail-directory-dev-archive=directory.apache.org@directory.apache.org Tue Aug 03 16:36:12 2010 Return-Path: Delivered-To: apmail-directory-dev-archive@www.apache.org Received: (qmail 92329 invoked from network); 3 Aug 2010 16:36:12 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 3 Aug 2010 16:36:12 -0000 Received: (qmail 88095 invoked by uid 500); 3 Aug 2010 16:36:12 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 87996 invoked by uid 500); 3 Aug 2010 16:36:11 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 87986 invoked by uid 99); 3 Aug 2010 16:36:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Aug 2010 16:36:11 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ayyagarikiran@gmail.com designates 209.85.161.50 as permitted sender) Received: from [209.85.161.50] (HELO mail-fx0-f50.google.com) (209.85.161.50) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Aug 2010 16:36:03 +0000 Received: by fxm9 with SMTP id 9so2502066fxm.37 for ; Tue, 03 Aug 2010 09:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:content-type:content-transfer-encoding; bh=2+7PsLvurib+lHHgBoU7fBTVmp7B0hzdGTq3G3y/B08=; b=apFawv/UXOuVKExnLSEgNvOMDf/oufebrJx5Pk2W+s/dsmcssgyV7HL/96utnqmfEH qSzgHYu91xvtf6zfuw4IV9Z5hwmrX2bVRYOdbC9f+9ARivYmuojq3CJ9JadSmfZkl+Rz E13QP5nSMBurCcg9xAWnLnql/35tf+gVmSVt8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=TyjKLX3QMdfEhI7FSSaokhMiNpLZJkOyfAvQGFb0u/ygDNXjwRv3tqfmJC4V+zt459 pbuV+1qsc3e2YMBQ1pzkyx28og5ncagXjFBvkENySs7MhCISSM9rskQYd07DYzSMvqWA KOJRq4opSQKk0jBejkB8B2m4Pl4C9NQBI8yrc= MIME-Version: 1.0 Received: by 10.223.104.136 with SMTP id p8mr7545518fao.105.1280853342657; Tue, 03 Aug 2010 09:35:42 -0700 (PDT) Sender: ayyagarikiran@gmail.com Received: by 10.223.116.9 with HTTP; Tue, 3 Aug 2010 09:35:42 -0700 (PDT) In-Reply-To: References: <30173696.86121280489836607.JavaMail.jira@thor> <4929557.90121280511796748.JavaMail.jira@thor> <4C575F57.3040709@gmail.com> Date: Tue, 3 Aug 2010 22:05:42 +0530 X-Google-Sender-Auth: ahUBnyXpiTs5Yi8wOLio_YgW2aE Message-ID: Subject: Re: Startup Error for Embedded ApacheDS Created by ApacheDS archetype From: Kiran Ayyagari To: Apache Directory Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on 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 wrote: > Hi Kiran, > > Can you tell me which version of ApacheDS you are using? =A0The 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 arch= etype > > hi Roy, > > =A0 =A0more inline > > On Tue, Aug 3, 2010 at 6:28 AM, Benjamin, Roy 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= =3Dschema.ldif' >> but no such file found. >> >> >> >> Question: >> >> 1) Is there really supposed to be a file named: 'ou=3Dschema.ldif' ? >> >> 2) The path >> C:\Tomcat_5_5\work\Catalina\localhost\ApacheDSXX\server-work\schema is >> valid, >> >> =A0=A0 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 embeddi= ng the server in a container and containers have a different classloading m= echanism which prevents generating the schema files. > However if you followed my earlier mails it can be easily circumvented by= setting the =A0property -Dschema.resource.location > > >> 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.=A0 I've tried >> every place, early in the >> >> code, late in the code, before startup(), pretty much in each place I >> could add it. =A0For each I >> >> re-check server startup.=A0 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 ser= ver. >> >> ... >> >> root cause >> >> ... >> >> org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupporte= dException: >> 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 ser= ver. >> >> >> >> 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 ar= e doing it (shown in the other mail), but I suspect that you are not initia= lizing that custom authenticator properly hence the issue, here I am attach= ing a modified StartStopListener code. > > note that it also supports an additional property 'ads-data-dir' to speci= fy the working directory > > HTH > > P.S:- appreciate your patience, and sorry if it took long time to solve t= his. been held up with other > =A0 =A0 =A0 =A0 issues > > Kiran Ayyagari > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D pasting the code here (in case= if attachment gets stripped ) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > /* > =A0* =A0Licensed to the Apache Software Foundation (ASF) under one > =A0* =A0or more contributor license agreements. =A0See the NOTICE file > =A0* =A0distributed with this work for additional information > =A0* =A0regarding copyright ownership. =A0The ASF licenses this file > =A0* =A0to you under the Apache License, Version 2.0 (the > =A0* =A0"License"); you may not use this file except in compliance > =A0* =A0with the License. =A0You may obtain a copy of the License at > =A0* > =A0* =A0 =A0http://www.apache.org/licenses/LICENSE-2.0 > =A0* > =A0* =A0Unless required by applicable law or agreed to in writing, > =A0* =A0software distributed under the License is distributed on an > =A0* =A0"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > =A0* =A0KIND, either express or implied. =A0See the License for the > =A0* =A0specific language governing permissions and limitations > =A0* =A0under the License. > =A0* > =A0*/ > 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.BindOperation= Context; > 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.SchemaLdifE= xtractor; > import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.Defaul= tSchemaLdifExtractor; > import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoad= er; > import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchema= Manager; > import org.apache.directory.shared.ldap.schema.registries.SchemaLoader; > > > /** > =A0* A Servlet context listener to start and stop ApacheDS. > =A0* > =A0* @author Apache Directory > =A0* =A0 =A0 =A0 =A0 Project > =A0*/ > public class StartStopListener implements ServletContextListener { > > =A0 =A0private DirectoryService directoryService; > > =A0 =A0private LdapServer ldapServer; > > > =A0 =A0/** > =A0 =A0 * Startup ApacheDS embedded. > =A0 =A0 */ > =A0 =A0public void contextInitialized( ServletContextEvent evt ) > =A0 =A0{ > =A0 =A0 =A0 =A0try > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0ServletContext servletContext =3D evt.getServletCo= ntext(); > > =A0 =A0 =A0 =A0 =A0 =A0directoryService =3D new DefaultDirectoryService()= ; > =A0 =A0 =A0 =A0 =A0 =A0directoryService.setShutdownHookEnabled( true ); > > =A0 =A0 =A0 =A0 =A0 =A0ldapServer =3D new LdapServer(); > =A0 =A0 =A0 =A0 =A0 =A0ldapServer.setDirectoryService( directoryService )= ; > =A0 =A0 =A0 =A0 =A0 =A0ldapServer.setAllowAnonymousAccess( true ); > > =A0 =A0 =A0 =A0 =A0 =A0// Set LDAP port to 10389 > =A0 =A0 =A0 =A0 =A0 =A0TcpTransport ldapTransport =3D new TcpTransport( 1= 0389 ); > =A0 =A0 =A0 =A0 =A0 =A0ldapServer.setTransports( ldapTransport ); > > =A0 =A0 =A0 =A0 =A0 =A0directoryService.setWorkingDirectory( getWorkingDi= r( servletContext ) ); > > =A0 =A0 =A0 =A0 =A0 =A0initSchema(); > =A0 =A0 =A0 =A0 =A0 =A0initSystemPartition(); > > =A0 =A0 =A0 =A0 =A0 =A0AuthenticationInterceptor authInterceptor =3D ( Au= thenticationInterceptor ) directoryService > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.getInterceptor( AuthenticationInterceptor= .class.getName() ); > =A0 =A0 =A0 =A0 =A0 =A0Set authenticators =3D authIntercep= tor.getAuthenticators(); > =A0 =A0 =A0 =A0 =A0 =A0if ( authenticators =3D=3D null ) > =A0 =A0 =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0authenticators =3D new HashSet(); > =A0 =A0 =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0 =A0 =A0// add your authenticator > =A0 =A0 =A0 =A0 =A0 =A0authenticators.add( new MyAuthenticator() ); > > =A0 =A0 =A0 =A0 =A0 =A0authInterceptor.setAuthenticators( authenticators = ); > > =A0 =A0 =A0 =A0 =A0 =A0directoryService.startup(); > =A0 =A0 =A0 =A0 =A0 =A0ldapServer.start(); > > =A0 =A0 =A0 =A0 =A0 =A0// Store directoryService in context to provide it= to servlets etc. > =A0 =A0 =A0 =A0 =A0 =A0servletContext.setAttribute( DirectoryService.JNDI= _KEY, directoryService ); > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0catch ( Exception e ) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException( e ); > =A0 =A0 =A0 =A0} > =A0 =A0} > > > =A0 =A0/** > =A0 =A0 * Shutdown ApacheDS embedded. > =A0 =A0 */ > =A0 =A0public void contextDestroyed( ServletContextEvent evt ) > =A0 =A0{ > =A0 =A0 =A0 =A0try > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0ldapServer.stop(); > =A0 =A0 =A0 =A0 =A0 =A0directoryService.shutdown(); > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0catch ( Exception e ) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException( e ); > =A0 =A0 =A0 =A0} > =A0 =A0} > > > =A0 =A0/** > =A0 =A0 * Inits the schema and schema partition. > =A0 =A0 */ > =A0 =A0private void initSchema() throws Exception > =A0 =A0{ > =A0 =A0 =A0 =A0SchemaPartition schemaPartition =3D directoryService.getSc= hemaService().getSchemaPartition(); > > =A0 =A0 =A0 =A0// Init the LdifPartition > =A0 =A0 =A0 =A0LdifPartition ldifPartition =3D new LdifPartition(); > =A0 =A0 =A0 =A0String workingDirectory =3D > directoryService.getWorkingDirectory().getPath(); > =A0 =A0 =A0 =A0ldifPartition.setWorkingDirectory( workingDirectory + "/sc= hema" ); > > =A0 =A0 =A0 =A0// Extract the schema on disk (a brand new one) and load t= he registries > =A0 =A0 =A0 =A0File serverWorkDirectory =3D new File( workingDirectory ); > =A0 =A0 =A0 =A0File schemaRepository =3D new File( serverWorkDirectory, "= schema" ); > =A0 =A0 =A0 =A0SchemaLdifExtractor extractor =3D new DefaultSchemaLdifExt= ractor( serverWorkDirectory ); > =A0 =A0 =A0 =A0if ( !schemaRepository.exists() ) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0// extract only if the schema directory is not pre= sent > =A0 =A0 =A0 =A0 =A0 =A0extractor.extractOrCopy(); > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0else > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0System.out.println( "schema partition directory ex= ists, skipping schema extraction" ); > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0schemaPartition.setWrappedPartition( ldifPartition ); > > =A0 =A0 =A0 =A0SchemaLoader loader =3D new LdifSchemaLoader( schemaReposi= tory ); > =A0 =A0 =A0 =A0SchemaManager schemaManager =3D new DefaultSchemaManager( = loader ); > =A0 =A0 =A0 =A0directoryService.setSchemaManager( schemaManager ); > > =A0 =A0 =A0 =A0// We have to load the schema now, otherwise we won't be a= ble > =A0 =A0 =A0 =A0// to initialize the Partitions, as we won't be able to pa= rse > =A0 =A0 =A0 =A0// and normalize their suffix DN > =A0 =A0 =A0 =A0schemaManager.loadAllEnabled(); > > =A0 =A0 =A0 =A0schemaPartition.setSchemaManager( schemaManager ); > > =A0 =A0 =A0 =A0List errors =3D schemaManager.getErrors(); > > =A0 =A0 =A0 =A0if ( errors.size() !=3D 0 ) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0System.out.println( errors ); > =A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException( "there were errors whi= le loading schema" ); > =A0 =A0 =A0 =A0} > =A0 =A0} > > > =A0 =A0/** > =A0 =A0 * Inits the system partition. > =A0 =A0 * > =A0 =A0 * @throws Exception the exception > =A0 =A0 */ > =A0 =A0private void initSystemPartition() throws Exception > =A0 =A0{ > =A0 =A0 =A0 =A0// change the working directory to something that is uniqu= e > =A0 =A0 =A0 =A0// on the system and somewhere either under target directo= ry > =A0 =A0 =A0 =A0// or somewhere in a temp area of the machine. > =A0 =A0 =A0 =A0JdbmPartitionFactory partitionFactory =3D new JdbmPartitio= nFactory(); > > =A0 =A0 =A0 =A0// Inject the System Partition > =A0 =A0 =A0 =A0Partition systemPartition =3D partitionFactory.createParti= tion( "system", ServerDNConstants.SYSTEM_DN, 500, > =A0 =A0 =A0 =A0 =A0 =A0new File( directoryService.getWorkingDirectory(), = "system" ) ); > =A0 =A0 =A0 =A0systemPartition.setSchemaManager( directoryService.getSche= maManager() ); > > =A0 =A0 =A0 =A0partitionFactory.addIndex( systemPartition, SchemaConstant= s.OBJECT_CLASS_AT, 100 ); > > =A0 =A0 =A0 =A0directoryService.setSystemPartition( systemPartition ); > =A0 =A0} > > > =A0 =A0private File getWorkingDir( ServletContext servletContext ) > =A0 =A0{ > =A0 =A0 =A0 =A0File workingDir =3D null; > > =A0 =A0 =A0 =A0String workDirPath =3D System.getProperty( "ads-data-dir" = ); > > =A0 =A0 =A0 =A0if ( workDirPath =3D=3D null ) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0// Determine an appropriate working directory > =A0 =A0 =A0 =A0 =A0 =A0workingDir =3D ( File ) servletContext.getAttribut= e( "javax.servlet.context.tempdir" ); > =A0 =A0 =A0 =A0 =A0 =A0workingDir =3D new File( workingDir, "server-work"= ); > =A0 =A0 =A0 =A0 =A0 =A0System.out.println( "ads-data-dir property is not = set storing the ldap data in temporary directory " > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0+ workingDir.getAbsolutePath() ); > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0else > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0workingDir =3D new File( workDirPath ); > =A0 =A0 =A0 =A0 =A0 =A0System.out.println( "storing the ldap data in the = directory " + workingDir.getAbsolutePath() ); > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0workingDir.mkdirs(); > > =A0 =A0 =A0 =A0return workingDir; > =A0 =A0} > } > > class MyAuthenticator extends AbstractAuthenticator { > > =A0 =A0private SimpleAuthenticator wrappedAuth; > > > =A0 =A0public MyAuthenticator() > =A0 =A0{ > =A0 =A0 =A0 =A0super( AuthenticationLevel.SIMPLE ); > =A0 =A0 =A0 =A0wrappedAuth =3D new SimpleAuthenticator(); > =A0 =A0} > > > =A0 =A0@Override > =A0 =A0protected void doInit() > =A0 =A0{ > =A0 =A0 =A0 =A0try > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0wrappedAuth.init( getDirectoryService() ); > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0catch ( Exception e ) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException( e ); > =A0 =A0 =A0 =A0} > =A0 =A0} > > > =A0 =A0public LdapPrincipal authenticate( BindOperationContext bindContex= t ) throws Exception > =A0 =A0{ > =A0 =A0 =A0 =A0System.out.println( "++++++++++ authenticating using a cus= tome authenticator '" > =A0 =A0 =A0 =A0 =A0 =A0+ MyAuthenticator.class.getName() + "'" ); > =A0 =A0 =A0 =A0return wrappedAuth.authenticate( bindContext ); > =A0 =A0} > > } >