Announcement Announcement Module
No announcement yet.
How to consume spring security enabled REST webservice in Android Spring RestTemplate Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to consume spring security enabled REST webservice in Android Spring RestTemplate

    Hi Guys,

    I created a rest webservice using spring, then later I added a spring authentication module. I would say it is working great as each time I access the REST URL my request ib being intercepted prompting me for username and password.

    Now, I would like to consume the REST webservice in android (authentication spring enabled) using the Spring RestTemplate. My question now is how do I consume the webservice in android given that it has authentication security?

    Could someone help me guys have a code snippet on how to pass the username and password in RestTemplate, or could anyone give me a way to do it.

    Thank you


  • #2

    To be more specific here's what I was dong but still was not able to run RestTemplate without being challenged for authentication:

    HttpClient client = new HttpClient();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("your_user","your_pass word");
    client.getState().setCredentials(new AuthScope("thehost", 9090, AuthScope.ANY_REALM), credentials);
    CommonsClientHttpRequestFactory commons = new CommonsClientHttpRequestFactory(client);

    RestTemplate template = new RestTemplate(commons);
    JobList results = template.getForObject(

    Any idea on how to call a secured (spring authentication) webservice using rest template?


    • #3
      You will need to set HttpClient to do Preemptive Authentication. See the 4.x documentation or the 3.x documentation.