handled HTTP and parsing errors, fixed guava cache contract, fixes #372
parent
b3486c31a0
commit
8294dbedd5
|
@ -298,6 +298,7 @@ public class IntrospectingTokenService implements ResourceServerTokenServices {
|
||||||
validatedToken = restTemplate.postForObject(introspectionUrl, form, String.class);
|
validatedToken = restTemplate.postForObject(introspectionUrl, form, String.class);
|
||||||
} catch (RestClientException rce) {
|
} catch (RestClientException rce) {
|
||||||
logger.error("validateToken", rce);
|
logger.error("validateToken", rce);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
if (validatedToken != null) {
|
if (validatedToken != null) {
|
||||||
// parse the json
|
// parse the json
|
||||||
|
|
|
@ -39,6 +39,8 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||||
|
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
@ -191,15 +193,18 @@ public class DynamicRegistrationClientConfigurationService implements ClientConf
|
||||||
|
|
||||||
HttpEntity<String> entity = new HttpEntity<>(serializedClient, headers);
|
HttpEntity<String> entity = new HttpEntity<>(serializedClient, headers);
|
||||||
|
|
||||||
String registered = restTemplate.postForObject(serverConfig.getRegistrationEndpointUri(), entity, String.class);
|
try {
|
||||||
// TODO: handle HTTP errors
|
String registered = restTemplate.postForObject(serverConfig.getRegistrationEndpointUri(), entity, String.class);
|
||||||
|
|
||||||
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
|
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
|
||||||
|
|
||||||
// save this client for later
|
// save this client for later
|
||||||
registeredClientService.save(serverConfig.getIssuer(), client);
|
registeredClientService.save(serverConfig.getIssuer(), client);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
} catch (RestClientException rce) {
|
||||||
|
throw new InvalidClientException("Error registering client with server");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (knownClient.getClientId() == null) {
|
if (knownClient.getClientId() == null) {
|
||||||
|
@ -211,12 +216,16 @@ public class DynamicRegistrationClientConfigurationService implements ClientConf
|
||||||
|
|
||||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody();
|
try {
|
||||||
// TODO: handle HTTP errors
|
String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody();
|
||||||
|
// TODO: handle HTTP errors
|
||||||
|
|
||||||
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
|
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
} catch (RestClientException rce) {
|
||||||
|
throw new InvalidClientException("Error loading previously registered client information from server");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// it's got a client ID from the store, don't bother trying to load it
|
// it's got a client ID from the store, don't bother trying to load it
|
||||||
return knownClient;
|
return knownClient;
|
||||||
|
|
Loading…
Reference in New Issue