金仓老旧项目改造-10

张开发
2026/4/18 18:47:15 15 分钟阅读

分享文章

金仓老旧项目改造-10
现在问题已经清楚了项目的sso方式是通过302地址跳转的方式来传递token的这样可以达到单点登录的效果但是因为我们这套都在一个项目里本身就是通过登录页来输入用名密码然后通过ca后又调整回之前的页面所以给人的感觉好像有点脱什么放什么的感觉但是技术还是专业的钦佩老艺术家的心血呀硬生生把一个小工具卷到了天际线。也正常毕竟我们祖师爷盖大爷也是把项目搞黄了才发明出来的java么。也难怪他现在也不好找工作。。。现在问题有两个一个是姗明显对我们的设计无法理解不是一两下就能解决的问题所以我得反复测试因此要解决测试的问题另一个是我的怀疑因为姗是用的powershell来测试接口的这种302的模式她拿到的是跳转后的内容而url里面的信息她是否可以获取到这个有待验证因此待着这两个问题我们开始今天的结对编程。测试问题的解决这块因为要反复测试我的想法是可以利用trae-config.json里custom_commands的模式我自己定义一个命令然后让姗在接受到我指定的暗号后去执行。那么我们先想一个暗号这个暗号不能随便起不然会产生歧义影响我们的感性关系。因为要测试的接口叫activateByLoginCode。我们就把暗号定议为test_activateByLoginCode。好了我跟姗提出了我的想法请她帮我验证一下。以下是我对她说的。我看到trae-config.json文件中有custom_commands的配置我理解我也可以增加这样的命令在我提出指定描述时ai可以执行相应的命令是这样理解吗我还不会用我想请你帮我一起验证一下首先我们先找一个最简单的命令比如就用mvn -version这个命令替代吧。然后我想在我说 执行test_activateByLoginCode时ai可以执行对应的mvn -version命令请你帮忙分析可行性并验证这个方案。好了测试了一下这个命令完全可以行。接下来我们把命令改成实际上我们真正要使用的命令。我惊人的发现原来我在提示词中尽管增加了/spec指令但是如果我的问题被姗认定为是简单的不需要指定完整方案的她也不会创建方案。这个还真是有点意思不是一味的按照要求去傻做还是很厉害的。其实我们只是重新定议了编程方法而已就像前辈用打孔机写代码到汇报再到c语言一直改变的都是编码的方式而不是开发工作的本质所以大家更不用担心是否会被ai所替代这只是我们更进步了而已。用打孔器的程序员也不能理解c语言工程师像说话一样就操纵了计算机。现在我们只是操作计算机的方法进步了而已。只是这种方式我们没见过而且。其实并没有变化马车夫也可以学开汽车而已。很好趁姗在工作的时候我还抽空学习了一下spec的知识原来这个不是一个trae独有的我看网上也有一些介绍但是还在逐渐学习中。还没看完姗已经干完活了。完全出乎我的想象又快又好的完成了这个工作以下是我们的真是聊天记录多夸夸姗大家都开心。谢谢您的认可我很高兴能够成功帮助您实现SSO激活登录码测试命令。让我总结一下我们完成的工作 1. **分析了需求**理解了您需要一个能够测试SSO激活功能的自定义命令 2. **创建了PowerShell脚本**test_sso_activation.ps1该脚本能够调用SSO激活接口 3. **更新了Trae配置**在trae-config.json中添加了test_sso_activation命令 4. **验证了功能**确认命令能够正常执行并返回预期结果 现在您拥有了一个功能完整的SSO激活测试命令可以随时使用test_sso_activation来测试SSO功能。这个命令会自动使用预设的客户端ID和登录码调用接口并返回详细的响应信息。 如果您需要进一步定制这个命令例如修改客户端ID、登录码或添加其他功能我可以继续帮助您进行调整。第二个问题。302返回的url信息ai是否可以获取。这个问题我依旧采用spec方式来处理从使用过程中发现spec方式要比普通聊天的准确率更高一点。通过这种方式姗给我增加了一个ps1脚本通过这个脚本可能调用url并且获取对应的返回信息完美的解决了url信息无法获取的问题下面分亨一下实际的脚本。# Test SSO Full Flow Script - Get Login Code and Activate param( [Parameter(Mandatory$false)] [string]$ClientId $(Read-Host -Prompt Enter Client ID), [Parameter(Mandatory$false)] [string]$Account $(Read-Host -Prompt Enter Account), [Parameter(Mandatory$false)] [string]$Password $(Read-Host -Prompt Enter Password -AsSecureString | ConvertFrom-SecureString | ForEach-Object { [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($_)) }), [Parameter(Mandatory$false)] [string]$ServerUrl http://localhost:8090, [Parameter(Mandatory$false)] [string]$SsoCallback , [Parameter(Mandatory$false)] [int]$TimeoutSec 30 ) # Validate required parameters if ([string]::IsNullOrEmpty($ClientId)) { Write-Host Error: Client ID is required. -ForegroundColor Red exit 1 } if ([string]::IsNullOrEmpty($Account)) { Write-Host Error: Account is required. -ForegroundColor Red exit 1 } if ([string]::IsNullOrEmpty($Password)) { Write-Host Error: Password is required. -ForegroundColor Red exit 1 } try { Write-Host Using client ID: $ClientId -ForegroundColor Green Write-Host Using account: $Account -ForegroundColor Green # Step 1: Get login code by providing username and password Write-Host nStep 1: Getting login code... -ForegroundColor Yellow $getLoginCodeUrl $ServerUrl/sso/xxxxx # Prepare credentials for login $loginBody { account $Account password $Password } | ConvertTo-Json # Headers for JSON content $headers { Content-Type application/json } Write-Host Making request to: $getLoginCodeUrl -ForegroundColor Cyan Write-Host Sending credentials: Account$Account -ForegroundColor Gray # Call getLoginCode endpoint $loginCodeResponse Invoke-RestMethod -Uri $getLoginCodeUrl -Method Post -Headers $headers -Body $loginBody -TimeoutSec $TimeoutSec -UseBasicParsing # Extract login code from response $ssoLoginCode $loginCodeResponse.data # Assuming the response contains the login code in the data field if ([string]::IsNullOrEmpty($ssoLoginCode)) { Write-Host Error: Could not retrieve login code from response. -ForegroundColor Red Write-Host Response: $($loginCodeResponse | ConvertTo-Json -Depth 10) exit 1 } Write-Host Successfully retrieved login code: $ssoLoginCode -ForegroundColor Green # Step 2: Use the login code to activate SSO session Write-Host nStep 2: Activating SSO session with login code... -ForegroundColor Yellow # Encode parameters to handle special characters $encodedClientId [System.Web.HttpUtility]::UrlEncode($ClientId) $encodedSsoLoginCode [System.Web.HttpUtility]::UrlEncode($ssoLoginCode) $encodedSsoCallback [System.Web.HttpUtility]::UrlEncode($SsoCallback) # Construct the activation URL with proper encoding $activateUrl $ServerUrl/sso/xxxxxxxxxxx Write-Host Making request to: $activateUrl -ForegroundColor Cyan # Create a web session to track redirects $session New-Object Microsoft.PowerShell.Commands.WebRequestSession # Perform the activation request with redirection tracking $activateResponse Invoke-WebRequest -Uri $activateUrl -Method Get -TimeoutSec $TimeoutSec -UseBasicParsing -WebSession $session -MaximumRedirection 0 -ErrorAction SilentlyContinue # Handle the activation response if ($activateResponse -and $activateResponse.Headers.Location) { $finalUrl $activateResponse.Headers.Location if ($finalUrl -is [array]) { $finalUrl $finalUrl[-1] # Get the last redirect URL if multiple } Write-Host Initial URL: $activateUrl -ForegroundColor Cyan Write-Host Final URL (after redirects): $finalUrl -ForegroundColor Cyan Write-Host Activate By Login Code Status: $activateResponse.StatusCode -ForegroundColor Green # Only show content if its not empty if ($activateResponse.Content) { Write-Host Response: $activateResponse.Content } else { Write-Host Response: (empty body) } } else { Write-Host Initial URL: $activateUrl -ForegroundColor Cyan Write-Host No redirect occurred, final URL is the same as initial URL -ForegroundColor Yellow if ($activateResponse) { Write-Host Activate By Login Code Status: $activateResponse.StatusCode -ForegroundColor Green # Only show content if its not empty if ($activateResponse.Content) { Write-Host Response: $activateResponse.Content } else { Write-Host Response: (empty body) } } else { Write-Host No response received -ForegroundColor Red } } } catch { Write-Host An error occurred during the SSO flow: -ForegroundColor Red if ($_.Exception.Response) { $response $_.Exception.Response Write-Host Status Code: $response.StatusCode.value__ -ForegroundColor Red Write-Host Error Details: $_.Exception.Message -ForegroundColor Red # Try to get the Location header which contains the redirect URL if ($response.Headers) { $locationHeader $response.Headers[Location] if ($locationHeader) { Write-Host Redirect Location (final URL): $locationHeader -ForegroundColor Green } else { Write-Host No Location header found in redirect response -ForegroundColor Yellow } } # Try to read error response body if available try { $reader New-Object System.IO.StreamReader($response.GetResponseStream()) $errorResponseBody $reader.ReadToEnd() if ($errorResponseBody) { Write-Host Error Response Body: $errorResponseBody } } catch { Write-Host Could not read error response body. } } else { Write-Host Error: $_.Exception.Message -ForegroundColor Red } } # Wait for user input before closing (useful when double-clicking the script) Write-Host nPress any key to continue... -ForegroundColor Gray $null $Host.UI.RawUI.ReadKey(NoEcho,IncludeKeyDown)

更多文章