From b7a8bbdddc70df1cdd0d7622ae2671dbb4f73e14 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Fri, 6 Jun 2014 10:58:40 -0400 Subject: [PATCH] cleanup, error wrappers on protected resource registration --- .../ClientDynamicRegistrationEndpoint.java | 2 +- ...ProtectedResourceRegistrationEndpoint.java | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientDynamicRegistrationEndpoint.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientDynamicRegistrationEndpoint.java index 43fd5fe0c..81a648e3b 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientDynamicRegistrationEndpoint.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientDynamicRegistrationEndpoint.java @@ -247,7 +247,7 @@ public class ClientDynamicRegistrationEndpoint { } catch (JsonSyntaxException e) { // bad parse // didn't parse, this is a bad request - logger.error("registerNewClient failed; submitted JSON is malformed"); + logger.error("updateClient failed; submitted JSON is malformed"); m.addAttribute("code", HttpStatus.BAD_REQUEST); // http 400 return "httpCodeView"; } diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ProtectedResourceRegistrationEndpoint.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ProtectedResourceRegistrationEndpoint.java index 4a65a093c..4cc056cfc 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ProtectedResourceRegistrationEndpoint.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ProtectedResourceRegistrationEndpoint.java @@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.util.UriUtils; import com.google.common.collect.Sets; +import com.google.gson.JsonSyntaxException; @Controller @RequestMapping(value = "resource") @@ -87,7 +88,16 @@ public class ProtectedResourceRegistrationEndpoint { @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public String registerNewProtectedResource(@RequestBody String jsonString, Model m) { - ClientDetailsEntity newClient = ClientDetailsEntityJsonProcessor.parse(jsonString); + ClientDetailsEntity newClient = null; + try { + newClient = ClientDetailsEntityJsonProcessor.parse(jsonString); + } catch (JsonSyntaxException e) { + // bad parse + // didn't parse, this is a bad request + logger.error("registerNewProtectedResource failed; submitted JSON is malformed"); + m.addAttribute("code", HttpStatus.BAD_REQUEST); // http 400 + return "httpCodeView"; + } if (newClient != null) { // it parsed! @@ -253,7 +263,17 @@ public class ProtectedResourceRegistrationEndpoint { public String updateProtectedResource(@PathVariable("id") String clientId, @RequestBody String jsonString, Model m, OAuth2Authentication auth) { - ClientDetailsEntity newClient = ClientDetailsEntityJsonProcessor.parse(jsonString); + ClientDetailsEntity newClient = null; + try { + newClient = ClientDetailsEntityJsonProcessor.parse(jsonString); + } catch (JsonSyntaxException e) { + // bad parse + // didn't parse, this is a bad request + logger.error("updateProtectedResource failed; submitted JSON is malformed"); + m.addAttribute("code", HttpStatus.BAD_REQUEST); // http 400 + return "httpCodeView"; + } + ClientDetailsEntity oldClient = clientService.loadClientByClientId(clientId); if (newClient != null && oldClient != null // we have an existing client and the new one parsed