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.
pull/1046/merge
Trung Nguyen 2016-02-25 13:33:31 -05:00 committed by Justin Richer
parent c96be134da
commit 6fb26856a7
1 changed files with 10 additions and 4 deletions

View File

@ -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<byte[]> 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);
}
}