apache - 使用 spring 引发嵌入式 ldap 服务器时出现 NullPointerException

标签 apache spring ldap

我正在尝试使用以下方法来启动 Spring Embedded Ldap Server:

但我不断收到此异常:

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: spring-security-ldap-3.0.2.RELEASE.jar spring-ldap-1.3.0.RELEASE-all.jar apacheds-all-1.5.6.jar 共享 ldap-0.9.15.jar slf4j-api-1.5.6.jar slf4j-simple-1.5.6.jar

请帮忙......

最佳答案

@Zorkus:我不确定您在使用 Apache Directory 时遇到了什么样的问题,以及其根本原因是什么,但如果您需要的是一个可用的嵌入式 java LDAP 服务器来与 Spring Security 进行集成测试那么您可能需要考虑一些替代方案。

我最近开始研究替代方案,因为尽管投入了大量时间和精力,但我仍无法使用 Apache Directory 实现我想要的目标。 (我基本上想将 Active Directory 实例的架构和用户数据库复制到嵌入式服务器中。)

我发现 UnboundID LDAP SDK 是一个很好的替代品。与它集成需要比 Spring 上下文中的单行代码(例如 <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, null, null));

InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);

ds.startListening();

// import your test data from ldif files
ds.importFromLDIF(true,"content.ldif");

为此工作所需的唯一依赖项是:

<dependency>
    <groupId>com.unboundid</groupId>
    <artifactId>unboundid-ldapsdk</artifactId>
    <version>2.3.1</version>
</dependency>

将上述代码包装在一个类中非常容易,您可以从 Spring 上下文实例化和配置该类。

有关 UnboundID LDAP SDK 的文档和代码示例,请参阅:https://www.unboundid.com/products/ldap-sdk/docs/

(我不以任何方式隶属于 UnboundID。)

关于apache - 使用 spring 引发嵌入式 ldap 服务器时出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3014003/

相关文章:

eclipse - Eclipse Indigo 中缺少 "Servers" View

Spring Webflow 阻止用户在流程完成后返回到流程的开头

java - JSF 2.1 Web 应用程序上的 Spring Security

ruby - 从绑定(bind)连接中检索当前经过身份验证的 LDAP 用户的用户名

c# - 在 C# 中将 LDAP AccountExpires 转换为 DateTime

java - NetBeans Tomcat 构建失败 - 模块尚未部署

apache - TIME_WAIT 连接过多

java - 使用 tomcat 的 spring webapp 的 SL4J 设置不记录?

ubuntu - Ubuntu 上的 LDAP 服务器安装问题

mysql - xampp-无法显示此页面