From 6fb26856a72410a5976ce9f6f12cae0e9c588a99 Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Thu, 25 Feb 2016 13:33:31 -0500 Subject: [PATCH] Make apiAddClient in the client api return a HttpStatus.Conflict if you try to create a client with a used client id. This fixes a bug where if you try to create a client with a client id that is already in use, you get an empty error message. Instead, now you get a message that tells you that the client couldn't be created because the client id is already in use. --- .../org/mitre/openid/connect/web/ClientAPI.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientAPI.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientAPI.java index 871f41bec..26350803e 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientAPI.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientAPI.java @@ -19,6 +19,7 @@ package org.mitre.openid.connect.web; import java.lang.reflect.Type; import java.text.ParseException; import java.util.Collection; +import javax.persistence.PersistenceException; import org.mitre.oauth2.model.ClientDetailsEntity; import org.mitre.oauth2.model.ClientDetailsEntity.AuthMethod; @@ -244,6 +245,11 @@ public class ClientAPI { m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Unable to save client: " + e.getMessage()); return JsonErrorView.VIEWNAME; + } catch (PersistenceException e) { + logger.error("Unable to save client. Duplicate client id entry found: {}", e.getMessage()); + m.addAttribute(HttpCodeView.CODE, HttpStatus.CONFLICT); + m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Unable to save client. Duplicate client id entry found: " + client.getClientId()); + return JsonErrorView.VIEWNAME; } } @@ -400,14 +406,14 @@ public class ClientAPI { return ClientEntityViewForUsers.VIEWNAME; } } - + /** * Get the logo image for a client * @param id */ @RequestMapping(value = "/{id}/logo", method=RequestMethod.GET, produces = { MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE }) public ResponseEntity getClientLogo(@PathVariable("id") Long id, Model model) { - + ClientDetailsEntity client = clientService.getClientById(id); if (client == null) { @@ -417,11 +423,11 @@ public class ClientAPI { } else { // get the image from cache CachedImage image = clientLogoLoadingService.getLogo(client); - + HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType(image.getContentType())); headers.setContentLength(image.getLength()); - + return new ResponseEntity<>(image.getData(), headers, HttpStatus.OK); } }