org.androidannotations.annotations.rest
Annotation Type RequiresAuthentication


@Retention(value=CLASS)
@Target(value={METHOD,TYPE})
public @interface RequiresAuthentication

Use on Get, Post, … annotated methods to use authentication on the request.

To set the current authentication object to use, you MUST either let your RestClient interface extends of RestClientHeaders or add the following method to your interface : void setAuthentication(org.springframework.http.HttpAuthentication auth).

You can also add this specific method for Basic Authentication : setHttpBasicAuth(String username, String password).

Example :
 @Rest(rootUrl = "http://myserver", converters = MappingJacksonHttpMessageConverter.class)
 public interface MyRestClient {
 
        @Get("/events/{id}")
        @RequiresAuthentication
        Event getEvent(long id);
 
        setHttpBasicAuth(String username, String password);
 }
 
 @EBean
 public class MyBean {
 
        @RestService MyRestClient;
 
        @AfterInject
        public void init() {
                myRestClient.setHttpBasicAuth("user", "password");
        }
 }
 

See Also:
Rest, Get, Post, Put, Delete, Head, Options



Copyright © 2010-2014. All Rights Reserved.