use of org.springframework.http.client.support.BasicAuthorizationInterceptor in project mirrorgate-jira-stories-collector by BBVA.
the class Config method getRestTemplate.
@Bean(MIRRORGATE_REST_TEMPLATE)
public RestTemplate getRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
MappingJackson2HttpMessageConverter jsonHttpMessageConverter = new MappingJackson2HttpMessageConverter();
restTemplate.getMessageConverters().add(jsonHttpMessageConverter);
if (mirrorGateUserName.isPresent() && !mirrorGateUserName.get().isEmpty()) {
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(mirrorGateUserName.get(), mirrorGatePassword.get()));
}
return restTemplate;
}
use of org.springframework.http.client.support.BasicAuthorizationInterceptor in project spring-boot by spring-projects.
the class TestRestTemplate method addAuthentication.
private void addAuthentication(RestTemplate restTemplate, String username, String password) {
if (username == null) {
return;
}
List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
if (interceptors == null) {
interceptors = Collections.emptyList();
}
interceptors = new ArrayList<>(interceptors);
Iterator<ClientHttpRequestInterceptor> iterator = interceptors.iterator();
while (iterator.hasNext()) {
if (iterator.next() instanceof BasicAuthorizationInterceptor) {
iterator.remove();
}
}
interceptors.add(new BasicAuthorizationInterceptor(username, password));
restTemplate.setInterceptors(interceptors);
}
use of org.springframework.http.client.support.BasicAuthorizationInterceptor in project spring-boot by spring-projects.
the class SampleMethodSecurityApplicationTests method testManagementUnauthorizedAccess.
@Test
public void testManagementUnauthorizedAccess() throws Exception {
BasicAuthorizationInterceptor basicAuthInterceptor = new BasicAuthorizationInterceptor("user", "user");
this.restTemplate.getRestTemplate().getInterceptors().add(basicAuthInterceptor);
try {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
} finally {
this.restTemplate.getRestTemplate().getInterceptors().remove(basicAuthInterceptor);
}
}
use of org.springframework.http.client.support.BasicAuthorizationInterceptor in project open-kilda by telstra.
the class ServiceConfig method buildRestTemplateWithAuth.
private RestTemplate buildRestTemplateWithAuth(String endpoint, String username, String password) {
final RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(endpoint));
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(username, password));
restTemplate.setErrorHandler(buildErrorHandler());
return restTemplate;
}
use of org.springframework.http.client.support.BasicAuthorizationInterceptor in project mirrorgate-jira-stories-collector by BBVA.
the class Config method getJiraRestTemplate.
@Bean(JIRA_REST_TEMPLATE)
public RestTemplate getJiraRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
MappingJackson2HttpMessageConverter jsonHttpMessageConverter = new MappingJackson2HttpMessageConverter();
restTemplate.getMessageConverters().add(jsonHttpMessageConverter);
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(jiraUserName, jiraPassword));
return restTemplate;
}
Aggregations