SonarQube Web Service API with user token?

1,957 views
Skip to first unread message

alix....@gmail.com

unread,
Sep 20, 2017, 5:18:47 AM9/20/17
to SonarQube
Hi,

I have a web service integration with SonarQube (5.6 LTS) that uses basic authentication which works fine using my login credentials. But when I try to use a user token (for the same account) instead I get an Internal Server Error (HTTP 500) when doing requests (which, by the way, works fine in a web browser when I am logged in).

My previous (successful) request body looked something like this (user: MyLogin, password: MyPassword):

"Basic " + Base64.getEncoder().encodeToString("MyLogin:MyPassword".getBytes());

My new attempt (unsuccessful) looks like:

"Basic " + Base64.getEncoder().encodeToString("b605dc3767701e05804fc052e4ce5d8225f7200d".getBytes());

Could anyone point me in the right direction, please?

G. Ann Campbell

unread,
Sep 20, 2017, 5:36:39 AM9/20/17
to SonarQube
Hi,

I don't think there's a need to Base64-encode a token...


Ann

alix....@gmail.com

unread,
Sep 20, 2017, 7:07:22 AM9/20/17
to SonarQube
Hi Ann,

thanks for the comment. I have now tried: "Basic " + userToken with the same result unfortunately

/ Alix

G. Ann Campbell

unread,
Sep 20, 2017, 9:02:28 AM9/20/17
to Alix Warnke, SonarQube
Hi,

So I can run through this on my end, can you give details on what comes after credentials? :-)

I.e. what are you trying to do with this call?


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/M1wcgiIlKAg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/a8ff94a3-1b42-4f0e-9faa-03b0e2d460bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

alix....@gmail.com

unread,
Sep 20, 2017, 10:08:22 AM9/20/17
to SonarQube
Hi Ann,

the request that I'm attempting is: https://$MY_SERVER$/api/qualityprofiles/search?language=lua
(the language value can differ, all result in the same error). Putting this same URL in a browser (with the same user logged in) will give the expected result as JSON

/ Alix
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

Julien Lancelot

unread,
Sep 21, 2017, 3:42:11 AM9/21/17
to SonarQube
Hi Alex,

Could you please sen us the server's error when using the token ?

Thanks,
Regards,
Julien Lancelot

alix....@gmail.com

unread,
Sep 21, 2017, 4:12:21 AM9/21/17
to SonarQube
Hi Julien,
I didn't have access to the server in question but I managed to set it up locally and could reproduce the problem:

2017.09.21 10:10:26 ERROR web[o.s.s.ui.JRubyFacade] Fail to render: http://localhost:9000/api/qualityprofiles/search?language=lua
undefined method `empty?' for nil:NilClass
C:/sonarqube-5.6.5/web/WEB-INF/lib/authenticated_system.rb:132:in `login_from_basic_auth'
org/jruby/RubyProc.java:290:in `call'
org/jruby/RubyProc.java:224:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/http_authentication.rb:126:in `authenticate'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/http_authentication.rb:116:in `authenticate_with_http_basic'
C:/sonarqube-5.6.5/web/WEB-INF/lib/authenticated_system.rb:129:in `login_from_basic_auth'
C:/sonarqube-5.6.5/web/WEB-INF/lib/authenticated_system.rb:11:in `current_user'
C:/sonarqube-5.6.5/web/WEB-INF/app/controllers/application_controller.rb:102:in `set_user_session'
org/jruby/RubyKernel.java:2223:in `send'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/callbacks.rb:178:in `evaluate_method'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/callbacks.rb:166:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:225:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:629:in `run_before_filters'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:615:in `call_filters'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:610:in `perform_action_with_filters'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/benchmarking.rb:68:in `perform_action_with_benchmark'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/core_ext/benchmark.rb:17:in `ms'
jar:file:/C:/sonarqube-5.6.5/lib/server/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/1.8/benchmark.rb:308:in `realtime'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/core_ext/benchmark.rb:17:in `ms'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/benchmarking.rb:68:in `perform_action_with_benchmark'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/rescue.rb:160:in `perform_action_with_rescue'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/flash.rb:151:in `perform_action_with_flash'
org/jruby/RubyKernel.java:2223:in `send'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:532:in `process'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:606:in `process_with_filters'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:391:in `process'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:386:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/routing/route_set.rb:450:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:87:in `dispatch'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:85:in `dispatch'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:121:in `_call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack'
org/jruby/RubyProc.java:290:in `call'
org/jruby/RubyProc.java:224:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:29:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:9:in `cache'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:28:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/config/environment.rb:67:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/string_coercion.rb:25:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/head.rb:9:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/methodoverride.rb:24:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/params_parser.rb:15:in `call'
file:/C:/sonarqube-5.6.5/lib/server/jruby-rack-1.1.13.2.jar!/jruby/rack/session_store.rb:70:in `context'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/session/abstract/id.rb:58:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/failsafe.rb:26:in `call'
C:/sonarqube-5.6.5/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:106:in `call'
file:/C:/sonarqube-5.6.5/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:34:in `serve_rails'
file:/C:/sonarqube-5.6.5/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:39:in `call'
file:/C:/sonarqube-5.6.5/lib/server/jruby-rack-1.1.13.2.jar!/rack/handler/servlet.rb:22:in `call'

/ Alix

Julien Lancelot

unread,
Sep 21, 2017, 7:54:00 AM9/21/17
to alix....@gmail.com, SonarQube
Ok, I think that you need to add the ":" after the token : 
"Basic " + YOUR_TOKEN  + ":"

Regards,

You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/89d0f5f6-0a0e-4cb9-a10d-3bae6382a13d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Julien Lancelot | SonarSource

alix....@gmail.com

unread,
Sep 21, 2017, 8:38:59 AM9/21/17
to SonarQube
It didn't work. Unfortunately I get the exact same error:

2017.09.21 14:37:32 ERROR web[o.s.s.ui.JRubyFacade] Fail to render: http://localhost:9000/api/qualityprofiles/search?language=lua

Julien Lancelot

unread,
Sep 22, 2017, 5:48:01 AM9/22/17
to alix....@gmail.com, SonarQube
Which tool are you using to do the authentication ?

Could you please try with curl
It would look something like : 


Regards,


For more options, visit https://groups.google.com/d/optout.

alix....@gmail.com

unread,
Sep 22, 2017, 6:30:35 AM9/22/17
to SonarQube
I'm using a Java client (using OkHttp 3.8.0).

Curl works fine:

D:\>curl -u ebd6d91099031eb08919012fa8e5084b2a1a1fae: "http://localhost:9000/api/qualityprofiles/search?language=lua"

{"profiles":[{"key":"lua-sonar-way-25442","name":"Sonar way","language":"lua","languageName":"Lua","isInherited":false,"isDefault":true,"activeRuleCount":8,"rulesUpdatedAt":"2017-09-22T10:24:37+0000"}]}

Julien Lancelot

unread,
Sep 22, 2017, 7:16:27 AM9/22/17
to alix....@gmail.com, SonarQube
If curl works fine, I don't know what we can do for you, you should check how your own tool is working.


For more options, visit https://groups.google.com/d/optout.

Alix Warnke

unread,
Sep 22, 2017, 7:58:41 AM9/22/17
to Julien Lancelot, SonarQube
Ok, thanks. 

To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages