Spring Boot 的 LDAPS 实现

问题描述

我目前正在通过 LDAPS 将 Active Directory 身份验证实施到 Spring Boot 应用程序中。 这意味着 AD Server 使用 SSL,现在似乎 Spring Boot 不提供对此的支持。 关于如何解决这个问题的任何想法?解决方案也将不胜感激。

直到现在我尝试过:

  • 将 CONTEXT.Security_PROTOCOL 设置为 SSL(没有帮助)
  • 实施临时证书库(没有帮助)
  • 哭着睡觉(没用)

这是我的 WebSecurityConfig 类:

package redacted.for.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider;

import javax.naming.Context;
import java.util.Hashtable;

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest().fullyAuthenticated()
                .and()
                .formLogin();
    }

    @Bean
    public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
        Hashtable<String,Object> env = new Hashtable<>();
        env.put(Context.Security_PROTOCOL,"ssl");
        ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider = new
                ActiveDirectoryLdapAuthenticationProvider("redacted.for.security","ldaps://redacted.for.security:636/");
        return activeDirectoryLdapAuthenticationProvider;
    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)