Check that the underlying cause of the PersistenceException is caused by a duplicate entry.
parent
6fb26856a7
commit
ecb4a9ed53
|
@ -46,6 +46,11 @@
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-tx</artifactId>
|
<artifactId>spring-tx</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.persistence</groupId>
|
||||||
|
<artifactId>org.eclipse.persistence.core</artifactId>
|
||||||
|
<version>2.5.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<description>OpenID Connect server libraries for Spring and Spring Security.</description>
|
<description>OpenID Connect server libraries for Spring and Spring Security.</description>
|
||||||
|
|
|
@ -17,10 +17,12 @@
|
||||||
package org.mitre.openid.connect.web;
|
package org.mitre.openid.connect.web;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.sql.SQLIntegrityConstraintViolationException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
|
|
||||||
|
import org.eclipse.persistence.exceptions.DatabaseException;
|
||||||
import org.mitre.oauth2.model.ClientDetailsEntity;
|
import org.mitre.oauth2.model.ClientDetailsEntity;
|
||||||
import org.mitre.oauth2.model.ClientDetailsEntity.AuthMethod;
|
import org.mitre.oauth2.model.ClientDetailsEntity.AuthMethod;
|
||||||
import org.mitre.oauth2.service.ClientDetailsEntityService;
|
import org.mitre.oauth2.service.ClientDetailsEntityService;
|
||||||
|
@ -246,10 +248,17 @@ public class ClientAPI {
|
||||||
m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Unable to save client: " + e.getMessage());
|
m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Unable to save client: " + e.getMessage());
|
||||||
return JsonErrorView.VIEWNAME;
|
return JsonErrorView.VIEWNAME;
|
||||||
} catch (PersistenceException e) {
|
} catch (PersistenceException e) {
|
||||||
logger.error("Unable to save client. Duplicate client id entry found: {}", e.getMessage());
|
Throwable cause = e.getCause();
|
||||||
m.addAttribute(HttpCodeView.CODE, HttpStatus.CONFLICT);
|
if (cause instanceof DatabaseException) {
|
||||||
m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Unable to save client. Duplicate client id entry found: " + client.getClientId());
|
Throwable databaseExceptionCause = cause.getCause();
|
||||||
return JsonErrorView.VIEWNAME;
|
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…
Reference in New Issue