Spring boot 无法在Spring启动应用程序中使用“连接到Active Directory”';用户DN';“未设置”;消息
各位。我正在尝试编写一个与Active Directory服务器一起工作的Spring引导程序(用于修改,而不是身份验证),但我无法让程序连接到它。无论我做什么,它都会显示以下信息:Spring boot 无法在Spring启动应用程序中使用“连接到Active Directory”';用户DN';“未设置”;消息,spring-boot,active-directory,spring-ldap,Spring Boot,Active Directory,Spring Ldap,各位。我正在尝试编写一个与Active Directory服务器一起工作的Spring引导程序(用于修改,而不是身份验证),但我无法让程序连接到它。无论我做什么,它都会显示以下信息: o.s.l.c.support.AbstractContextSource : Property 'userDn' not set - anonymous context will be used for read-write operations 这是错误的,因为AD服务器不接受匿名连接 这是我完整的bu
o.s.l.c.support.AbstractContextSource : Property 'userDn' not set - anonymous context will be used for read-write operations
这是错误的,因为AD服务器不接受匿名连接
这是我完整的build.gradle文件
plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'groovy'
}
group = 'edu.sunyjcc.gateway'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.codehaus.groovy:groovy'
implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
我在src\main\resources\applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/ldap
https://www.springframework.org/schema/ldap/spring-ldap.xsd"
>
<context:property-placeholder location="classpath:ldap.properties"/>
<!-- <ldap:context-source id="mydomainContextSource" -->
<!-- userDn="${ldap.authentication.manager.userdn}" -->
<!-- username="${ldap.authentication.manager.username}" -->
<!-- password="${ldap.authentication.manager.password}" -->
<!-- url="${ldap.authentication.server.urls}" -->
<!-- base="${ldap.authentication.basedn}" /> -->
<bean id="mydomainContextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="pooled" value="false"/>
<property name="urls">
<bean class="org.springframework.util.StringUtils" factory-method="commaDelimitedListToSet">
<constructor-arg type="java.lang.String" value="${ldap.authentication.server.urls}"/>
</bean>
</property>
<property name="userDn" value="${ldap.authentication.manager.userdn}"/>
<!-- <property name="username" value="${ldap.authentication.manager.userdn}"/> -->
<!-- <property name="username" value="${ldap.authentication.manager.username}"/> -->
<property name="password" value="${ldap.authentication.manager.password}"/>
<property name="baseEnvironmentProperties">
<map>
<entry key="com.sun.jndi.ldap.connect.timeout" value="${ldap.authentication.jndi.connect.timeout}" />
<entry key="com.sun.jndi.ldap.read.timeout" value="${ldap.authentication.jndi.read.timeout}" />
<entry key="java.naming.security.authentication" value="${ldap.authentication.jndi.security.level}" />
</map>
</property>
</bean>
<ldap:ldap-template id="mydomainLdapTemplate"
ignore-partial-result="true"
context-source-ref="mydomainContextSource"/>
</beans>
我还尝试在bean配置中在username和userDn之间切换,但似乎没有任何效果。谁能告诉我我做错了什么
ActiveDirectoryLdapAuthenticationProvider似乎不是一个选项,因为我不尝试进行身份验证,而是修改用户记录
谢谢
Ed.嗯,有时候提出正确的问题比得到正确的答案更重要。事实证明,SpringBoot不会自动检测XML配置,您必须手动检测。通过将@ImportResource注释添加到主类中,这很容易做到。您可以更改此选项:
@SpringBootApplication
public class GatewayLdapApplication implements CommandLineRunner {
对这个
@SpringBootApplication
@ImportResource(["classpath*:applicationContext.xml"])
public class GatewayLdapApplication implements CommandLineRunner {
现在它连接得很好
埃德
@SpringBootApplication
@ImportResource(["classpath*:applicationContext.xml"])
public class GatewayLdapApplication implements CommandLineRunner {