0
votes

PDF Report in SonarQube version 4.5.4 is not generating the report due to an error while executing Sonar runner. During post job execution the error raised says the user is not authorized by throwing a 401 HTTP STATUS CODE.

ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.runner.Main.executeTask(Main.java:70)
at org.sonar.runner.Main.execute(Main.java:59)
at org.sonar.runner.Main.main(Main.java:53)
Caused by: org.sonar.wsclient.base.HttpException: Error 401 on http://127.0.0.1:9001/api/issues/search?pageSize=20&componentRoots=MYCODE&rules=findbugs:ODR_OPEN_DATABASE_RESOURCE
at org.sonar.wsclient.internal.HttpRequestFactory.execute(HttpRequestFactory.java:153)
at org.sonar.wsclient.internal.HttpRequestFactory.get(HttpRequestFactory.java:129)
at org.sonar.wsclient.issue.internal.DefaultIssueClient.find(DefaultIssueClient.java:49)
at org.sonar.report.pdf.builder.RuleBuilder.loadViolatedResources(RuleBuilder.java:105)
at org.sonar.report.pdf.builder.ProjectBuilder.initMostViolatedRulesFromNode(ProjectBuilder.java:248)
at org.sonar.report.pdf.builder.ProjectBuilder.initMostViolatedRules(ProjectBuilder.java:175)
at org.sonar.report.pdf.builder.ProjectBuilder.initializeProject(ProjectBuilder.java:98)
at org.sonar.report.pdf.PDFReporter.getProject(PDFReporter.java:132)
at org.sonar.report.pdf.PDFReporter.getReport(PDFReporter.java:82)
at org.sonar.report.pdf.batch.PDFGenerator.execute(PDFGenerator.java:109)
at org.sonar.report.pdf.batch.PDFPostJob.executeOn(PDFPostJob.java:70)
at org.sonar.batch.phases.PostJobsExecutor.execute(PostJobsExecutor.java:72)
at org.sonar.batch.phases.PostJobsExecutor.execute(PostJobsExecutor.java:61)
at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:132)
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:194)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:233)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:228)
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:221)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:64)
at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:51)
at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:125)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:173)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
... 9 more

I've installed PDF Report version 1.4 in SonarQube version 4.5.4. The pdf is generated as a post job task by sonar-runner that reports the user is unauthorized.

I also use LDAP to authenticate my users and force authentication on the server. I've:

  • Configured the plugin to generate the report;
  • Entered a valid Administrator user and password for the keys sonar.pdf.password and sonar.pdf.username;
  • Inserted the PDF Report widget in the Projects dashboard; and
  • Configured the user has administrator for sonar.

If I remove the force authentication option everything works fine.

What am I missing here?

1
there's a patch at [GitHub][1] but solved nothing. src/main/java/org/sonar/report/pdf/builder/RuleBuilder.java was added code after SonarClient client = SonarClient.create(credentials.getUrl());` .login(credentials.getUsername()) .password(credentials.getPassword()) .build(); It goes all the way into creating the temporary file, but at the post job POST to /pdf_report/store server redirects the request with a HTTP 302 REDIRECT back to the login page. [1]: github.com/lvilela/sonar-pdf-report/commit/… - designerferro

1 Answers

0
votes

Found out that applying 3 patchs to the code solved the issu:

Patch 10:

    From 1e5f746c3416b666233711ec4447f80455db1f36 Mon Sep 17 00:00:00 2001
    From: i2slbv <[email protected]>
    Date: Thu, 21 May 2015 15:19:37 +0100
    Subject: [PATCH] Fix for authentication exception in RuleBuilder.

Patch 11

    From e20b52644acc7d40e6383b25642e46bf905a8a21 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Micha=C5=82=20Dettlaff?= <[email protected]>
    Date: Thu, 4 Jun 2015 16:11:40 +0200
    Subject: [PATCH] Related to SONARPLUGINS-3853 - Wrong use of sonar.branch

and patch 12

    From d0c408c1adf9bcd2560387ec8d5984c763b5d73b Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Micha=C5=82=20Dettlaff?= <[email protected]>
    Date: Thu, 4 Jun 2015 18:48:43 +0200
    Subject: [PATCH] fix passing credentials when uploading PDF to the server

Now works perfectly.