Skip to content

Commit 8294dbe

Browse files
committed
handled HTTP and parsing errors, fixed guava cache contract, fixes mitreid-connect#372
1 parent b3486c3 commit 8294dbe

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

openid-connect-client/src/main/java/org/mitre/oauth2/introspectingfilter/IntrospectingTokenService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOE
298298
validatedToken = restTemplate.postForObject(introspectionUrl, form, String.class);
299299
} catch (RestClientException rce) {
300300
logger.error("validateToken", rce);
301+
return null;
301302
}
302303
if (validatedToken != null) {
303304
// parse the json

openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/DynamicRegistrationClientConfigurationService.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
4040
import org.springframework.security.authentication.AuthenticationServiceException;
4141
import org.springframework.security.oauth2.common.OAuth2AccessToken;
42+
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
43+
import org.springframework.web.client.RestClientException;
4244
import org.springframework.web.client.RestTemplate;
4345

4446
import com.google.common.cache.CacheBuilder;
@@ -191,15 +193,18 @@ public RegisteredClient load(ServerConfiguration serverConfig) throws Exception
191193

192194
HttpEntity<String> entity = new HttpEntity<>(serializedClient, headers);
193195

194-
String registered = restTemplate.postForObject(serverConfig.getRegistrationEndpointUri(), entity, String.class);
195-
// TODO: handle HTTP errors
196-
197-
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
198-
199-
// save this client for later
200-
registeredClientService.save(serverConfig.getIssuer(), client);
201-
202-
return client;
196+
try {
197+
String registered = restTemplate.postForObject(serverConfig.getRegistrationEndpointUri(), entity, String.class);
198+
199+
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
200+
201+
// save this client for later
202+
registeredClientService.save(serverConfig.getIssuer(), client);
203+
204+
return client;
205+
} catch (RestClientException rce) {
206+
throw new InvalidClientException("Error registering client with server");
207+
}
203208
} else {
204209

205210
if (knownClient.getClientId() == null) {
@@ -211,12 +216,16 @@ public RegisteredClient load(ServerConfiguration serverConfig) throws Exception
211216

212217
HttpEntity<String> entity = new HttpEntity<>(headers);
213218

214-
String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody();
215-
// TODO: handle HTTP errors
216-
217-
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
218-
219-
return client;
219+
try {
220+
String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody();
221+
// TODO: handle HTTP errors
222+
223+
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
224+
225+
return client;
226+
} catch (RestClientException rce) {
227+
throw new InvalidClientException("Error loading previously registered client information from server");
228+
}
220229
} else {
221230
// it's got a client ID from the store, don't bother trying to load it
222231
return knownClient;

0 commit comments

Comments
 (0)