首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring和Spring配置

Spring和Spring配置
EN

Stack Overflow用户
提问于 2017-05-20 09:44:43
回答 1查看 7.2K关注 0票数 3

我有教育问题:

有带有用户及其密码的windows server 2003 (AD)虚拟机。建立到机器的连接(ip:192.168.56.101:389)。

web应用程序的目的是使用户能够在AD中更改密码。

问题:无法配置到windws服务器2003的连接。

我从本教程https://spring.io/guides/gs/authenticating-ldap/开始

当我试图以“杰克·伍德”的身份登录并通过"1234“时,我得到了错误。

代码语言:javascript
运行
复制
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'

application.properties**.** 请检查

代码语言:javascript
运行
复制
#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

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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!";
    }
}

应用程序

代码语言:javascript
运行
复制
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);
    }

}

EN

回答 1

Stack Overflow用户

发布于 2018-11-19 00:14:01

试着改变

代码语言:javascript
运行
复制
spring.ldap.username=cn=Jack Wood,cn=Users,dc=GRSU,dc=local

代码语言:javascript
运行
复制
spring.ldap.username=cn=Jack Wood,cn=Users

这有用吗?

我的理解是,用户名使用相对域名(rdn),而不是绝对域名(dn)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44084343

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档