跳到主要內容

發表文章

目前顯示的是有「AD」標籤的文章

Support SAM-Account-Name of AD Provider

Introduction Windows Active Directory提供User Principle Name(簡稱UPN)與SAM Account Name(簡稱SAM)兩種登入方式: 然而ActiveDirectoryLdapAuthenticationProvider僅支援UPN的驗證方式。因此本篇文章主要告訴大家如何支援SAM驗證方式。 How to? ActiveDirectoryLdapAuthenticationProvider驗證UPN的方式,是透過使用者輸入的帳號密碼,並藉由JNDI去做搜尋。而搜尋過濾的條件為: ( & ( objectClass = user ) ( userPrincipalName = { 0 } ) ) 所以我們也許可以透過JNDI並搭配搜尋過濾條件去驗證SAM;在開始修改Provider前,我要先確認JNDI是否有辦法支援SAM。我撰寫以下程式碼做確認: Domain: TEST.COM SAM: TEST\test filter: (&(objectClass=user)(samaccountname=test)) LdapContextSource contextSource = new DefaultSpringSecurityContextSource ( "ldap://10.134.15.138:389" ) ; contextSource. setBase ( "DC=TEST,DC=COM" ) ; //contextSource.setUserDn("test@TEST.COM"); contextSource. setUserDn ( "TEST \\ test" ) ; contextSource. setPassword ( "123456" ) ; contextSource. afterPropertiesSet ( ) ;   LdapTemplate ldapTemplate = new LdapTemplate ( contextSource ) ; ldapTemplate. afterPropertiesSet ( ) ;   Search...

Spring-Security with LDAP物件關係

Introduction 本篇主要記載Spring-Security-LDAP中,我們有使用到的物件去做說明。我們目的是整合LDAP與AD驗證,其中為了滿足我們的需求,有對不少Spring所提供的物件做擴充。這部分有機會再另外分享。 Configuration With Code 以我的範例來說,首先會透過資料庫做登入認證,接著會是AD,最後是LDAP。而透過程式碼配置的方式,會去extend WebSecurityConfigurerAdapter;接著override configure的method,AuthenticationManagerBuilder可以讓你配置AuthenticationProvider: @Autowired @Qualifier ( "dataSource" ) DataSource datasource ;   @Autowired @Qualifier ( "ldapConfig" ) Properties ldapConfig ;   @Autowired @Qualifier ( "adConfig" ) Properties adConfig ;   @Override protected void configure ( AuthenticationManagerBuilder aAuth ) throws Exception { aAuth. jdbcAuthentication ( ) . dataSource ( datasource ) ;   String domain = ( String ) adConfig. get ( "ad.domain" ) ; String url = ( String ) adConfig. get ( "ad.url" ) ; ActiveDirectoryLdapAuthenticationProvider adProvider = new ActiveDirectoryLdapAuthenticationProvider ( domain, url ) ; aAuth. authenticationProvid...

AD/LDAP with Spring API

Articles Simple Authentication   SSL and StartTLS Spring-Security with LDAP物件關係 ActiveDirectoryLdapAuthenticationProvider Support SAM-Account-Name Support TLS LdapAuthenticationProvider 如何透過LDAP做認證? Support Secure connection Support StartTLS with anonymous login Search AD User and Groups LdapContextSource contextSource = new DefaultSpringSecurityContextSource ( "ldap://10.134.15.138:389" ) ; contextSource. setBase ( "DC=TEST,DC=SSM" ) ; contextSource. setUserDn ( "test@TEST.SSM" ) ; contextSource. setPassword ( "123456" ) ; DirContextAuthenticationStrategy strategy = createTLSStrategy ( ) ; contextSource. setAuthenticationStrategy ( strategy ) ; contextSource. afterPropertiesSet ( ) ;   LdapTemplate ldapTemplate = new LdapTemplate ( contextSource ) ; ldapTemplate. afterPropertiesSet ( ) ;   SearchControls sc = new SearchControls ( ) ; sc. setSearchScope ( SearchControls . SUBTREE_SCOPE ) ;   ldapTemplate. search ( ...

LDAP & AD相關文章

LDAP & AD都算是老東西了,會開始寫些教學是因為遇到與它的整合。內容隨著我的學習會慢慢增加,如果我有空寫的話~XD。 LDAP + RestAPI + Digest Auth? 目前遇到的問題是: LDAP使用者是否可以透過RestAPI進行Digest Auth? 我認為有困難。 由於認證行為是交給LDAP Server,RestAPI Web層只負責forwarding;而Digest Auth中的密碼會被根據Http Request種類、密碼等等內容一起MD5 encoding過。如果無法取得明文,除非LDAP Server允許接受一樣的方式。 SunCertPathBuilderException Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 參考 此篇 教學,執行以下command將root ca給匯入到Java keystore中,changeit是預設密碼,如果要用記得要改: keytool -importcert -trustcacerts -keystore / opt / jdk1.8.0_60 / jre / lib / security / cacerts -storepass changeit -noprompt -alias tonytest -file / etc / ldap / ssl / rootca.crt Certificate was added to keystore 列出現有的ca: keytool -list -keystore / opt / jdk1.8.0_60 / jre / lib / security / cacerts -storepass changeit 查看看測試的ca: . / keytool -list -keystore / opt / jdk1.8.0_60 / jre / lib / security / cacerts -storepass changeit | grep tony tonytest, Mar 23 , 201...

Enable LDAP SSL/TLS on Windows AD

Setup 在設定Active Directory Certificate Services之前,ldaps port就是enable的,但無法使用: netstat -na | findstr ":636" 我測試用的AD server是安裝在Windows 2012,與Reference 1的系統不同。但大致上按照它的教學就可以設定成功。 Install AD Certificate Service 打開Add Roles and Fetures Wizard後,選擇Active Directory Certificate Service,接著一直下一步就可以安裝完成。 Config AD Certificate Service 透過Server Manager選擇AD CS,然後選你的server後,會出現以下畫面: 接著點擊Action就會出現設定畫面: 除了要選擇Key的加密方式外,一直下一步就完成了。安裝完成後,直接重開機。 Export Certificate 要透過SSL/TLS存取AD server的client,一定會遇到certificate驗證問題。所以你必須把server certificate匯出,可以透過以下command匯出為client.crt: certutil -ca.cert client.crt Test connection with LdapAdmin Reference Config certificate for Microsoft Active Directory