это мой код
Код: Выделить всё
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();
}
}
Код: Выделить всё
Failed to bind with any user DNs [uid=riemann,dc=example,dc=com]Но когда я нажимаю на 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)"Что я здесь делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/792 ... ringboot-3
Мобильная версия