@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 a specific method for
Basic
Authentication :
setHttpBasicAuth(String username, String password) or
Bearer (OAuth)
authentication : setBearerAuth(String token).
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");
}
}
Copyright © 2010–2020 simpligility technologies inc.. All rights reserved.