Я использую шаблон Spring Rest в приложении Spring Boot.Spring REST template - 401 Unauthorized error
Я всегда получаю 401 Несанкционированную ошибку, хотя я передаю учетные данные.
Я могу получить доступ к этой услуге клиентом веб-службы Chrome REST.
Есть ли упрощенный способ доступа к шаблону REST в SpringBoot.
Ниже приведен фрагмент кода сделано до сих пор, что приводит к ошибке 401
private DetailsBean invokeDetailsRestService(UserParam userParam){
ResponseEntity<DetailsBean> responseEntity = null;
String url = "https://dev.com/app/identifyuser/";
RestClientConfig restClientConfig =new RestClientConfig("user123","pass123");
responseEntity= restClientConfig.postForEntity(url, userParam, DetailsBean.class);
log.debug("User Details : {} ", responseEntity.getBody());
return responseEntity.getBody();
}
public ClientHttpRequestFactory getRequestFactory(String userName,String password){
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(userName,password));
HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
return new HttpComponentsClientHttpRequestFactory(httpClient);
}
класс RestClientConfig
public RestClientConfig(String username, String password) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(null, -1),
new UsernamePasswordCredentials(username, password));
HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
Ошибка:
WARN c7af55b5-1cac-4db6-a202-202416c27ba4
12612 --- [apr-8082-exec-8] o.a.http.impl.auth.HttpAuthenticator
: NEGOTIATE authentication error:
No valid credentials provided (Mechanism level:
No valid credentials provided (Mechanism level:
Failed to find any Kerberos tgt))
Вы не используете RestTemplate весны на всех. – baao
RestClientConfig отличается от RestTemplate, ошибка связана с конечной точкой https://dev.com/app/identifyuser/, вы уверены, что с учетными данными. – nole