我想在 keycloak 中实现交易功能。我正在创建一个用户,然后是一个角色并将该角色与用户相关联。我希望在一个事务中完成所有这些操作。这是我的代码片段:
Keycloak keyClk = getKeyCloakInstance();
UserRepresentation userRepresentation = new UserRepresentation();
userRepresentation.setEnabled(user.getStatus());
userRepresentation.setUsername(user.getUserId() != null ? user.getUserId() : "");
userRepresentation.setEmail(user.getEmail());
RealmResource realmResource = keyClk.realm(KeyCloakUtil.realmName);
UsersResource usersRessource = realmResource.users();
Response response = usersRessource.create(userRepresentation);
List<Role> roleList = user.getRoles();
if (!roleList.isEmpty() || roleList != null) {
createUserRoleList(user.getUserId(), roleList, KeyCloakUtil.clientId, KeyCloakConstant.ACTION_ADD);
}