Check that the underlying cause of the PersistenceException is caused by a duplicate entry.

pull/1046/merge
Trung Nguyen 9 years ago committed by Justin Richer
parent 6fb26856a7
commit ecb4a9ed53

@ -46,6 +46,11 @@
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
<description>OpenID Connect server libraries for Spring and Spring Security.</description>

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

Loading…
Cancel
Save