尝试了最基本的cas-server登录登出是不够的,我们还要对它进行二次开发,比如如何设置数据库连接,如何使用数据库的用户名和密码登录,如何使用Restful API方式实现SSO,如何自定义服务,如何自定义登陆界面等等。接下来将逐步介绍。
Cas官方说明,如果你想对它默认项目有所更改,那么就使用覆盖它路径的方式进行
修改默认的用户名密码
1、在cas-overlay-template-master项目中,新建一个src/main/resources目录
2、将resources目录设置成资源目录
3、将target/war/work/org.apereo.cas/cas-server-webapp-tomcat/WEB-INF/classes/apereo.properties文件,拷贝到我们的resources目录中去
项目结构如下图
application.properties 默认配置内容如下
## # CAS Server Context Configuration # server.context-path=/cas server.port=8443 server.ssl.key-store=file:/etc/cas/thekeystore server.ssl.key-store-password=changeit server.ssl.key-password=changeit # server.ssl.ciphers= # server.ssl.client-auth= # server.ssl.enabled= # server.ssl.key-alias= # server.ssl.key-store-provider= # server.ssl.key-store-type= # server.ssl.protocol= # server.ssl.trust-store= # server.ssl.trust-store-password= # server.ssl.trust-store-provider= # server.ssl.trust-store-type= server.max-http-header-size=2097152 server.use-forward-headers=true server.connection-timeout=20000 server.error.include-stacktrace=ALWAYS server.compression.enabled=true server.compression.mime-types=application/javascript,application/json,application/xml,text/html,text/xml,text/plain 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 # spring.cloud.bus.refresh.enabled=true # spring.cloud.bus.env.enabled=true # spring.cloud.bus.destination=CasCloudBus # spring.cloud.bus.ack.enabled=true 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
其中cas.authn.accept.users=casuser::Mellon 表示默认的用户名密码为 casuser::Mellon,
我这里修改为 tingfeng::tingfeng,
然后重新编译后,你的target目录中,cas和classes目录中的application.properties文件,与resources目录中的一样,表示修改成功。
重启cas-server进行测试
登录成功页面
登出页面
源码下载
源码地址:https://github.com/X-rapido/CAS_SSO_Record
参考资源
YouTube教程:CAS 5.1.2 very basic demo, explanation & install process
我把它下载后放在腾讯视频了,链接:https://v.qq.com/x/page/j063197nnmj.html