2016-11-22 90 views
0

我正在使用Spring引導和開發REST服務並希望與LDAP身份驗證安全機制集成。使用Spring Boot進行LDAP驗證1.4.1

我GOOGLE了很多,但沒有得到具體的解決方案。我正在尋找一個完整的例子。

此外,我正在使用POSTMAN客戶端,並想知道如何使用它來測試LDAP身份驗證。

在此先感謝.. !!

+0

你應該看看Spring LDAP:https://spring.io/guides/gs/authenticating-ldap/ –

+0

喜丹尼爾,感謝烏爾response..Actually我做到了,但在這裏它的使用ldif文件代替實際的LDAP,所以堅持在那一點.. –

+0

@丹尼爾Olszewski 你能請給我提供一個工作的例子丹尼爾 –

回答

0

下面是使用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")); 


     } 
    } 
} 
+0

嗨arseniyandru,感謝您的迴應..我已經添加了上述類,但重新啓動服務器後,它沒有檢測到這一點安全類。我的意思是,我沒有看到任何東西在我的日誌... –

+0

發送ü更多信息,清晰.. 簡單的控制器 RequestMapping(值=「/平」,方法= RequestMethod.GET) \t ResponseBody \t公共字符串testPing(RequestParam (「param」)String param){ \t \t return param; \t} RequestMapping(值= { 「/測試」},方法= RequestMethod.GET) \t公共ResponseBody字符串檢索(){ \t返回 「你好」; } 我想驗證用戶對LDAP訪問「ping」服務。 通常我們使用像 Hashtable environment = new Hashtable (); –

+0

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,「simple」); environment.put(Context.SECURITY_PRINCIPAL,principal); environment.put(Context.SECURITY_CREDENTIALS,password); environment.put(Context.REFERRAL,「ignore」); 我如何使用Spring啓動來驗證用戶訪問我的「ping」服務。 –

相關問題