fix: guard against null orgId in createAndInviteUser and createUserWithPassword

Vendor admins use global roles, not org roles — passing null orgId
would previously cause addUserToOrganization to call
/api/organizations/null/users and fail.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-27 14:48:00 +02:00
parent 022b6d9722
commit 0da1ffea7f

View File

@@ -222,9 +222,11 @@ public class LogtoManagementClient {
.retrieve() .retrieve()
.body(Map.class); .body(Map.class);
String userId = String.valueOf(userResp.get("id")); String userId = String.valueOf(userResp.get("id"));
addUserToOrganization(orgId, userId); if (orgId != null) {
if (roleId != null) { addUserToOrganization(orgId, userId);
assignOrganizationRole(orgId, userId, roleId); if (roleId != null) {
assignOrganizationRole(orgId, userId, roleId);
}
} }
return userId; return userId;
} catch (Exception e) { } catch (Exception e) {
@@ -233,7 +235,7 @@ public class LogtoManagementClient {
} }
} }
/** Create a user with username/password and add to org with role. */ /** Create a user with username/password and optionally add to org with role. */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public String createUserWithPassword(String username, String password, String orgId, String roleId) { public String createUserWithPassword(String username, String password, String orgId, String roleId) {
if (!isAvailable()) return null; if (!isAvailable()) return null;
@@ -246,9 +248,11 @@ public class LogtoManagementClient {
.retrieve() .retrieve()
.body(Map.class); .body(Map.class);
String userId = String.valueOf(userResp.get("id")); String userId = String.valueOf(userResp.get("id"));
addUserToOrganization(orgId, userId); if (orgId != null) {
if (roleId != null) { addUserToOrganization(orgId, userId);
assignOrganizationRole(orgId, userId, roleId); if (roleId != null) {
assignOrganizationRole(orgId, userId, roleId);
}
} }
log.info("Created user '{}' and added to org {} with role {}", username, orgId, roleId); log.info("Created user '{}' and added to org {} with role {}", username, orgId, roleId);
return userId; return userId;