2014-11-03 87 views
4

如何设置弹性安全LDAP配置的URL? 有很多基于xml的示例,但我找不到java配置示例来复制下面的xml行。我认为它是在弹簧指南下面的java代码块中配置的,以便使用嵌入式ldap,但我们如何设置外部url?用于LDAP的Spring Security Java配置

<ldap-server id="ldapServer" url="ldap://example.com:PORT/dc=example,dc=com" /> 
@Override 
public void init(AuthenticationManagerBuilder auth) throws Exception { 
    auth.ldapAuthentication() 
      .userDnPatterns("uid={0},ou=people") 
      .groupSearchBase("ou=groups") 
      .contextSource() 
       .ldif("classpath:test-server.ldif"); 
} 

回答

9

您只需使用的LdapAuthenticationProviderConfigurer.ContextSourceBuilder

url()方法所以,你会简单的扩展您的代码如下:

@Override 
public void init(AuthenticationManagerBuilder auth) throws Exception { 
    auth.ldapAuthentication() 
      .userDnPatterns("uid={0},ou=people") 
      .groupSearchBase("ou=groups") 
      .contextSource() 
       .ldif("classpath:test-server.ldif") 
       .url("ldap://example.com:PORT/dc=example,dc=com"); 
} 
+7

给予使用.ldif()的例子是相当无用对任何人。每个教程都会回退,并不能解决任何人的问题。 – 2016-04-06 18:35:50

相关问题