Getting Exception in adding user

Hi,

I am using Camunda 7.7.0 release.

I want to create a user and provide authorization for camunda-admin group.
I am writing java api to achieve the same.

My code

adminUser = identityService.newUser(“test123”);
adminUser.setFirstName(“test123”);
adminUser.setLastName(“test123”);
adminUser.setEmail("test123@gmail.com");
adminUser.setPassword(“test123”);
identityService.saveUser(adminUser);

identityService.createMembership(“test123”, CAMUNDA_ADMIN);

This code is correctly adding the user and authorization in the backend. But after execution it shows the below exception

org.camunda.bpm.engine.ProcessEngineException: ENGINE-03004 Exception while executing Database Operation ‘INSERT AuthorizationEntity[18752bae-4149-11e8-838e-ea3b20524153]’ with message ’ ### Error updating database. Cause: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: “ACT_UNIQ_AUTH_USER_INDEX_6 ON PUBLIC.ACT_RU_AUTHORIZATION(TYPE_, USER_ID_, RESOURCE_TYPE_, RESOURCE_ID_) VALUES (1, ‘test123’, 1, ‘test123’, 76)”; SQL statement: insert into ACT_RU_AUTHORIZATION ( ID_, TYPE_, GROUP_ID_, USER_ID_, RESOURCE_TYPE_, RESOURCE_ID_, PERMS_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, 1 ) [23505-190] ### The error may involve org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity.insertAuthorization-Inline ### The error occurred while setting parameters ### SQL: insert into ACT_RU_AUTHORIZATION ( ID_, TYPE_, GROUP_ID_, USER_ID_, RESOURCE_TYPE_, RESOURCE_ID_, PERMS_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, 1 ) ### Cause: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: “ACT_UNIQ_AUTH_USER_INDEX_6 ON PUBLIC.ACT_RU_AUTHORIZATION(TYPE_, USER_ID_, RESOURCE_TYPE_, RESOURCE_ID_) VALUES (1, ‘test123’, 1, ‘test123’, 76)”; SQL statement: insert into ACT_RU_AUTHORIZATION ( ID_, TYPE_, GROUP_ID_, USER_ID_, RESOURCE_TYPE_, RESOURCE_ID_, PERMS_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, 1 ) [23505-190]’. Flush summary: [ INSERT AuthorizationEntity[18752bae-4149-11e8-838e-ea3b20524153] INSERT UserEntity[test123] ]
org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationException(EnginePersistenceLogger.java:115)
org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:305)

Kindly provide your help in this code.

Thanks
Senthil

@senlog80 take a look at: https://github.com/DigitalState/camunda-administrative-user-plugin/blob/master/src/main/java/io/digitalstate/camunda/plugins/AdministrativeUserPlugin.java#L92-L127 for a working example of generating a user as part of the admin group (and creating the admin group as well if you like).

1 Like

Thanks Stephen, I will check this link.

Thanks
Senthil