diff --git a/openid-connect-server/pom.xml b/openid-connect-server/pom.xml
index c80649c34..fa78c963f 100644
--- a/openid-connect-server/pom.xml
+++ b/openid-connect-server/pom.xml
@@ -46,6 +46,11 @@
org.springframework
spring-tx
+
+ org.eclipse.persistence
+ org.eclipse.persistence.core
+ 2.5.1
+
OpenID Connect server libraries for Spring and Spring Security.
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 26350803e..a950c29ea 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
@@ -17,10 +17,12 @@
package org.mitre.openid.connect.web;
import java.lang.reflect.Type;
+import java.sql.SQLIntegrityConstraintViolationException;
import java.text.ParseException;
import java.util.Collection;
import javax.persistence.PersistenceException;
+import org.eclipse.persistence.exceptions.DatabaseException;
import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.oauth2.model.ClientDetailsEntity.AuthMethod;
import org.mitre.oauth2.service.ClientDetailsEntityService;
@@ -246,10 +248,17 @@ public class ClientAPI {
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;
+ Throwable cause = e.getCause();
+ if (cause instanceof DatabaseException) {
+ Throwable databaseExceptionCause = cause.getCause();
+ if(databaseExceptionCause instanceof SQLIntegrityConstraintViolationException) {
+ logger.error("apiAddClient failed; duplicate client id entry found: {}", client.getClientId());
+ 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;
+ }
+ }
+ throw e;
}
}