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,10 +222,12 @@ 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"));
if (orgId != null) {
addUserToOrganization(orgId, userId); addUserToOrganization(orgId, userId);
if (roleId != null) { if (roleId != null) {
assignOrganizationRole(orgId, userId, roleId); assignOrganizationRole(orgId, userId, roleId);
} }
}
return userId; return userId;
} catch (Exception e) { } catch (Exception e) {
log.error("Failed to create and invite user: {}", e.getMessage()); log.error("Failed to create and invite user: {}", e.getMessage());
@@ -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,10 +248,12 @@ 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"));
if (orgId != null) {
addUserToOrganization(orgId, userId); addUserToOrganization(orgId, userId);
if (roleId != null) { if (roleId != null) {
assignOrganizationRole(orgId, userId, roleId); 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;
} catch (Exception e) { } catch (Exception e) {