Hygieia Sonar Collector配置Token遇401错误,请求技术协助
解决Hygieia Sonar Collector 401认证错误
我已搭建Hygieia仪表盘,正在配置Sonar项目,运行Sonar Collector时未配置sonar.usernames和sonar.passwords,仅设置sonar.tokens[0],出现如下401登录错误:
ERROR c.c.d.collector.DefaultSonar6Client - org.springframework.web.client.HttpClientErrorException: 401 2022-08-16 04:19:00,304 [taskScheduler-1] ERROR c.c.d.collector.SonarCollectorTask - org.springframework.web.client.HttpClientErrorException: 401 2022-08-16 04:19:00,304 [taskScheduler-1] INFO c.c.d.collect
我的application.properties配置内容如下:
# Database Name dbname=dashboarddb # Database HostName - default is localhost dbhost=localhost # Database Port - default is 27017 dbport=27017 # MongoDB replicaset dbreplicaset=[false if you are not using MongoDB replicaset] dbhostport=[host1:port1,host2:port2,host3:port3] # Database Username - default is blank dbusername=dashboarduser # Database Password - default is blank dbpassword=dbpassword # Collector schedule (required) sonar.cron=0 0/5 * * * * # Sonar server(s) (required) - Can provide multiple sonar.servers[0]=https://abc.company.com # Sonar version, match array index to the server. If not set, will default to version prior to 6.3. sonar.versions[0]=8.6 # Sonar Metrics - Required. #Sonar versions lesser than 6.3 # Sonar tokens to connect to authenticated url sonar.tokens[0]=xxxxxxxxx #sonar.metrics[0]=ncloc,line_coverage,violations,critical_violations,major_violations,blocker_violations,violations_density,sqale_index,test_success_density,test_failures,test_errors,tests # For Sonar version 6.3 and above sonar.metrics[0]=ncloc,violations,new_vulnerabilities,critical_violations,major_violations,blocker_violations,tests,test_success_density,test_errors,test_failures,coverage,line_coverage,sqale_index,alert_status,quality_gate_details # Sonar login credentials # Format: username1,username2,username3,etc. #sonar.usernames= # Format: password1,password2,password3,etc. #sonar.passwords=
排查与解决步骤
- 验证Sonar Token权限与正确性:确认生成的Sonar Token拥有项目浏览及以上权限,且
sonar.tokens[0]的值与SonarQube平台生成的令牌完全一致,无多余空格或字符。 - 适配Sonar版本与Collector版本:你的Sonar版本为8.6,需确保Hygieia Sonar Collector版本兼容该Sonar版本,建议升级Collector至最新稳定版。
- 尝试替代认证配置:部分Collector版本对
sonar.tokens配置支持不完善,可尝试将sonar.usernames[0]设为你的令牌值,sonar.passwords[0]留空(SonarQube 6.3+支持令牌作为用户名、密码为空的认证方式)。 - 检查网络与服务器可达性:确认
sonar.servers[0]地址可正常访问,无防火墙、反向代理拦截Collector的请求。
内容的提问来源于stack exchange,提问作者CH BHARATH KUMAR
相关产品推荐
相关产品推荐

