前言
上一篇:CAS單點登入-配置中心
下一篇:待續……
https配置
未支援https時預設登入頁

-
自簽名服務端需要導入證書
PS:
- passport.sso.com 是我們測試的域名
- 測試時需要把本地機的ip映射為passport.sso.com設到系統hosts檔案
配置hosts檔案
在目錄
C:\Windows\System32\drivers\etc
下找到并修改hosts檔案
證書處理
生成密鑰
生成步驟,各參數含義:
-genkeypair 生成密鑰
-keyalg 指定密鑰算法,這時指定RSA,
-keysize 指定密鑰長度,預設是1024位,這裡指定2048,長一點,我讓你破解不了(哈哈…),
-siglag 指定數字簽名算法,這裡指定為SHA1withRSA算法
-validity 指定證書有效期,這裡指定36500天,也就是100年,我想我的應用用不到那麼長時間
-alias 指定别名,這裡是cas.server.com
-keystore 指定密鑰庫存儲位置,這裡存在d盤
-dname 指定使用者資訊,不用一個一個回答它的問題了;
**注意:CN=域名,我們采用passport.sso.com **
keytool -genkeypair -keyalg RSA -keysize 2048 -sigalg SHA1withRSA -validity 36500 -alias passport.sso.com -keystore x:/tomcat.keystore -dname "CN=passport.sso.com,OU=kawhi,O=carl,L=GuangZhou,ST=GuangDong,C=CN"
輸入上述指令,密鑰庫密碼輸入123456,然後回車,就在x盤生成了tomcat.keystore檔案;
生成證書
keytool -exportcert -alias passport.sso.com -keystore x:/tomcat.keystore -file x:/tomcat.cer -rfc
證書生成在:x:/tomcat.cer
導入cacerts證書庫
keytool -import -alias passport.sso.com -keystore %JAVA_HOME%\jre\lib\security\cacerts -file x:/tomcat.cer -trustcacerts
輸入密碼為 changeit并同意導入
keytool -list -keystore "%JAVA_HOME%\jre\lib\security\cacerts" | findstr/i server
檢查是否導入成功,有東西輸出代表成功
項目設定
有了證書後,讓項目能夠識别證書,并且把ssl開關打開
引用密鑰
把
tomcat.keystore
拷貝到
sso-server\src\main\resources
下
開啟ssl
檔案
sso-config\src\main\resources\config\sso-dev.properties
調整
- 調整
server.ssl.enabled=true
- 新增如下:
server.ssl.key-store=classpath:tomcat.keystore
server.ssl.key-store-password=123456
server.ssl.keyAlias=passport.sso.com
提供一下完整的配置檔案
server.context-path=/cas
server.port=8443
##SSL配置
server.ssl.enabled=true
server.ssl.key-store=classpath:tomcat.keystore
server.ssl.key-store-password=123456
server.ssl.keyAlias=passport.sso.com
server.max-http-header-size=2097152
server.use-forward-headers=true
server.connection-timeout=20000
server.error.include-stacktrace=NEVER
server.tomcat.max-http-post-size=2097152
server.tomcat.basedir=build/tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)
server.tomcat.accesslog.suffix=.log
server.tomcat.max-threads=10
server.tomcat.port-header=X-Forwarded-Port
server.tomcat.protocol-header=X-Forwarded-Proto
server.tomcat.protocol-header-https-value=https
server.tomcat.remote-ip-header=X-FORWARDED-FOR
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
##
# CAS Cloud Bus Configuration
#
spring.cloud.bus.enabled=false
endpoints.enabled=false
endpoints.sensitive=true
endpoints.restart.enabled=false
endpoints.shutdown.enabled=false
management.security.enabled=true
management.security.roles=ACTUATOR,ADMIN
management.security.sessions=if_required
management.context-path=/status
management.add-application-context-header=false
security.basic.authorize-mode=role
security.basic.enabled=false
security.basic.path=/cas/status/**
##
# CAS Web Application Session Configuration
#
server.session.timeout=300
server.session.cookie.http-only=true
server.session.tracking-modes=COOKIE
##
# CAS Thymeleaf View Configuration
#
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=true
spring.thymeleaf.mode=HTML
##
# CAS Log4j Configuration
#
# logging.config=file:/etc/cas/log4j2.xml
server.context-parameters.isLog4jAutoInitializationDisabled=true
##
# CAS AspectJ Configuration
#
spring.aop.auto=true
spring.aop.proxy-target-class=true
##
# CAS Authentication Credentials
#
cas.authn.accept.users=casuser::Mellon
測試
- 重新開機配置中心
mvn spring-boot:run
- 啟動sso-server
build.cmd run
- 通路 https://passport.sso.com:8443/cas/login 如下圖所示
CAS單點登入-https配置前言https配置
本文參考他人部落格學習整理,需要看原部落格的或者檢視後續文章的可以點選