Windows加入AD域後,想實作用登入計算機的AD域賬号密碼,登入各個web應用站點。即浏覽器通路web站點時,不需要輸入使用者密碼,自動使用登入windows系統時的AD賬号登入。
官網位址:
https://apereo.github.io/cas/5.1.x/installation/SPNEGO-Authentication.html
AD域伺服器上生成keytab檔案
- 在AD域中,建立1個域賬号,密碼設定為永不過期
-
使用上面建立的域賬号,建立SPN(服務主體名稱)
使用administrator賬戶登入AD域控伺服器,在指令行運作以下指令:
setspn -S HTTP/[email protected] loginName
參數說明:
cas.test.com:CAS伺服器域名
apitest.domain.com:AD域伺服器的域名
loginName:域登入賬号
SPN:Kerberos身份驗證使用SPN将服務執行個體與服務登入帳戶相關聯
-
生成keytab檔案
使用administrator賬戶登入AD域伺服器,在指令行運作以下指令:
ktpass /out cas.keytab /princ HTTP/[email protected] /pass * /mapuser [email protected]PITEST. DOMAIN.COM /ptype KRB5_NT_PRINCIPAL /crypto RC4-HMAC-NT
參數說明:
cas.keytab:生産的keytab檔案名
cas.test.com:CAS伺服器域名
APITEST.DOMAIN.COM:AD域伺服器的域名(必須大寫)
loginName:域登入賬号
搭建Kerberos
認證原理
https://www.jianshu.com/p/fc2d2dbd510b
https://blog.csdn.net/wulantian/article/details/42418231
Kerberos和CAS需要安裝在同一台伺服器上,且該伺服器必須有域名
- 解壓縮安裝包:krb5-1.17.tar.gz(Linux版Kerberos)
- 進入到安裝包src目錄下,編譯安裝
編譯時可能會出現一些依賴錯誤,需要解決[email protected]# ./configure [email protected]# make && make install
- 修改Kerberos配置檔案 /etc/krb5.conf
[logging] default = FILE:/var/log/krb5libs.log kdc = FILE:/var/log/krb5kdc.log admin_server = FILE:/var/log/kadmind.log [libdefaults] ticket_lifetime = 24000 default_realm = APITEST.DOMAIN.COM default_keytab_name = /root/cas.keytab dns_lookup_realm = true dns_lookup_kdc = true default_tkt_enctypes = rc4-hmac default_tgs_enctypes = rc4-hmac [realms] APITEST.PACTERA.COM = { kdc = apitest.domain.com:88 } [domain_realm] .apitest.pactera.com = APITEST.DOMAIN.COM apitest.pactera.com = APITEST.DOMAIN.COM
- 檢視是否安裝成功
klist -k Keytab name: FILE:/home/cas/kerberos/cas.keytab KVNO Principal ---- -------------------------------------------------------------------------- 3 HTTP/[email protected]
類似上面的結果,說明keytab檔案能正常識别
注意:JDK bin目錄裡也有klist指令,會和Kerberos的指令沖突,建議到Kerberos安裝目錄下執行klist
搭建CAS
- 添加依賴
<dependency> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-support-spnego-webflow</artifactId> <version>${cas.version}</version> </dependency> <dependency> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-support-ldap</artifactId> <version>${cas.version}</version> </dependency>
- 添加配置
#如果在域環境中,使用域賬戶登入,免登 cas.authn.spnego.kerberosConf=/etc/krb5.conf cas.authn.spnego.jcifsServicePrincipal=HTTP/[email protected] cas.authn.spnego.loginConf=classpath:login.conf cas.authn.spnego.kerberosKdc=10.12.30.160 cas.authn.spnego.jcifsDomain=cas.test.com #cas伺服器域名 cas.authn.spnego.kerberosDebug=true cas.authn.spnego.kerberosRealm=APITEST.DOMAIN.COM cas.authn.spnego.ntlm=false cas.authn.spnego.jcifsServicePassword=abcd-123 #生成keytab檔案域賬号的密碼 #不是域使用者,需要輸入AD域賬号密碼登入 cas.authn.ldap[0].type=AUTHENTICATED cas.authn.ldap[0].ldapUrl=ldap://172.16.253.237:389 cas.authn.ldap[0].useSsl=false cas.authn.ldap[0].connectTimeout=5000 cas.authn.ldap[0].baseDn=DC=apitest,DC=domain,DC=com cas.authn.ldap[0].userFilter=(|(sAMAccountName={user})(mail={user})(mobile={user})) cas.authn.ldap[0].subtreeSearch=true cas.authn.ldap[0].bindDn=shiyonghui #域賬号密碼 cas.authn.ldap[0].bindCredential=abcd-123
- 添加配置檔案login.conf,放到CAS classpath目錄下
指定keytab檔案的位置jcifs.spnego.initiate { com.sun.security.auth.module.Krb5LoginModule required storeKey=true useKeyTab=true keyTab="/root/cas.keytab"; }; jcifs.spnego.accept { com.sun.security.auth.module.Krb5LoginModule required storeKey=true useKeyTab=true keyTab="/root/cas.keytab"; };
浏覽器配置
免密登入,需要浏覽器開啟windows身份驗證。
IE開啟windows身份驗證
工具 - Internet選項 – 安全 – 自定義級别 – 自動使用目前使用者名和密碼登入

本地Intranet – 站點 – 進階 – 添加(CAS登入位址)
谷歌浏覽器開啟windows身份驗證
IE開啟後,谷歌浏覽器也就開啟了windows身份驗證