差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
java:ldap:spring:simpleauthentication [2016/04/02 19:13] tony [With TLS(StartTLS)] |
java:ldap:spring:simpleauthentication [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 48: | 行 48: | ||
* 透過DefaultTlsDirContextAuthenticationStrategy讓client與server negotiate。 | * 透過DefaultTlsDirContextAuthenticationStrategy讓client與server negotiate。 | ||
* 由於會做hostname的verify,為了測試,所以我們先override去避掉它。 | * 由於會做hostname的verify,為了測試,所以我們先override去避掉它。 | ||
- | * 在TLS做authenticate時,由於僅做連線沒做search,所以透過LookupAttemptingCallback讓它強制做search,以驗證密碼是否正確。 | + | * 做authenticate時,透過LookupAttemptingCallback讓它在連線完成後做search,以驗證密碼是否正確。 |
<code java> | <code java> | ||
LdapContextSource contextSource = new LdapContextSource(); | LdapContextSource contextSource = new LdapContextSource(); | ||
行 57: | 行 57: | ||
DefaultTlsDirContextAuthenticationStrategy strategy = new DefaultTlsDirContextAuthenticationStrategy(); | DefaultTlsDirContextAuthenticationStrategy strategy = new DefaultTlsDirContextAuthenticationStrategy(); | ||
- | strategy.setHostnameVerifier(new HostnameVerifier() { | + | strategy.setHostnameVerifier((hostname, sslsession) -> { |
- | @Override | + | return true; |
- | public boolean verify(String arg0, SSLSession arg1) { | + | |
- | return true; | + | |
- | } | + | |
}); | }); | ||
+ | |||
contextSource.setAuthenticationStrategy(strategy); | contextSource.setAuthenticationStrategy(strategy); | ||
contextSource.afterPropertiesSet(); | contextSource.afterPropertiesSet(); | ||
行 76: | 行 74: | ||
} | } | ||
</code> | </code> | ||
+ | 為了確認真的是TLS,透別使用wireshark觀察一下: [[pc:goodsoftware:wireshark|link]]。 | ||
===== Reference ===== | ===== Reference ===== | ||
* [[http://www.jayway.com/2009/02/02/simple-authentication-using-spring-ldap/|simple-authentication-using-spring-ldap]] | * [[http://www.jayway.com/2009/02/02/simple-authentication-using-spring-ldap/|simple-authentication-using-spring-ldap]] | ||
- | * | + | * [[http://stackoverflow.com/questions/16570222/how-to-authenticate-against-active-directory-via-ldap-over-tls|how-to-authenticate-against-active-directory-via-ldap-over-tls]] |
===== ===== | ===== ===== |