我正在尝试使用以下方法来升级Spring嵌入式Ldap服务器:
但我继续得到这个例外:
2010-06-10 14:33:35,559 ERROR main ApacheDSContainer start - Server startup Failed
java.lang.NullPointerException
at org.apache.directory.server.core.schema.DefaultSchemaService.initialize(DefaultSchemaService.java:382)
at org.apache.directory.server.core.DefaultDirectoryService.initialize(DefaultDirectoryService.java:1425)
at org.apache.directory.server.core.DefaultDirectoryService.startup(DefaultDirectoryService.java:907)
at org.springframework.security.ldap.server.ApacheDSContainer.start(ApacheDSContainer.java:160)
at org.springframework.security.ldap.server.ApacheDSContainer.afterPropertiesSet(ApacheDSContainer.java:113)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.invokeInitMethods(AbstractAutowireCapablebeanfactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.initializeBean(AbstractAutowireCapablebeanfactory.java:1409)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:456)
at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:288)
at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:190)
at org.springframework.beans.factory.support.DefaultListablebeanfactory.preInstantiateSingletons(DefaultListablebeanfactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishbeanfactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4212)
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.deployDescriptor(HostConfig.java:626)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
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:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
我正在使用spring 3.0.2并为ldap添加了以下jar:
弹簧安全LDAP的3.0.2.RELEASE.jar
弹簧LDAP的1.3.0.RELEASE-all.jar在
ApacheDS中,全1.5.6.jar
共享LDAP的0.9.15.jar
SLF4J-API-1.5.6.jar
SLF4J-简单1.5.6.jar
请帮忙….
最佳答案
@Zorkus:我不确定您在Apache Directory中遇到了什么样的问题,以及它的根本原因是什么,但如果您只需要一个有效的嵌入式Java LDAP服务器来进行Spring Security的集成测试,那么您可能会想考虑一些替代方案.
我最近开始研究替代品,因为尽管投入了大量的时间和精力,但我无法用Apache Directory实现我想要的东西. (我基本上想将Active Directory实例的模式和用户数据库复制到嵌入式服务器中.)
我发现UnboundID LDAP SDK是一个很好的替代品.与它集成需要比弹簧上下文中的单线程更多的努力(例如< security:ldap-server />),但不多.启动LDAP服务器只需几行代码:
InMemoryDirectoryServerConfig config =
new InMemoryDirectoryServerConfig("dc=example,dc=com");
// schema config only necessary if the standard
// schema provided by the library doesn't suit your needs
config.setSchema(Schema.getSchema("your-custom-schema.schema"));
// listener config only necessary if you want to make sure that the
// server listens on port 33389,otherwise a free random port will
// be picked at runtime - which might be even better for tests btw.
config.setListenerConfigs(
new InMemoryListenerConfig("myListener",null,33389,null));
InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
ds.startListening();
// import your test data from ldif files
ds.importFromLDIF(true,"content.ldif");
您需要的唯一依赖是:
将上面的代码包装在一个可以从Spring上下文中实例化和配置的类中非常容易.
有关UnboundID LDAP SDK的文档和代码示例,请参阅:https://www.unboundid.com/products/ldap-sdk/docs/
(我不以任何方式与UnboundID有关联.)