CAS單點登入-https配置

Null指標發表於2018-12-26

前言

上一篇:CAS單點登入-配置中心

下一篇:待續……

https配置

未支援https時預設登入頁

CAS單點登入-https配置

  • 自簽名服務端需要匯入證照

    PS:

    1. passport.sso.com 是我們測試的域名
    2. 測試時需要把本地機的ip對映為passport.sso.com設到系統hosts檔案

配置hosts檔案

在目錄C:\Windows\System32\drivers\etc下找到並修改hosts檔案

CAS單點登入-https配置

證照處理

生成金鑰

生成步驟,各引數含義:

-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檔案;

CAS單點登入-https配置

生成證照

keytool -exportcert -alias passport.sso.com -keystore x:/tomcat.keystore  -file x:/tomcat.cer -rfc
複製程式碼

證照生成在:x:/tomcat.cer

CAS單點登入-https配置

匯入cacerts證照庫

keytool -import -alias passport.sso.com -keystore %JAVA_HOME%\jre\lib\security\cacerts -file x:/tomcat.cer -trustcacerts
複製程式碼

輸入密碼為 changeit並同意匯入

CAS單點登入-https配置

keytool -list -keystore "%JAVA_HOME%\jre\lib\security\cacerts" | findstr/i server
複製程式碼

檢查是否匯入成功,有東西輸出代表成功

CAS單點登入-https配置

專案設定

有了證照後,讓專案能夠識別證照,並且把ssl開關開啟

引用金鑰

tomcat.keystore拷貝到sso-server\src\main\resources

開啟ssl

檔案sso-config\src\main\resources\config\sso-dev.properties調整

  1. 調整server.ssl.enabled=true
  2. 新增如下:
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
複製程式碼

測試

  1. 重啟配置中心

    mvn spring-boot:run
    複製程式碼
  2. 啟動sso-server

    build.cmd run
    複製程式碼
  3. 訪問 passport.sso.com:8443/cas/login 如下圖所示

    CAS單點登入-https配置

本文參考他人部落格學習整理,需要看原部落格的或者檢視後續文章的可以點選

相關文章