CAS单点登录-Debug调试源码(十八)
程序员文章站
2022-05-05 16:32:55
...
CAS单点登录-Debug调试源码(十八)
一路过来学习或者使用CAS 5.x版本已经有段时间,开始有朋友问我如何进行调试找问题或者开发了,那么这一章介绍一下如何采用IDEA、Eclipse进行调试
实战
通过官网的overlay构建会发现跟目录有build.cmd
/build.sh
两个文件,当然啦就是不同系统环境下的执行文件,而通过作者的源码的,就是在sso-server
目录下
build.cmd
@echo off
@set JAVA_ARGS=-Xms500m -Xmx1g
@set CAS_DIR=\etc\cas
@set CONFIG_DIR=\etc\cas\config
@rem Call this script with DNAME and CERT_SUBJ_ALT_NAMES already set to override
@if "%DNAME%" == "" set DNAME=CN=cas.example.org,OU=Example,OU=Org,C=US
@rem List other host names or ip addresses you want in your certificate, may help with host name verification,
@rem if client apps make https connection for ticket validation and compare name in cert (include sub. alt. names)
@rem to name used to access CAS
@if "%CERT_SUBJ_ALT_NAMES%" == "" set CERT_SUBJ_ALT_NAMES=dns:example.org,dns:localhost,dns:%COMPUTERNAME%,ip:127.0.0.1
@rem Check for mvn in path, use it if found, otherwise use maven wrapper
@set MAVEN_CMD=mvn
@where /q mvn
@if %ERRORLEVEL% neq 0 set MAVEN_CMD=.\mvnw.bat
@if "%1" == "" call:help
@if "%1" == "copy" call:copy
@if "%1" == "clean" call:clean %2 %3 %4
@if "%1" == "package" call:package %2 %3 %4
@if "%1" == "bootrun" call:bootrun %2 %3 %4
@if "%1" == "debug" call:debug %2 %3 %4
@if "%1" == "run" call:run %2 %3 %4
@if "%1" == "help" call:help
@if "%1" == "gencert" call:gencert
@rem function section starts here
@goto:eof
:copy
@echo "Creating configuration directory under %CONFIG_DIR%"
if not exist %CONFIG_DIR% mkdir %CONFIG_DIR%
@echo "Copying configuration files from etc/cas to /etc/cas"
xcopy /S /Y etc\cas\* \etc\cas
@goto:eof
:help
@echo "Usage: build.bat [copy|clean|package|run|debug|bootrun|gencert] [optional extra args for maven]"
@echo "To get started on a clean system, run "build.bat copy" and "build.bat gencert", then "build.bat run"
@echo "Note that using the copy or gencert arguments will create and/or overwrite the %CAS_DIR% which is outside this project"
@goto:eof
:clean
call %MAVEN_CMD% clean %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:package
call %MAVEN_CMD% clean package -T 5 %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:bootrun
call %MAVEN_CMD% clean package spring-boot:run -T 5 %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:debug
call:package %1 %2 %3 & java %JAVA_ARGS% -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
@goto:eof
:run
call:package %1 %2 %3 & java %JAVA_ARGS% -jar target/cas.war
@goto:eof
:gencert
where /q keytool
if ERRORLEVEL 1 (
@echo Java keytool.exe not found in path.
exit /b 1
) else (
if not exist %CAS_DIR% mkdir %CAS_DIR%
@echo on
@echo Generating self-signed SSL cert for %DNAME% in %CAS_DIR%\thekeystore
keytool -genkeypair -alias cas -keyalg RSA -keypass changeit -storepass changeit -keystore %CAS_DIR%\thekeystore -dname %DNAME% -ext SAN=%CERT_SUBJ_ALT_NAMES%
@echo Exporting cert for use in trust store (used by cas clients)
keytool -exportcert -alias cas -storepass changeit -keystore %CAS_DIR%\thekeystore -file %CAS_DIR%\cas.cer
)
@goto:eof
代码62行如下,
call:package %1 %2 %3 & java %JAVA_ARGS% -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
不难发现是采用java -jar
的方式启用了一个远程调试5000
端口,当然了这个端口也是可以改的
启用调试
build.cmd debug
结果如下:
监听端口
以下作者采用IDEA方式监听,eclipse监听可以参考,点击我打开参考
点击Edit Configuration
如果看到如下您已成功了一半
调试代码
选择一个代码进行调试:
我挑了QueryDatabaseAuthenticationHandler
进行调试,具体调试哪个代码按自己的实际情况
以上操作在查询数据库认证的时候触发debug,那么我在提交用户名密码之后的,会跳到这里来进行阻塞
注意要点
- 由于cas默认是在war包下已经包含了很多lib,若需要进行调试需要加上部分依赖找到代码即可进行debug
- 默认端口为5000,可以再脚本进行调试,当然了,在启用自己加上debug端口也是没问题的
另外如果读者仍然在学习cas,可以参考其他博文或者下载源码尝试:
作者联系方式
如果技术的交流或者疑问可以联系或者提出issue。
邮箱:aaa@qq.com
QQ: 756884434 (请注明:SSO-CSDN)
上一篇: 一段Spring代码引起的调用绑定总结
下一篇: 多线程学习(三)之volatile关键字