【问题标题】:Connecting to existing AD via Spring LDAP and Spring security通过 Spring LDAP 和 Spring security 连接到现有 AD
【发布时间】:2017-10-10 14:36:58
【问题描述】:

我正在尝试使用 Spring Security 通过 Spring LDAP (2.3.1.RELEASE) 将自己登录到现有的 AD。到目前为止,我有以下负责配置的代码(几乎取自Spring getting started guide):

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
        .antMatchers("/", "/home").permitAll()
        .anyRequest().fullyAuthenticated()
        .and()
        .formLogin()
        .loginPage("/login")
        .permitAll()
        .and()
        .logout()
        .permitAll();
}

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
    authauth
        .ldapAuthentication()
        .userDnPatterns("uid={0}")
        .contextSource(contextSource())
        .passwordCompare()
        .passwordEncoder(new LdapShaPasswordEncoder())
        .passwordAttribute("userPassword");
}


@Bean
public BaseLdapPathContextSource contextSource() {
    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setAnonymousReadOnly(false);
    contextSource.setBase("dc=foo,dc=bar");
    contextSource.setUserDn("j.doe@company.com");
    contextSource.setPassword("plainTextPassword");
    contextSource.setUrl("ldap://active.directory.address");
    return ldapContextSource;
 }
}

这是我的 pom sn-p:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
    </dependency>
    <dependency>
        <groupId>com.unboundid</groupId>
        <artifactId>unboundid-ldapsdk</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.directory.server</groupId>
        <artifactId>apacheds-all</artifactId>
        <version>1.5.5</version>
    </dependency>
</dependencies>

<properties>
    <java.version>1.8</java.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我故意省略了 .html 文件,因为我认为它们在这个问题中没有任何作用。 自动取款机

javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903D9, comment: AcceptSecurityContext error, data 52e, v2580 ]

结果。在谷歌搜索异常后,我发现数据 52e 表示AD_INVALID CREDENTIALS。我多次检查我的凭据,它们确实非常正确。我什至下载了 Microsoft 的 AD 资源管理器并使用这些凭据成功连接到 AD。为什么它不能通过代码运行,而是通过 AD 资源管理器运行?

【问题讨论】:

    标签: java maven spring-security ldap spring-ldap


    【解决方案1】:

    这个错误是什么时候发生的?在应用程序启动或尝试登录时? 如果我在上下文源中输入无效凭据,我会收到此错误。如果你确定你的密码是正确的,你应该检查你的 base 和 userDN。

    您能否发布您在上下文源中使用的 LDAP 树或列出用户的 LDIF 部分?

    【讨论】:

      猜你喜欢
      • 2015-01-18
      • 2018-11-03
      • 2018-04-15
      • 2016-04-13
      • 2015-10-12
      • 1970-01-01
      • 2019-12-04
      • 2013-06-03
      • 2020-07-18
      相关资源
      最近更新 更多