From 4a1adf3e21e52a70799ebfa1b43f532d5696860e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 15 Nov 2016 16:43:30 +0300 Subject: juick-notifications: using http auth --- .../configuration/NotificationsAppConfiguration.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'juick-notifications/src/main/java/com/juick') diff --git a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsAppConfiguration.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsAppConfiguration.java index c17587ac..c7747aa1 100644 --- a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsAppConfiguration.java +++ b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsAppConfiguration.java @@ -7,9 +7,14 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.InterceptingClientHttpRequestFactory; +import org.springframework.http.client.support.BasicAuthorizationInterceptor; import org.springframework.web.client.RestTemplate; import javax.inject.Inject; +import java.util.Collections; +import java.util.List; /** * Created by aalexeev on 11/12/16. @@ -23,7 +28,13 @@ public class NotificationsAppConfiguration { @Bean public RestTemplate rest() { - return new RestTemplate(); + RestTemplate rest = new RestTemplate(); + List interceptors = Collections + .singletonList( + new BasicAuthorizationInterceptor(env.getProperty("api_user", "juick"), + env.getProperty("api_password", "secret"))); + rest.setRequestFactory(new InterceptingClientHttpRequestFactory(rest.getRequestFactory(), interceptors)); + return rest; } @Bean -- cgit v1.2.3