[keycloak-dev] Import Realm when running Keycloak server from Maven

Scott Rossillo srossillo at smartling.com
Thu May 14 21:59:11 EDT 2015


Hi,

We’re trying to run Keycloak from Maven using:

mvn -f testsuite/integration/pom.xml exec:java -Pkeycloak-server -Dkeycloak.port=8080

For development purposes. We saw in the code that you can specify a realm to import. It seems either:

mvn -f testsuite/integration/pom.xml exec:java -Pkeycloak-server -Dkeycloak.port=8080 -Dimport=/path/to/realm.json

should work. However, we get an exception:

21:58:22,028 DEBUG [org.keycloak.models.utils.RepresentationToModel] Create client: {0}security-admin-console
[WARNING] 
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.keycloak.models.ModelDuplicateException: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Unique index or primary key violation: "UK_B71CJLBENV945RB6GCON438AT_INDEX_4 ON PUBLIC.CLIENT(REALM_ID, CLIENT_ID)"; SQL statement:
insert into CLIENT (BASE_URL, BEARER_ONLY, CLIENT_ID, CONSENT_REQUIRED, DIRECT_GRANTS_ONLY, ENABLED, FRONTCHANNEL_LOGOUT, FULL_SCOPE_ALLOWED, MANAGEMENT_URL, NAME, NODE_REREG_TIMEOUT, NOT_BEFORE, PROTOCOL, PUBLIC_CLIENT, REALM_ID, SECRET, SURROGATE_AUTH_REQUIRED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-168]
	at org.keycloak.connections.jpa.PersistenceExceptionConverter.convert(PersistenceExceptionConverter.java:40)
	at org.keycloak.connections.jpa.PersistenceExceptionConverter.invoke(PersistenceExceptionConverter.java:34)
	at com.sun.proxy.$Proxy61.flush(Unknown Source)
	at org.keycloak.models.jpa.RealmAdapter.addClient(RealmAdapter.java:643)
	at org.keycloak.models.utils.RepresentationToModel.createClient(RepresentationToModel.java:525)
	at org.keycloak.models.utils.RepresentationToModel.createClients(RepresentationToModel.java:509)
	at org.keycloak.models.utils.RepresentationToModel.importRealm(RepresentationToModel.java:136)
	at org.keycloak.services.managers.RealmManager.importRealm(RealmManager.java:252)
	at org.keycloak.testsuite.KeycloakServer.importRealm(KeycloakServer.java:250)
	at org.keycloak.testsuite.KeycloakServer.importRealm(KeycloakServer.java:230)
	at org.keycloak.testsuite.KeycloakServer.bootstrapKeycloakServer(KeycloakServer.java:189)
	at org.keycloak.testsuite.KeycloakServer.main(KeycloakServer.java:108)
	... 6 more
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Unique index or primary key violation: "UK_B71CJLBENV945RB6GCON438AT_INDEX_4 ON PUBLIC.CLIENT(REALM_ID, CLIENT_ID)"; SQL statement:
insert into CLIENT (BASE_URL, BEARER_ONLY, CLIENT_ID, CONSENT_REQUIRED, DIRECT_GRANTS_ONLY, ENABLED, FRONTCHANNEL_LOGOUT, FULL_SCOPE_ALLOWED, MANAGEMENT_URL, NAME, NODE_REREG_TIMEOUT, NOT_BEFORE, PROTOCOL, PUBLIC_CLIENT, REALM_ID, SECRET, SURROGATE_AUTH_REQUIRED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-168]
	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361)
	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)
	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295)
	at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:976)
	at sun.reflect.GeneratedMethodAccessor273.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.keycloak.connections.jpa.PersistenceExceptionConverter.invoke(PersistenceExceptionConverter.java:32)
	... 16 more
Caused by: org.hibernate.exception.ConstraintViolationException: Unique index or primary key violation: "UK_B71CJLBENV945RB6GCON438AT_INDEX_4 ON PUBLIC.CLIENT(REALM_ID, CLIENT_ID)"; SQL statement:
insert into CLIENT (BASE_URL, BEARER_ONLY, CLIENT_ID, CONSENT_REQUIRED, DIRECT_GRANTS_ONLY, ENABLED, FRONTCHANNEL_LOGOUT, FULL_SCOPE_ALLOWED, MANAGEMENT_URL, NAME, NODE_REREG_TIMEOUT, NOT_BEFORE, PROTOCOL, PUBLIC_CLIENT, REALM_ID, SECRET, SURROGATE_AUTH_REQUIRED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-168]
	at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:128)
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
	at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
	at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
	at com.sun.proxy.$Proxy63.executeUpdate(Unknown Source)
	at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56)
	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2849)
	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3290)
	at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:80)
	at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:272)
	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:264)
	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:186)
	at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1081)
	at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:973)
	... 20 more
Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "UK_B71CJLBENV945RB6GCON438AT_INDEX_4 ON PUBLIC.CLIENT(REALM_ID, CLIENT_ID)"; SQL statement:
insert into CLIENT (BASE_URL, BEARER_ONLY, CLIENT_ID, CONSENT_REQUIRED, DIRECT_GRANTS_ONLY, ENABLED, FRONTCHANNEL_LOGOUT, FULL_SCOPE_ALLOWED, MANAGEMENT_URL, NAME, NODE_REREG_TIMEOUT, NOT_BEFORE, PROTOCOL, PUBLIC_CLIENT, REALM_ID, SECRET, SURROGATE_AUTH_REQUIRED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-168]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
	at org.h2.message.DbException.get(DbException.java:169)
	at org.h2.message.DbException.get(DbException.java:146)
	at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:81)
	at org.h2.index.TreeIndex.add(TreeIndex.java:62)
	at org.h2.table.RegularTable.addRow(RegularTable.java:121)
	at org.h2.command.dml.Insert.insertRows(Insert.java:124)
	at org.h2.command.dml.Insert.update(Insert.java:84)
	at org.h2.command.CommandContainer.update(CommandContainer.java:75)
	at org.h2.command.Command.executeUpdate(Command.java:230)
	at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156)
	at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142)
	at sun.reflect.GeneratedMethodAccessor271.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
	... 33 more

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-dev/attachments/20150514/72a0aa8a/attachment-0001.html 


More information about the keycloak-dev mailing list