CAS单点登录-https配置

前言

上一篇:CAS单点登录-配置中心

下一篇:待续……

https配置

未支持https时默认登录页

  • 自签名服务端需要导入证书

    PS:

    1. passport.sso.com 是我们测试的域名
    2. 测试时需要把本地机的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调整

  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 如下图所示

本文参考他人博客学习整理,需要看原博客的或者查看后续文章的可以点击

转载于:https://juejin.im/post/5c234f9951882551b72802fc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值