2016-08-12 17 views
0

Spring Securityが提供するLDAP認証を使用しようとしています。すべてがうまくコンパイルされます。アプリケーションを配備する際に次のエラーが発生します。SpringセキュリティLDAP認証がJava 8で機能しない

Caused by: java.lang.RuntimeException: Could not postProcess [email protected]efa of type class org.springframework.security.ldap.server.ApacheDSContainer 
    at org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor.postProcess(AutowireBeanFactoryObjectPostProcessor.java:70) 
    at org.springframework.security.config.annotation.SecurityConfigurerAdapter$CompositeObjectPostProcessor.postProcess(SecurityConfigurerAdapter.java:123) 
    at org.springframework.security.config.annotation.SecurityConfigurerAdapter.postProcess(SecurityConfigurerAdapter.java:82) 
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.access$400(LdapAuthenticationProviderConfigurer.java:58) 
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer$ContextSourceBuilder.build(LdapAuthenticationProviderConfigurer.java:555) 
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer$ContextSourceBuilder.access$500(LdapAuthenticationProviderConfigurer.java:446) 
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.getContextSource(LdapAuthenticationProviderConfigurer.java:606) 
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.build(LdapAuthenticationProviderConfigurer.java:76) 

スプリングコアバージョンは4.3.2です。 Spring Security LDAPバージョンは4.1.1です。

私のGoogleの調査では、Spring Security LDAPとJava 8との間に互換性がないため、この問題が2013年の記事に掲載されています。これは、非Springブートライブラリの修正については言及していません。

誰かがJava 8を使用してSpring Security LDAP認証を試みましたか?助けてください。

答えて

1

Java 8とSpring Security LDAPを使用しています。 Spring WebアプリケーションをActive Directoryインスタンスに接続し、URLによるアクセスを保護しています。

私が正しく思い出した場合、これは期待以上に時間がかかりました。

LDAPコンテキストパスの "Base"を変更する必要があります。また、ldap.userはユーザー名だけでなくLDAPの完全なCNであることに注意してください。 JXplorer(http://jxplorer.org/)のようなLDAPブラウザを使用すると、LDAP設定を正しく取得できます。

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.beans.factory.annotation.Value; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.context.annotation.Profile; 
import org.springframework.ldap.core.support.BaseLdapPathContextSource; 
import org.springframework.ldap.core.support.LdapContextSource; 
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 
import org.springframework.security.config.annotation.web.builders.HttpSecurity; 
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    private static final Logger LOGGER = LoggerFactory.getLogger(SecurityConfig.class); 

    @Value("ldap://${ldap.host}:${ldap.port:389}") 
    private String url; 

    @Value("${ldap.user}") 
    private String user; 

    @Value("${ldap.password}") 
    private String password; 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     LOGGER.info("Configuring security..."); 
     http.authorizeRequests() 
       .antMatchers("/").permitAll() 
       .antMatchers("/index.html").permitAll() 
       .anyRequest().fullyAuthenticated() 
       .and() 
       .httpBasic(); 
    } 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
     auth.ldapAuthentication() 
      .userSearchFilter("(&(objectClass=user)(sAMAccountName={0}))") 
      .contextSource(ldapContextSource()); 
    } 

    @Bean 
    public BaseLdapPathContextSource ldapContextSource() { 
     LOGGER.info("LDAP: {}", url); 
     LdapContextSource bean = new LdapContextSource(); 
     bean.setUrl(url); 
     bean.setBase("DC=CORP,DC=MyCompany,DC=com"); 
     bean.setUserDn(user); 
     bean.setPassword(password); 
     bean.setPooled(true); 
     bean.setReferral("follow"); 
     return bean; 
    } 
} 

これは、あなたの答えをずっとこの

ldap.host=ldap.mycompany.com 
ldap.user=CN=MyUser,OU=Service Accounts,OU=New-York,DC=CORP,DC=MyCompany,DC=com 
# Encrypt using Jasypt or something 
ldap.password=B1gS3cr3t 
+0

おかげのようになりますコンフィギュレーションファイルにLDAP設定を前提としています。私の場合、つまりクラスパス上のLDIFファイルを使用してApacheDS LDAPサーバーを組み込んだ場合、アプリケーションが失敗する原因になるのでしょうか? –

関連する問題