Announcement Announcement Module
Collapse
No announcement yet.
Spring security authentication enabled rest webservice, how do I consume it Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring security authentication enabled rest webservice, how do I consume it

    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.

    Guys, I also posted same question in security forum as I am not sure where the best section to post this.

    Thank you

    Lightyear

  • #2
    Guys,

    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(
    "http://thehost:9090/foo/job/history?order=desc&limit=5&status=completed"
    ,JobList.class);

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

    Comment

    Working...
    X