Ошибка аутентификации LDAP в Springboot 3JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Ошибка аутентификации LDAP в Springboot 3

Сообщение Anonymous »

Я пытаюсь подключиться к онлайн-LDAP с помощью Springboot 3.0.8
это мой код

Код: Выделить всё

package org.pg.ldap;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.ldap.authentication.BindAuthenticator;
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider;
import org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
public class LDAPSecurityConfig {

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(authz -> authz
.anyRequest().authenticated()
)
.formLogin().and()
.csrf().disable();
return http.build();
}

@Bean
public LdapAuthenticationProvider ldapAuthenticationProvider() {
DefaultLdapAuthoritiesPopulator authoritiesPopulator =
new DefaultLdapAuthoritiesPopulator(contextSource(), null);
authoritiesPopulator.setIgnorePartialResultException(true);
return new LdapAuthenticationProvider(bindAuthenticator(), authoritiesPopulator);
}

@Bean
public BindAuthenticator bindAuthenticator() {
BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource());
bindAuthenticator.setUserDnPatterns(new String[]{"uid={0},dc=example,dc=com"});
return bindAuthenticator;
}

@Bean
public LdapContextSource contextSource() {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://ldap.forumsys.com:389");
contextSource.setBase("dc=example,dc=com");
contextSource.setUserDn("cn=read-only-admin,dc=example,dc=com");
contextSource.setPassword("password");
return contextSource;
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}

По умолчанию при запуске кода отображается страница входа в систему, но всякий раз, когда я пытаюсь подключиться, вводя учетные данные (имя пользователя = riemann, пароль = пароль), отображается

Код: Выделить всё

Failed to bind with any user DNs [uid=riemann,dc=example,dc=com]
Информацию о LDAP можно найти здесь: https://www.forumsys.com/2022/05/10/onl ... st-server/
Но когда я нажимаю на URL-адрес с помощью этой команды

Код: Выделить всё

ldapsearch -x -H ldap://ldap.forumsys.com:389 -D "cn=read-only-admin,dc=example,dc=com" -w password -b "dc=example,dc=com" "(uid=riemann)"
Он показывает всю информацию о пользователе, сообщая мне, что LDAP работает нормально.
Что я здесь делаю не так?

Подробнее здесь: https://stackoverflow.com/questions/792 ... ringboot-3
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»