2016-05-16 154 views
0

我试图用Spring Security 4和Java配置实现LDAP认证。 这是什么XML在Java中配置的相当于:使用Java配置进行LDAP认证

<ldap-authentication-provider> 
     <password-compare hash="{ssha}"/> 
    </ldap-authentication-provider> 

回答

1
@Configuration 
@EnableWebSecurity 
public class PasswordCompareLdapConfig extends WebSecurityConfigurerAdapter { 
    protected void registerAuthentication(
      AuthenticationManagerBuilder auth) throws Exception { 
     auth 
      .ldapAuthentication() 
       .passwordCompare() 
        .passwordEncoder(new BaseDigestPasswordEncoder()) 
        .passwordAttribute("userPassword"); 
    } 
} 
+0

“无法实例类型BaseDigestPasswordEncoder” – esonat

+0

我认为这是新的ShaPasswordEncoder()和必须设置setEncodeHashAsBase64(真)为ShaPasswordEncoder.I”我会检查它是否有效。 – esonat

+0

你可能是对的。我只是贴了一个示例注释配置..随意更新它适用于你的答案 – Shibashis