handled HTTP and parsing errors, fixed guava cache contract, fixes #372

pull/990/head
Justin Richer 2015-12-18 17:42:15 -05:00
parent b3486c31a0
commit 8294dbedd5
2 changed files with 25 additions and 15 deletions

View File

@ -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

View File

@ -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,8 +193,8 @@ public class DynamicRegistrationClientConfigurationService implements ClientConf
HttpEntity<String> entity = new HttpEntity<>(serializedClient, headers); HttpEntity<String> entity = new HttpEntity<>(serializedClient, headers);
try {
String registered = restTemplate.postForObject(serverConfig.getRegistrationEndpointUri(), entity, String.class); String registered = restTemplate.postForObject(serverConfig.getRegistrationEndpointUri(), entity, String.class);
// TODO: handle HTTP errors
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered); RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
@ -200,6 +202,9 @@ public class DynamicRegistrationClientConfigurationService implements ClientConf
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);
try {
String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody(); String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody();
// TODO: handle HTTP errors // 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;