expected= [java.net.URI] actual=[java.io.File]错误

本文解决了一个JBoss中的AttachmentStore构造时发生的参数类型不匹配的问题,通过修改profile.xml文件中的构造函数参数声明,成功避免了IllegalArgumentException异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

java.lang.IllegalArgumentException: Wrong arguments. new for target java.lang.reflect.Constructor expected=

[java.net.URI] actual=[java.io.File]

此问题为jboss的一个bug,其链接为https://jira.jboss.org/browse/JBAS-6981

修改$JBOSS_HOME/server/< serverName>/conf/bootstrap/profile.xml 中的

<bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore">
		<constructor><parameter><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
		<property name="mainDeployer"><inject bean="MainDeployer" /></property>
		<property name="serializer"><inject bean="AttachmentsSerializer" /></property>
		<property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
	</bean>

 为下面代码

<bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore">
		<constructor><parameter class="java.io.File"><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
		<property name="mainDeployer"><inject bean="MainDeployer" /></property>
		<property name="serializer"><inject bean="AttachmentsSerializer" /></property>
		<property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
	</bean>
 

 

 

# CurlTools.psm1 - 企业级安全下载模块 $projectRoot = $PSScriptRoot # 从清单文件获取路径配置 $manifest = Test-ModuleManifest -Path (Join-Path $projectRoot "CurlTools.psd1") -ErrorAction Stop $pathConfig = $manifest.PrivateData.PSData.ProjectPaths # 初始化目录路径 $configDir = Join-Path $projectRoot $pathConfig.Config $logDir = Join-Path $projectRoot $pathConfig.Logs $tempDir = Join-Path $projectRoot $pathConfig.Temp $curlBinDir = Join-Path $projectRoot $pathConfig.CurlBin # 目录初始化 foreach ($dir in ($configDir, $logDir, $tempDir, $curlBinDir)) { if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null Write-Verbose "Created directory: $dir" } } # 模块作用域配置变量 $script:ModuleConfig = $null function Write-Log { param( [string]$Message, [ValidateSet('Info','Warning','Error','Audit')] [string]$Level = 'Info' ) $logPath = "$logDir\curl_tools_$(Get-Date -Format 'yyyyMMdd').log" $timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' $logEntry = "[$timestamp] [$Level] $Message" Add-Content -Path $logPath -Value $logEntry # 审计级日志额外记录到单独文件 if ($Level -eq 'Audit') { $auditPath = "$logDir\audit_$(Get-Date -Format 'yyyyMMdd').log" Add-Content -Path $auditPath -Value $logEntry } } function Get-CurlPath { <# .SYNOPSIS 获取curl.exe的完整路径 #> try { $curlPath = Join-Path $curlBinDir "curl.exe" if (-not (Test-Path $curlPath)) { throw "curl.exe not found at: $curlPath" } # 二进制签名验证(简化版) $fileInfo = Get-Item $curlPath if ($fileInfo.Length -lt 2) { throw "Invalid binary size" } # 读取文件头验证PE格式 (MZ header) $header = [System.IO.File]::ReadAllBytes($curlPath)[0..1] if (-not ($header[0] -eq 0x4D -and $header[1] -eq 0x5A)) { throw "Invalid binary signature" } return $curlPath } catch { Write-Log -Message "Get-CurlPath error: $_" -Level 'Error' throw $_ } } function Get-CurlVersion { <# .SYNOPSIS 获取curl版本信息 #> try { $curlPath = Get-CurlPath $versionInfo = & $curlPath --version $versionString = $versionInfo[0] -replace 'curl ', '' return [System.Version]::new($versionString.Split(' ')[0]) } catch { Write-Log -Message "Get-CurlVersion error: $_" -Level 'Error' throw $_ } } function Set-SecurityConfig { <# .SYNOPSIS 设置安全配置 .PARAMETER Config 包含安全配置的哈希表 .EXAMPLE $config = @{ AllowedDomains = @("example.com") BlockedDomains = @("malicious.com") MaxDownloadSpeed = 1024 MaxFileSizeMB = 10 RequireHTTPS = $true } Set-SecurityConfig -Config $config #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [hashtable]$Config ) # 验证必要配置项 $requiredKeys = @('AllowedDomains', 'BlockedDomains', 'MaxDownloadSpeed', 'MaxFileSizeMB', 'RequireHTTPS') foreach ($key in $requiredKeys) { if (-not $Config.ContainsKey($key)) { throw "Missing required configuration key: $key" } } # 验证域名列表 if ($Config.AllowedDomains.Count -eq 0) { throw "AllowedDomains cannot be empty" } # 验证数值范围 if ($Config.MaxDownloadSpeed -lt 0) { throw "MaxDownloadSpeed must be non-negative" } if ($Config.MaxFileSizeMB -le 0) { throw "MaxFileSizeMB must be greater than 0" } $script:ModuleConfig = $Config Write-Log -Message "Security configuration updated" -Level 'Audit' } function Get-SecurityConfig { <# .SYNOPSIS 获取当前安全配置 #> if ($null -ne $script:ModuleConfig) { return $script:ModuleConfig } # 从配置文件加载 $configPath = Join-Path $configDir "config.json" if (-not (Test-Path $configPath)) { throw "Config file not found: $configPath" } try { $config = Get-Content $configPath | ConvertFrom-Json -AsHashtable -ErrorAction Stop $script:ModuleConfig = $config return $config } catch { Write-Log -Message "Failed to load config: $_" -Level 'Error' throw $_ } } function Invoke-SecureDownload { <# .SYNOPSIS 执行安全文件下载 #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [string]$OutputPath, [ValidateSet('SHA256','MD5','SHA1')] [string]$HashAlgorithm, [string]$ExpectedHash, [int]$MaxRetry = 3, [int]$MaxDownloadSpeed = 0 ) $activity = "Secure Download" Write-Progress -Activity $activity -Status "Initializing..." $retryCount = 0 $tempFile = $null do { try { # 审计日志 Write-Log -Message "DOWNLOAD INITIATED: $Url => $OutputPath" -Level 'Audit' Write-Log -Message "Starting download (attempt $($retryCount+1)/$MaxRetry): $Url" -Level 'Info' # 获取安全配置 $config = Get-SecurityConfig # HTTPS 验证 if ($config.RequireHTTPS -and -not $Url.StartsWith("https://")) { $msg = "Non-HTTPS downloads are prohibited: $Url" Write-Log -Message $msg -Level 'Warning' throw $msg } # 域名验证 $domain = ([uri]$Url).Host # 检查黑名单 foreach ($blocked in $config.BlockedDomains) { if ($domain -eq $blocked -or $domain.EndsWith(".$blocked")) { $msg = "Domain blocked by policy: $domain" Write-Log -Message $msg -Level 'Warning' throw $msg } } # 检查白名单 $isAllowed = $false foreach ($allowed in $config.AllowedDomains) { if ($domain -eq $allowed -or $domain.EndsWith(".$allowed")) { $isAllowed = $true break } } if (-not $isAllowed) { $msg = "Domain not allowed by policy: $domain" Write-Log -Message $msg -Level 'Warning' throw $msg } # 输出目录准备 $outputDir = Split-Path $OutputPath -Parent if (-not (Test-Path $outputDir)) { New-Item -Path $outputDir -ItemType Directory -Force | Out-Null Write-Log -Message "Created directory: $outputDir" } # 下载执行 $curlPath = Get-CurlPath $tempFile = Join-Path $tempDir "$([System.IO.Path]::GetRandomFileName()).tmp" $arguments = @( "-L", "--progress-bar", "--fail", "-o", "`"$tempFile`"", "`"$Url`"" ) # 添加限速参数 $effectiveSpeed = $config.MaxDownloadSpeed if ($MaxDownloadSpeed -gt 0) { $effectiveSpeed = $MaxDownloadSpeed } if ($effectiveSpeed -gt 0) { $arguments += "--limit-rate" $arguments += "$($effectiveSpeed)k" } Write-Progress -Activity $activity -Status "Downloading..." $process = Start-Process -FilePath $curlPath -ArgumentList $arguments ` -NoNewWindow -PassThru -Wait if ($process.ExitCode -ne 0) { throw "Download failed with exit code $($process.ExitCode)" } # 文件验证 if (-not (Test-Path $tempFile)) { throw "Downloaded file not found" } $fileSize = (Get-Item $tempFile).Length if ($fileSize -eq 0) { throw "Downloaded file is empty" } # 文件大小检查 $maxSizeBytes = $config.MaxFileSizeMB * 1MB if ($fileSize -gt $maxSizeBytes) { $msg = "File size ($([math]::Round($fileSize/1MB,2))MB) exceeds limit ($($config.MaxFileSizeMB)MB)" Write-Log -Message $msg -Level 'Error' throw $msg } # 哈希验证 if ($PSBoundParameters.ContainsKey('HashAlgorithm')) { Write-Progress -Activity $activity -Status "Verifying hash..." $actualHash = (Get-FileHash -Path $tempFile -Algorithm $HashAlgorithm).Hash Write-Log -Message "File hash ($HashAlgorithm): $actualHash" -Level 'Info' if ($PSBoundParameters.ContainsKey('ExpectedHash') -and $actualHash -ne $ExpectedHash) { $msg = "Hash verification failed! Expected: $ExpectedHash, Actual: $actualHash" Write-Log -Message $msg -Level 'Error' throw $msg } } # 最终文件移动 Move-Item -Path $tempFile -Destination $OutputPath -Force Write-Log -Message "Download completed: $OutputPath" -Level 'Info' Write-Log -Message "DOWNLOAD COMPLETED: $Url => $OutputPath" -Level 'Audit' return $true } catch { $retryCount++ Write-Log -Message "Download attempt $retryCount failed: $_" -Level 'Warning' if ($retryCount -ge $MaxRetry) { Write-Log -Message "Max retries reached for: $Url" -Level 'Error' throw "Download failed after $MaxRetry attempts: $_" } # 等待指数退避时间 $delay = [Math]::Pow(2, $retryCount) Write-Progress -Activity $activity -Status "Retrying in $delay seconds..." Start-Sleep -Seconds $delay } finally { if ($null -ne $tempFile -and (Test-Path $tempFile)) { Remove-Item $tempFile -Force -ErrorAction SilentlyContinue } } } while ($retryCount -lt $MaxRetry) } # 导出公共函数 $exportFunctions = @( 'Get-CurlPath', 'Get-CurlVersion', 'Invoke-SecureDownload', 'Set-SecurityConfig', 'Get-SecurityConfig' ) Export-ModuleMember -Function $exportFunctions
最新发布
08-15
# CurlTools.psm1 - 企业级安全下载模块 $projectRoot = $PSScriptRoot # 从清单文件获取路径配置 $manifest = Test-ModuleManifest -Path (Join-Path $projectRoot "CurlTools.psd1") -ErrorAction Stop $pathConfig = $manifest.PrivateData.PSData.ProjectPaths # 初始化目录路径 $configDir = Join-Path $projectRoot $pathConfig.Config $logDir = Join-Path $projectRoot $pathConfig.Logs $tempDir = Join-Path $projectRoot $pathConfig.Temp $curlBinDir = Join-Path $projectRoot $pathConfig.CurlBin # 目录初始化 foreach ($dir in ($configDir, $logDir, $tempDir, $curlBinDir)) { if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null Write-Verbose "Created directory: $dir" } } function Write-Log { param( [string]$Message, [ValidateSet('Info','Warning','Error','Audit')] [string]$Level = 'Info' ) $logPath = "$logDir\curl_tools_$(Get-Date -Format 'yyyyMMdd').log" $timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' $logEntry = "[$timestamp] [$Level] $Message" Add-Content -Path $logPath -Value $logEntry # 审计级日志额外记录到单独文件 if ($Level -eq 'Audit') { $auditPath = "$logDir\audit_$(Get-Date -Format 'yyyyMMdd').log" Add-Content -Path $auditPath -Value $logEntry } } function Get-CurlPath { <# .SYNOPSIS 获取curl.exe的完整路径 #> try { $curlPath = Join-Path $curlBinDir "curl.exe" if (-not (Test-Path $curlPath)) { throw "curl.exe not found at: $curlPath" } return $curlPath } catch { Write-Log -Message "Get-CurlPath error: $_" -Level 'Error' throw $_ } } function Get-CurlVersion { <# .SYNOPSIS 获取curl版本信息(内部函数) #> try { $curlPath = Get-CurlPath $versionInfo = & $curlPath --version return $versionInfo[0] } catch { Write-Log -Message "Get-CurlVersion error: $_" -Level 'Error' throw $_ } } function Invoke-SecureDownload { <# .SYNOPSIS 执行安全文件下载 #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [string]$OutputPath, [ValidateSet('SHA256','MD5','SHA1')] [string]$HashAlgorithm, [string]$ExpectedHash, [int]$MaxRetry = 3, [int]$MaxDownloadSpeed = 0 ) $activity = "Secure Download" Write-Progress -Activity $activity -Status "Initializing..." $retryCount = 0 $tempFile = $null do { try { # 审计日志 Write-Log -Message "DOWNLOAD INITIATED: $Url => $OutputPath" -Level 'Audit' Write-Log -Message "Starting download (attempt $($retryCount+1)/$MaxRetry): $Url" -Level 'Info' # 域名验证 $domain = ([uri]$Url).Host $configPath = Join-Path $configDir "config.json" if (-not (Test-Path $configPath)) { throw "Config file not found: $configPath" } $config = Get-Content $configPath | ConvertFrom-Json -ErrorAction Stop $isAllowed = $false foreach ($allowed in $config.AllowedDomains) { if ($domain -eq $allowed -or $domain.EndsWith(".$allowed")) { $isAllowed = $true break } } if (-not $isAllowed) { $msg = "Domain blocked by policy: $domain" Write-Log -Message $msg -Level 'Warning' throw $msg } # 输出目录准备 $outputDir = Split-Path $OutputPath -Parent if (-not (Test-Path $outputDir)) { New-Item -Path $outputDir -ItemType Directory -Force | Out-Null Write-Log -Message "Created directory: $outputDir" } # 下载执行 $curlPath = Get-CurlPath $tempFile = Join-Path $tempDir "$([System.IO.Path]::GetRandomFileName()).tmp" $arguments = @( "-L", "--progress-bar", "--fail", "-o", "`"$tempFile`"", "`"$Url`"" ) # 添加限速参数 if ($MaxDownloadSpeed -gt 0) { $arguments += "--limit-rate" $arguments += "$($MaxDownloadSpeed)k" } Write-Progress -Activity $activity -Status "Downloading..." $process = Start-Process -FilePath $curlPath -ArgumentList $arguments ` -NoNewWindow -PassThru -Wait if ($process.ExitCode -ne 0) { throw "Download failed with exit code $($process.ExitCode)" } # 文件验证 if (-not (Test-Path $tempFile)) { throw "Downloaded file not found" } if ((Get-Item $tempFile).Length -eq 0) { throw "Downloaded file is empty" } # 哈希验证 if ($PSBoundParameters.ContainsKey('HashAlgorithm')) { Write-Progress -Activity $activity -Status "Verifying hash..." $actualHash = (Get-FileHash -Path $tempFile -Algorithm $HashAlgorithm).Hash Write-Log -Message "File hash ($HashAlgorithm): $actualHash" -Level 'Info' if ($PSBoundParameters.ContainsKey('ExpectedHash') -and $actualHash -ne $ExpectedHash) { $msg = "Hash verification failed! Expected: $ExpectedHash, Actual: $actualHash" Write-Log -Message $msg -Level 'Error' throw $msg } } # 最终文件移动 Move-Item -Path $tempFile -Destination $OutputPath -Force Write-Log -Message "Download completed: $OutputPath" -Level 'Info' # 在模块清单文件 (CurlTools.psd1) 中添加 FunctionsToExport = @('Get-CurlPath', 'Get-CurlVersion', 'Invoke-SecureDownload') # 在模块主体中实现 Get-CurlVersion function Get-CurlVersion { $curlPath = Get-CurlPath try { $result = & $curlPath --version 2>&1 return ($result | Select-Object -First 1).Trim() } catch { Write-Error "Failed to get curl version: $_" return $null } } # 添加配置注入点 $script:ModuleConfig = @{ AllowedDomains = @("example.com", "github.com") MaxDownloadSpeed = 1024 } function Set-ModuleConfig { param( [hashtable]$Config ) $script:ModuleConfig = $Config } Write-Log -Message "DOWNLOAD COMPLETED: $Url => $OutputPath" -Level 'Audit' return $true } catch { $retryCount++ Write-Log -Message "Download attempt $retryCount failed: $_" -Level 'Warning' if ($retryCount -ge $MaxRetry) { Write-Log -Message "Max retries reached for: $Url" -Level 'Error' throw "Download failed after $MaxRetry attempts: $_" } # 等待指数退避时间 $delay = [Math]::Pow(2, $retryCount) Write-Progress -Activity $activity -Status "Retrying in $delay seconds..." Start-Sleep -Seconds $delay } finally { if ($null -ne $tempFile -and (Test-Path $tempFile)) { Remove-Item $tempFile -Force -ErrorAction SilentlyContinue } } } while ($retryCount -lt $MaxRetry) } # 导出公共函数 Export-ModuleMember -Function 'Get-CurlPath', 'Invoke-SecureDownload'
08-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值