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;
}
}