2014-11-03 86 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

相關問題