We are trying to authenticate an existing user via Keycloak so implemented
a custom SPI and added the custom SPI as User Federation
"Getting a different object with the same identifier value was already
associated with the session exception" when trying to add a user with role
from a custom SPI to Keycloak database
Please find the exception message
*Caused by: javax.persistence.EntityExistsException: A different object
with the same identifier value was already associated with the session :
[org.keycloak.storage.jpa.entity.FederatedUserRoleMappingEntity#org.keycloak.storage.jpa.entity.FederatedUserRoleMappingEntity$Key@e3a03493]*
We are trying to use Keycloak *6.0.1* for authentication and using the
custom provider to authenticate the users the user details are are in
custom provider using Storage provider SPI
@Override
public UserModel getUserByUsername(String username, RealmModel realm) {
UserModel userModel = new UserAdapter(session, realm, model,
repository.findUserByUsernameOrEmail(username));
RoleModel roleModel = realm.getRole("user");
* // Adding the 'user' RoleModel to the UserModel object*
userModel.grantRole(roleModel);
return userModel;
}
The exception is happening when adding the "user" role and the realm this
user is trying to add has role 'user' when i don't add the user role web
application is redirected to keycloak web page for adding the user ....
Realm containing the user role also there are no existing users fin the
realm
[image: Screen Shot 2019-07-01 at 4.46.39 PM.png]
Newbie to Keycloak. Appreciate the community guidance in resolving the
issue please.
Thanks,
Aditya
Show replies by date