gpt4 book ai didi

java - Spring 无法加载 ldif

转载 作者:太空宇宙 更新时间:2023-11-04 12:02:02 25 4
gpt4 key购买 nike

我目前正在尝试使用 Spring Boot 1.4.2.RELEASE 构建一个小型 Web 应用程序。为此,我还使用加载了嵌入式 LDAP 和 ldif 的 Spring Boot LDAP。如果我开始,它总是告诉我没有设置 DN,如下所示。

如果我遗漏了某些东西,有人能够告诉我如何运行它吗?已经尝试了教程中的一些示例 ldif 文件,但总是得到相同的结果。

以下是我的配置的一些部分:- Java 8- Spring Boot 1.4.2.RELEASE- Spring注解代替xml- Gradle

构建.gradle:

... springBootVersion = '1.4.2.RELEASE'
compile ('org.springframework.boot:spring-boot-starter-web') {
exclude module: 'org.springframework.boot:spring-boot-starter-tomcat'
}
compile 'org.springframework.boot:spring-boot-starter-jetty',
'org.springframework.boot:spring-boot-starter-data-jpa',
'org.springframework.boot:spring-boot-starter-data-rest',
'org.springframework.boot:spring-boot-starter-freemarker',
'org.springframework.boot:spring-boot-starter-security',
'org.springframework.boot:spring-boot-actuator',
'org.springframework.boot:spring-boot-devtools',
'org.springframework.security:spring-security-ldap',
'org.springframework:spring-tx',
'com.h2database:h2',
'org.apache.directory.server:apacheds-server-jndi:1.5.5'
testCompile 'org.springframework.boot:spring-boot-starter-test',
'org.springframework.security:spring-security-test'
...

配置:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin();
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userSearchFilter("uid={0}")
.userSearchBase("ou=users")
.groupSearchBase("ou=groups")
.groupSearchFilter("(uniqueMember={0}")
.groupRoleAttribute("cn")
.rolePrefix("ROLE")
.contextSource().ldif("classpath:test.ldif")
.root("o=mojo");
}

...

测试.ldif:

version: 1

dn: o=mojo
objectClass: organization
objectClass: extensibleObject
objectClass: top
o: mojo

dn: ou=users,o=mojo
objectClass: extensibleObject
objectClass: organizationalUnit
objectClass: top
ou: users

dn: ou=groups,o=mojo
objectClass: extensibleObject
objectClass: organizationalUnit
objectClass: top
ou: groups

dn: cn=User,ou=groups,o=mojo
objectClass: groupOfUniqueNames
objectClass: top
cn: User
uniqueMember: cn=John Milton,ou=users,o=mojo
uniqueMember: cn=Robert Browning,ou=users,o=mojo
uniqueMember: cn=Hugo Williams,ou=users,o=mojo
uniqueMember: cn=John Keats,ou=users,o=mojo

dn: cn=Admin,ou=groups,o=mojo
objectClass: groupOfUniqueNames
objectClass: top
cn: Admin
uniqueMember: cn=Hugo Williams,ou=users,o=mojo
uniqueMember: cn=John Keats,ou=users,o=mojo

dn: cn=Robert Browning,ou=users,o=mojo
objectClass: organizationalPerson
objectClass: person
objectClass: inetOrgPerson
objectClass: top
cn: Robert Browning
sn: Browning
uid: rbrowning
userPassword:: cGFzcw==

...

错误消息:

2016-11-25 22:45:58.383  INFO 15028 --- [  restartedMain] o.s.s.ldap.server.ApacheDSContainer      : Loading LDIF file: C:\SourceCode\Zeiterfassung\src\main\resources\test.ldif
2016-11-25 22:45:58.391 WARN 15028 --- [ restartedMain] o.a.d.shared.ldap.ldif.LdifReader : No version information : assuming version: 1
2016-11-25 22:45:58.391 ERROR 15028 --- [ restartedMain] o.a.d.shared.ldap.ldif.LdifReader : A ldif entry must start with a DN
2016-11-25 22:45:58.392 ERROR 15028 --- [ restartedMain] o.a.d.s.p.shared.store.LdifFileLoader : Failed to import LDIF into backing store.

javax.naming.NamingException: No DN for entry
at org.apache.directory.shared.ldap.ldif.LdifReader.parseDn(LdifReader.java:562) ~[shared-ldap-0.9.15.jar:na]
at org.apache.directory.shared.ldap.ldif.LdifReader.parseEntry(LdifReader.java:1234) ~[shared-ldap-0.9.15.jar:na]
at org.apache.directory.shared.ldap.ldif.LdifReader.init(LdifReader.java:282) ~[shared-ldap-0.9.15.jar:na]
at org.apache.directory.shared.ldap.ldif.LdifReader.<init>(LdifReader.java:329) ~[shared-ldap-0.9.15.jar:na]
at org.apache.directory.server.protocol.shared.store.LdifFileLoader.execute(LdifFileLoader.java:181) ~[apacheds-protocol-shared-1.5.5.jar:na]
at org.springframework.security.ldap.server.ApacheDSContainer.importLdifs(ApacheDSContainer.java:280) [spring-security-ldap-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.ldap.server.ApacheDSContainer.start(ApacheDSContainer.java:216) [spring-security-ldap-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.ldap.server.ApacheDSContainer.afterPropertiesSet(ApacheDSContainer.java:134) [spring-security-ldap-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) [spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

非常感谢您的帮助

空中弹跳

最佳答案

我通过删除 application.yml 中的验证属性来修复它

之前:

spring:
ldap:
embedded:
base-dn: dc=example,dc=com
ldif: classpath:test-server.ldif
port: 12745
validation:
enabled: true

现在是:

spring:
ldap:
embedded:
base-dn: dc=example,dc=com
ldif: classpath:test-server.ldif
port: 12745

如果嵌入式 LDAP 服务器有任何日志记录,那么发现此类问题会更​​容易。

关于java - Spring 无法加载 ldif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40813006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com