I have educational problem:
There are virtual machine with windows server 2003 (AD) with users and their passwords. Connection to the machine is established (ip:192.168.56.101:389).
The purpose of the web application is to enable the user to change his password in AD.
Problem: can't configure connection to windws server 2003.
I started from this tutorial https://spring.io/guides/gs/authenticating-ldap/
When I try to log in as "Jack Wood" and pass "1234" I got error.
org.springframework.security.authentication.InternalAuthenticationServiceException:
Uncategorized exception occured during LDAP processing;
nested exception is javax.naming.NamingException:
[LDAP: error code 1 - 00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece ]; remaining name 'cn=Jack Wood,cn=Users'
Please check application.properties
.
#spring.ldap.embedded.ldif=classpath:test-server.ldif
#spring.ldap.embedded.base-dn=dc=springframework,dc=org
#spring.ldap.embedded.port=8389
spring.ldap.base=dc=GRSU,dc=local
spring.ldap.urls=192.168.56.101:389
spring.ldap.username=cn=Jack Wood,cn=Users,dc=GRSU,dc=local
spring.ldap.password=1234
WebSecurityConfig
package hello;
import java.util.Arrays;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.encoding.LdapShaPasswordEncoder;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("cn={0},cn=Users")
.groupSearchBase("ou=groups")
.contextSource(contextSource())
.passwordCompare()
.passwordEncoder(new LdapShaPasswordEncoder())
.passwordAttribute("userPassword");
}
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource("ldap://192.168.56.101:389/");
}
}
HomeController
package hello;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HomeController {
@GetMapping("/")
public String index() {
return "Welcome to the home page!";
}
}
Application
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Try changing
spring.ldap.username=cn=Jack Wood,cn=Users,dc=GRSU,dc=local
to
spring.ldap.username=cn=Jack Wood,cn=Users
Does that help?
My understanding is that the username uses the relative domain name (rdn) as opposed to the absolute domain name (dn).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.