【问题标题】:LDAP authentication with Spring Boot 1.4.1使用 Spring Boot 1.4.1 进行 LDAP 身份验证
【发布时间】:2016-11-23 00:02:37
【问题描述】:

我正在使用 Spring boot 并开发 REST 服务,并希望与 LDAP 身份验证安全机制集成。

我搜索了很多,但没有得到具体的解决方案。我正在寻找一个完整的例子。

我也在使用 POSTMAN 客户端,想知道如何使用它来测试 LDAP 身份验证。

提前谢谢..!!

【问题讨论】:

  • 你应该看看 Spring LDAP:spring.io/guides/gs/authenticating-ldap
  • 嗨,丹尼尔,感谢您的回复..实际上我做到了,但这里使用的是 ldif 文件而不是实际的 LDAP,所以卡在了这一点上..
  • @Daniel Olszewski 你能不能给我一个工作的例子丹尼尔

标签: spring-boot ldap


【解决方案1】:

这里是一个使用ActiveDirectoryLdapAuthenticationProvider的例子

这实际上非常简单。谢谢你,引导。

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

   @Override
   protected void configure(HttpSecurity http) throws Exception {
       http
               .authorizeRequests()
               .antMatchers("/yourstuff/**").permitAll()
               .antMatchers("/your/protectedstuff/**").authenticated()
               .and()
               .httpBasic()
               .permitAll();
   }

   @Configuration
   protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {

       @Override
       public void init(AuthenticationManagerBuilder auth) throws Exception {
               auth.authenticationProvider(new ActiveDirectoryLdapAuthenticationProvider("DOMAINNAME","LDAP SERVER URI"));


       }
   }
}

【讨论】:

  • 嗨,arseniyadru,感谢您的回复..我已经添加了上述类,但在重新启动服务器后它没有检测到这个安全类。我的意思是,我的日志中没有看到任何内容..
  • 为清楚起见向您发送更多信息.. 简单控制器 RequestMapping(value = "/ping", method = RequestMethod.GET) ResponseBody public String testPing(RequestParam("param") String param) { return param ; } RequestMapping(value = { "/test" }, method = RequestMethod.GET) public ResponseBody String retrieve() { return "hello";我想针对 LDAP 对用户进行身份验证以访问“ping”服务。通常我们使用like Hashtable environment = new Hashtable();
  • String ldapUrl = ""; String principal = "uid=" + username + ",OU=" + ou + ",O=cco.org.com"; environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); environment.put(Context.PROVIDER_URL, ldapUrl); environment.put(Context.SECURITY_AUTHENTICATION, "简单"); environment.put(Context.SECURITY_PRINCIPAL, principal); environment.put(Context.SECURITY_CREDENTIALS, 密码); environment.put(Context.REFERRAL, "忽略");我如何使用 Spring Boot 对用户进行身份验证以访问我的“ping”服务。
  • 你能帮我吗??
  • 你能给我提供一个工作示例 arseniyadru 吗??
猜你喜欢
  • 2015-11-22
  • 2017-04-12
  • 2020-07-06
  • 2020-08-07
  • 2022-01-20
  • 2018-08-09
  • 2021-09-02
  • 1970-01-01
  • 2012-11-18
相关资源
最近更新 更多