问题描述
大家。我正在尝试编写一个与 Active Directory 服务器一起使用的 Spring Boot 程序(用于修改,而不是身份验证),但我无法让程序连接到它。无论我做什么,它都会显示以下消息:
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
中的 mydomainLdapTemplate 定义了一个 bean
<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>
我尝试在 userdn 和 username 之间切换(在 src\main\resources\ldap.properties
中),但都不起作用。
ldap.authentication.manager.userdn=cn=myacct,dc=mydomain,dc=sunyjcc,dc=edu
[email protected]
我也尝试过在 bean 配置中在 username 和 userDn 之间切换,但似乎没有任何效果。谁能告诉我我做错了什么?
ActiveDirectoryLdapAuthenticationProvider 似乎不是一个选项,因为我不是要进行身份验证,而是要修改用户记录。
谢谢!
编辑
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)