3

We have used AD/LDAP for authentication in SonarQube 7.0... We achieved AD/LDAP authentication successfully...However we want to give project level permissions to different users through program (php / Python).

SonarQube suggests to use web api as below

POST api/permissions/add_user

Params      
 1. login = XXX
 2. permission = user / codereviewer / scan / issueadmin
 3. projectid (optional )
 4. projectkey (optional ) = ABC

Example Request suggested by SonarQube documentation

curl -X POST -v -u admin:admin 'http://localhost:9000/api/permissions/add_user?permission=codeviewer&user=XXX&component=ABC'

We attempted to write php curl to handle post web request and get json response as per below :

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://localhost:9000/api/permissions/add_user");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "login=XXX&permission=user&projectkey=ABC");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

if ($server_output == "OK") { ... } else { ... }

?>

It did not reflect any changes over the ABC project permission for user XXX....

Can anyone guide me on this topic ?

I want to know algorithm if any for Sonarqube web api post request... e.g. To access this post request we need web api admin login /logout for sonarqube before api/permission OR It needs some cookie or tokens...

Thank you for helping me on this..

Asmi
  • 651
  • 1
  • 8
  • 16
  • Issues is resolved by curl HTTP basic authentication header addition as below : curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additional_headers)); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_USERPWD, "username:password"); – Asmi May 31 '18 at 12:12
  • you can refer this ans : https://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl/32272006 – Asmi May 31 '18 at 12:15

1 Answers1

1

use "projectKey" instead of "projectkey"

Maxence Lecointe
  • 238
  • 5
  • 11