Skip to content

Conversation

@BimsaraBodaragama
Copy link
Member

@BimsaraBodaragama BimsaraBodaragama commented Dec 8, 2025

Purpose

This PR introduces a new versioned User Sharing API (/api/server/v2/users/**) to address functional and frontend limitations of the existing /api/server/v1/users/** endpoints.
The new API aligns conceptually and structurally with the Application Sharing API and enables incremental role assignment and selective sharing across hierarchical organizations.

Goals

  • Provide a versioned User Sharing API with a consistent design following Application Sharing patterns.
  • Support optional role assignment through a roleAssignment object with supported modes: NONE | SELECTED.
  • Enable incremental role modifications via PATCH operations.
  • Support paginated retrieval of shared organizations and per-organization role visibility.
  • Maintain backward compatibility for existing /v1 integrations.

Approach

  • Added new endpoints under /api/server/v2/users/**:
    POST   /users/share
    POST   /users/share-with-all
    POST   /users/unshare
    POST   /users/unshare-with-all
    PATCH  /users/share
    GET    /users/{userId}/share
    
  • Model roleAssignment to reflect role assignment semantics in sub-organizations.
  • Allowed the role assignment modes NONE and SELECTED, consistent with the Application Sharing model.
  • Introduced SCIM-style incremental PATCH for add/remove of roles.
  • Updated OpenAPI specification and supporting backend controller logic.
  • Ensured no behavioural change to existing v1 implementation.

Related PRs

Related Issues

Summary by CodeRabbit

  • New Features

    • User Sharing Management API v2 released: share/unshare (selected or all orgs), patch sharing, and list a user’s shared organizations with pagination, filtering and recursion; server-side v2 implementation and wiring.
  • Documentation

    • Added OpenAPI v3 spec for User Sharing v2 with schemas, examples, security schemes, scopes and responses.
  • Chores

    • Added v2 module to the build, bumped related module/property versions, added V2 service accessor, and introduced user-share patch error codes/constants.

✏️ Tip: You can customize this high-level summary in your review settings.

@BimsaraBodaragama BimsaraBodaragama self-assigned this Dec 8, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 8, 2025

Walkthrough

Adds a new v2 organization user-sharing module: Maven module registration and POM, OpenAPI v3 specification, generated API types and service layer (core, factory, impl), common-holder/constants updates to support V2, and version/property bumps in parent POMs.

Changes

Cohort / File(s) Summary
Module POMs & root property
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/pom.xml, components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/pom.xml, pom.xml
Added new v2 module POM and registered it in parent <modules>; declared provided dependencies and build helpers for generated sources; updated org.wso2.carbon.identity.organization.management.version (2.0.8 → 2.0.43).
OpenAPI spec (v2)
.../v2/src/main/resources/organization-user-share-v2.yaml
New OpenAPI v3 definition for v2 endpoints (POST/PATCH share, POST share-with-all/unshare/unshare-with-all, GET user shared organizations), security schemes, schemas, pagination, examples and operation scopes.
API core implementation
.../v2/src/main/java/.../v2/core/UsersApiServiceCore.java
New core service implementing share/unshare/patch/list endpoints: input validation, API↔service model mapping, pagination/link construction, backend delegation to V2 handler, and standardized error/response building.
Factory & API impl
.../v2/src/main/java/.../v2/factories/UsersApiServiceCoreFactory.java, .../v2/src/main/java/.../v2/impl/UsersApiServiceImpl.java
Factory eagerly initializes singleton UsersApiServiceCore by fetching UserSharingPolicyHandlerServiceV2 from the holder; API impl delegates all endpoints to core and surfaces init failures as runtime exceptions.
Common module — holder, constants & pom
.../common/src/main/java/.../UserSharingMgtServiceHolder.java, .../common/src/main/java/.../constants/UserSharingMgtConstants.java, .../common/pom.xml
Added getUserSharingPolicyHandlerServiceV2() accessor and import; added RESPONSE_DETAIL_USER_SHARE_PATCH constant and new ErrorMessage enum entries (60005–60010); bumped common parent version to 1.3.229-SNAPSHOT.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API as UsersApiServiceImpl
    participant Factory as UsersApiServiceCoreFactory
    participant Core as UsersApiServiceCore
    participant Handler as UserSharingPolicyHandlerServiceV2
    participant Holder as UserSharingMgtServiceHolder

    note over Factory,Holder: eager static initialization at class load
    Factory->>Holder: getUserSharingPolicyHandlerServiceV2()
    Holder-->>Factory: UserSharingPolicyHandlerServiceV2
    Factory->>Core: new UsersApiServiceCore(handler)

    Client->>API: HTTP request (e.g., POST /users/share)
    API->>Core: delegate request
    Core->>Handler: validate & execute operation
    Handler-->>Core: result / error
    Core->>API: build HTTP response (202/200/error)
    API-->>Client: HTTP response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing extra attention:
    • UsersApiServiceCore: patch handling logic, request→DO mapping, pagination link construction, and error mapping.
    • UsersApiServiceCoreFactory: eager static initialization when V2 handler is absent (exception semantics).
    • OpenAPI YAML vs generated DTOs: ensure shape and examples align with generated code.
    • New error codes/messages for clarity and uniqueness.
    • POM dependency/version bumps for transitive compatibility.

Poem

🐰 I nibble on specs and hop through code bright,
A v2 YAML burrow and new module take flight,
Factories plant roots, the core hums soft and spry,
Requests hop in, responses bound swiftly by,
A tiny rabbit cheers — shared users leap high!

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 79.07% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ⚠️ Warning The PR description covers Purpose, Goals, and Approach comprehensively with endpoint details and related PRs, but lacks critical sections required by the template. Add mandatory sections: Developer Checklist, Release notes, Documentation, Security checks, Automation tests, and Test environment details. These are essential for code review and release management.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Introduce User Sharing API v2' is concise, clear, and directly describes the main change in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1 Y #1044 (comment)
#### Log Improvement Suggestion No: 2 Y #1044 (comment)
#### Log Improvement Suggestion No: 3 Y #1044 (comment)
#### Log Improvement Suggestion No: 4 Y #1044 (comment)
#### Log Improvement Suggestion No: 5 Y #1044 (comment)
#### Log Improvement Suggestion No: 6 Y #1044 (comment)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java (1)

30-49: Static initializer hides the intended IllegalStateException from callers

Throwing IllegalStateException in the static block will surface to callers as ExceptionInInitializerError, so the IllegalStateException catch in UsersApiServiceImpl will never see it. If you want the API layer to consistently get IllegalStateException from the factory, consider moving the null‑check and construction into getUsersApiServiceCore() (lazy init) instead of the static block.

One possible refactor:

-    private static final UsersApiServiceCore SERVICE;
-
-    static {
-        UserSharingPolicyHandlerService userSharingPolicyHandlerService = UserSharingMgtServiceHolder
-                .getUserSharingPolicyHandlerService();
-        if (userSharingPolicyHandlerService == null) {
-            throw new IllegalStateException("UserSharingPolicyHandlerService is not available from the OSGi context.");
-        }
-        SERVICE = new UsersApiServiceCore(userSharingPolicyHandlerService);
-    }
+    private static volatile UsersApiServiceCore service;
@@
-    public static UsersApiServiceCore getUsersApiServiceCore() {
-
-        return SERVICE;
-    }
+    public static UsersApiServiceCore getUsersApiServiceCore() {
+
+        if (service == null) {
+            synchronized (UsersApiServiceCoreFactory.class) {
+                if (service == null) {
+                    UserSharingPolicyHandlerService userSharingPolicyHandlerService =
+                            UserSharingMgtServiceHolder.getUserSharingPolicyHandlerService();
+                    if (userSharingPolicyHandlerService == null) {
+                        throw new IllegalStateException(
+                                "UserSharingPolicyHandlerService is not available from the OSGi context.");
+                    }
+                    service = new UsersApiServiceCore(userSharingPolicyHandlerService);
+                }
+            }
+        }
+        return service;
+    }
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java (1)

43-50: Constructor’s IllegalStateException catch won’t see static‑init failures from the factory

Given the current factory implementation, a missing UserSharingPolicyHandlerService will throw IllegalStateException from a static initializer, which reaches this constructor as ExceptionInInitializerError, bypassing the IllegalStateException catch.

If you don’t refactor the factory, consider broadening the catch here; if you do refactor as suggested in the factory comment, this constructor will then work as intended.

Example if you keep the static initializer:

-        try {
-            this.usersApiServiceCore = UsersApiServiceCoreFactory.getUsersApiServiceCore();
-        } catch (IllegalStateException e) {
-            throw new RuntimeException(ERROR_INITIATING_USERS_API_SERVICE.getMessage(), e);
-        }
+        try {
+            this.usersApiServiceCore = UsersApiServiceCoreFactory.getUsersApiServiceCore();
+        } catch (IllegalStateException | ExceptionInInitializerError e) {
+            throw new RuntimeException(ERROR_INITIATING_USERS_API_SERVICE.getMessage(), e);
+        }
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml (3)

455-465: Unbounded userIds array may be problematic; consider adding maxItems

UserCriteria.userIds is required but unconstrained in size. For bulk operations like share/unshare, this can invite very large payloads and DoS‑type scenarios. If the backend already enforces a sensible cap, it’s worth reflecting that here with a maxItems (and optionally minItems) so clients have a clear contract.

For example (adjust the limit to match server behavior):

     userIds:
       type: array
       description: List of user IDs.
       items:
         type: string
+      maxItems: 1000

435-449: Clarify that BasicAuth/OAuth2 credentials must only be used over TLS

Static analysis flagged the securitySchemes because HTTP auth can expose credentials over cleartext if used on plain HTTP. Your examples and OAuth2 URLs already use https, but the spec itself doesn’t state the TLS requirement.

I’d recommend explicitly documenting that these endpoints are only supported over HTTPS (and that HTTP is not allowed in production), to satisfy tooling and avoid misconfiguration.


753-765: Align Error.code example prefix with actual error prefix

The Error.code example uses "US-00000", while UserSharingMgtConstants.ERROR_PREFIX is "USM-". To avoid confusion for integrators, it’s better if the example matches the real prefix.

-        code:
-          type: string
-          example: "US-00000"
+        code:
+          type: string
+          example: "USM-00000"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73ac434 and 2b99e3d.

⛔ Files ignored due to path filters (20)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/UsersApi.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/UsersApiService.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceFactory.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/Error.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/Link.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/ProcessSuccessResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleAssignment.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleShareConfig.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleShareConfigAudience.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/SharingMode.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserCriteria.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserOrgShareConfig.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserShareAllRequestBody.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserShareSelectedRequestBody.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserSharedOrganization.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserSharedOrganizationsResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserSharingPatchOperation.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserSharingPatchRequest.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserUnshareAllRequestBody.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserUnshareSelectedRequestBody.java is excluded by !**/gen/**
📒 Files selected for processing (6)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/pom.xml (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/pom.xml (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java (3)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1)
  • UsersApiServiceCore (35-82)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java (1)
  • UsersApiServiceCoreFactory (28-50)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (1)
  • UserSharingMgtConstants (24-101)
🪛 Checkov (3.2.334)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml

[medium] 460-465: Ensure that arrays have a maximum number of items

(CKV_OPENAPI_21)


[high] 438-441: Ensure that security schemes don't allow cleartext credentials over unencrypted channel - version 3.x.y files

(CKV_OPENAPI_3)

🔇 Additional comments (2)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/pom.xml (1)

31-35: V2 module wiring in parent POM looks consistent

Adding the v2 module alongside v1 and common matches the expected multi‑module structure for versioned APIs.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/pom.xml (1)

31-172: POM configuration for the v2 module looks fine; just ensure generated sources are present

Dependencies and build plugins align with other JAX‑RS/OpenAPI modules (provided scopes, build-helper-maven-plugin for src/gen/java, Java 8 compiler settings). From a POM perspective this looks good.

Just make sure that the generated sources for src/gen/java (e.g., UsersApiService interface) are either checked in or produced by your build pipeline, since the openapi‑generator plugin here is commented out.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new versioned User Sharing API (v2) under /api/server/v2/users/** to address limitations of the existing v1 endpoints. The new API follows the Application Sharing pattern and enables incremental role assignment with selective sharing across hierarchical organizations.

Key Changes:

  • Added 6 new REST endpoints for user sharing operations (share, unshare, patch, and query)
  • Introduced role assignment modes (NONE, SELECTED) with SCIM-style PATCH semantics for incremental updates
  • Implemented paginated retrieval of shared organizations with per-organization role visibility

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
pom.xml (parent) Added v2 module to the parent POM build configuration
organization-user-share-v2.yaml OpenAPI 3.0 specification defining the v2 API endpoints, schemas, and examples
UsersApiServiceImpl.java Implementation delegating API calls to the core service layer
UsersApiServiceCore.java Core business logic with placeholder methods for all v2 operations
UsersApiServiceCoreFactory.java Factory pattern for initializing the core service with OSGi dependencies
Model classes (20 files) Auto-generated DTOs from OpenAPI spec for request/response handling
UsersApi.java JAX-RS resource class with endpoint mappings and validation
UsersApiService.java Service interface defining the API contract
UsersApiServiceFactory.java Factory for service instantiation
pom.xml (v2 module) Maven configuration with dependencies and build plugins

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 28 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@BimsaraBodaragama BimsaraBodaragama marked this pull request as ready for review December 19, 2025 06:04
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pom.xml (1)

967-968: Duplicate property definition for carbon.identity.framework.version.

Lines 967 and 968 both define carbon.identity.framework.version. Maven will use the last declared value (7.8.610), making the SNAPSHOT declaration on line 967 effectively dead code. If the intent is to use 7.8.610, remove the duplicate SNAPSHOT line to avoid confusion.

🔎 Proposed fix
-        <carbon.identity.framework.version>7.8.596-SNAPSHOT</carbon.identity.framework.version>
         <carbon.identity.framework.version>7.8.610</carbon.identity.framework.version>
🧹 Nitpick comments (2)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1)

296-300: Consider sanitizing or omitting userId from error logs.

The userId is logged directly in the error message on line 298. Depending on your logging policy and whether userId could contain PII or be used for correlation attacks, consider using a hashed/masked value or omitting it from production logs.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml (1)

478-484: Consider adding maxItems constraint to prevent unbounded array requests.

The userIds array (and other arrays like organizations, orgIds, Operations) don't specify a maximum number of items. This could allow clients to submit extremely large payloads, potentially causing performance issues or DoS.

🔎 Proposed fix for UserCriteria
     UserCriteria:
       type: object
       description: Criteria for selecting users to share/unshare.
       properties:
         userIds:
           type: array
           description: List of user IDs.
+          maxItems: 100
           items:
             type: string
       required:
         - userIds

Apply similar constraints to other arrays (organizations, orgIds, Operations, roles) based on expected usage limits.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b99e3d and 795deca.

⛔ Files ignored due to path filters (20)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/UsersApi.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/UsersApiService.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceFactory.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/Error.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/Link.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/ProcessSuccessResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleAssignment.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleShareConfig.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleShareConfigAudience.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/SharingMode.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserCriteria.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserOrgShareConfig.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserShareAllRequestBody.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserShareSelectedRequestBody.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserSharedOrganization.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserSharedOrganizationsResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserSharingPatchOperation.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserSharingPatchRequest.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserUnshareAllRequestBody.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/UserUnshareSelectedRequestBody.java is excluded by !**/gen/**
📒 Files selected for processing (9)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/pom.xml (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/UserSharingMgtServiceHolder.java (3 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (2 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/pom.xml (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml (1 hunks)
  • pom.xml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/pom.xml
🧰 Additional context used
🧬 Code graph analysis (2)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java (2)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/UserSharingMgtServiceHolder.java (1)
  • UserSharingMgtServiceHolder (28-67)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1)
  • UsersApiServiceCore (92-869)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java (3)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1)
  • UsersApiServiceCore (92-869)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java (1)
  • UsersApiServiceCoreFactory (30-58)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (1)
  • UserSharingMgtConstants (24-107)
🪛 Checkov (3.2.334)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml

[medium] 479-484: Ensure that arrays have a maximum number of items

(CKV_OPENAPI_21)


[high] 457-460: Ensure that security schemes don't allow cleartext credentials over unencrypted channel - version 3.x.y files

(CKV_OPENAPI_3)

🔇 Additional comments (9)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/pom.xml (1)

21-26: Parent version update looks consistent.

The parent version update to 1.3.229-SNAPSHOT aligns with the multi-module build structure for the new v2 API module.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (1)

33-34: New constants for patch operation are well-structured.

The RESPONSE_DETAIL_USER_SHARE_PATCH constant and INVALID_USER_SHARE_PATCH_REQUEST_BODY error enum follow the existing patterns and maintain sequential error codes. The error messages are clear and actionable.

Also applies to: 65-68

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/UserSharingMgtServiceHolder.java (1)

41-46: V2 service holder follows the established V1 pattern.

The implementation mirrors the existing V1 pattern using the initialization-on-demand holder idiom, ensuring thread-safe lazy initialization. The structure is consistent with the existing codebase.

Note that if the OSGi service is not registered, getUserSharingPolicyHandlerServiceV2() will return null. Ensure callers handle this case appropriately (the factory should validate this).

Also applies to: 57-66

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (2)

92-105: Constructor and dependency injection look good.

The constructor properly accepts the V2 service dependency and assigns it to a final field, following good practices for immutability.


709-735: Pagination link building is well-implemented.

The cursor-based pagination with Base64-encoded cursors follows good practices. The fallback to relative URLs when UriInfo is unavailable ensures robustness.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml (2)

456-468: BasicAuth security scheme is acceptable with HTTPS.

The static analysis flagged BasicAuth (CKV_OPENAPI_3), but since the server URL explicitly uses https://, credentials are encrypted in transit. This is acceptable, though OAuth2 is the preferred mechanism for production use.


1-30: OpenAPI specification structure and versioning look good.

The v2 API spec is well-structured with clear descriptions, proper versioning in the server URL, and appropriate security schemes.

pom.xml (1)

1001-1002: Version bump to 2.0.43 should be verified against the artifact repository and V2 API requirements.

The update to org.wso2.carbon.identity.organization.management.version from its previous version to 2.0.43 requires verification that:

  • Version 2.0.43 is a released version in the WSO2 repository
  • It includes the V2 service interfaces referenced in the code changes

Additionally, review the pom.xml for the duplicate carbon.identity.framework.version property definition mentioned in the original analysis.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java (1)

59-95: LGTM: Clean delegation pattern.

The implementation correctly delegates all API operations to the core service, maintaining a clear separation between the API layer and business logic.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (1)

65-75: Consider aligning error naming conventions for consistency.

The first error constant (line 65) follows the established INVALID_ prefix pattern used by all existing client validation errors (60000-60004). However, the two subsequent errors (lines 69, 72) introduce an ERROR_ prefix, creating inconsistency.

Additionally, ERROR_MISSING_USER_CRITERIA is generic and doesn't indicate its specific context (patch operations). For clarity and consistency with operation-specific error names (e.g., INVALID_SELECTIVE_USER_SHARE_REQUEST_BODY), consider:

  • INVALID_USER_SHARE_PATCH_MISSING_USER_CRITERIA
  • INVALID_USER_SHARE_PATCH_PATH

This maintains the INVALID_ prefix pattern and makes the context explicit.

Proposed naming alignment
-        ERROR_MISSING_USER_CRITERIA("60006",
-                "Missing user criteria in the request body.",
-                "The user criteria is missing in the request body. Please provide the user criteria to proceed."),
-        ERROR_UNSUPPORTED_USER_SHARE_PATCH_PATH("60007",
-                "Unsupported user share patch path.",
+        INVALID_USER_SHARE_PATCH_MISSING_USER_CRITERIA("60006",
+                "Missing user criteria in patch request body.",
+                "The user criteria is missing in the patch request body. Please provide the user criteria to proceed."),
+        INVALID_USER_SHARE_PATCH_PATH("60007",
+                "Invalid user share patch path.",
                 "The provided patch path to update attributes of shared user is not supported. " +
                         "Please provide a valid patch path."),
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml (2)

382-390: Add enum constraint to attributes parameter for validation.

The attributes parameter description states "Supported values: roles, sharingMode" but the schema lacks an enum constraint. Without this, the OpenAPI spec accepts any string value (e.g., attributes=invalidValue), deferring validation to runtime.

A previous review suggested adding both values to an enum, which would provide client-side validation and better API documentation.

🔎 Proposed fix
         - in: query
           name: attributes
           required: false
           schema:
             type: string
+            enum:
+              - roles
+              - sharingMode
           example: "roles"
           description: |-
             Specifies the required parameters in the response.
             Supported values: `roles`, `sharingMode`.

472-482: Consider adding maxItems constraint to userIds array.

Static analysis flags that the userIds array lacks a maxItems constraint, which could allow arbitrarily large batch requests that might cause performance issues or DoS vulnerabilities.

While backend validation likely enforces reasonable limits, adding maxItems to the schema provides:

  • Early client-side validation
  • Clear documentation of API limits
  • Defense-in-depth
Example constraint
       properties:
         userIds:
           type: array
           description: List of user IDs.
+          maxItems: 100
           items:
             type: string

Adjust the limit based on your backend's batch processing capabilities.

Based on static analysis hints.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 795deca and 64a0a4c.

⛔ Files ignored due to path filters (1)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/UsersApi.java is excluded by !**/gen/**
📒 Files selected for processing (4)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (2 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java (1 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/impl/UsersApiServiceImpl.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-19T07:42:30.680Z
Learnt from: BimsaraBodaragama
Repo: wso2/identity-api-server PR: 1044
File: components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java:35-47
Timestamp: 2025-12-19T07:42:30.680Z
Learning: In the organization user sharing management API modules, factory classes use eager static initialization (static blocks) to fail fast if required OSGi services are not available. This is an intentional design pattern for consistency across API service factories in this module.

Applied to files:

  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java
🧬 Code graph analysis (1)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (3)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/Link.java (1)
  • Link (33-118)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleShareConfigAudience.java (1)
  • RoleShareConfigAudience (33-124)
components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/SharingMode.java (1)
  • SharingMode (34-157)
🪛 Checkov (3.2.334)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml

[medium] 477-482: Ensure that arrays have a maximum number of items

(CKV_OPENAPI_21)


[high] 455-458: Ensure that security schemes don't allow cleartext credentials over unencrypted channel - version 3.x.y files

(CKV_OPENAPI_3)

🔇 Additional comments (5)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (1)

33-34: LGTM! Consistent success message constant.

The new constant follows the existing naming and messaging pattern for async operation responses.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (2)

104-107: LGTM! Clean dependency injection and error handling.

The constructor-based dependency injection and consistent error handling pattern across all public methods effectively distinguish client errors (400) from server errors (500). The validation logic and exception handling align well with REST API best practices.

Also applies to: 118-139, 148-168


714-779: Well-designed pagination link builder with proper fallback.

The pagination implementation correctly handles both absolute URI construction (using JAX-RS UriInfo) and falls back to relative link building when URI context is unavailable. The cursor encoding and proper query parameter handling ensure robust pagination support.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/resources/organization-user-share-v2.yaml (2)

454-466: BasicAuth security scheme requires HTTPS enforcement.

Static analysis correctly flags that BasicAuth transmits credentials in cleartext (base64-encoded). While the server URL specifies https:// (line 20), the OpenAPI spec doesn't enforce HTTPS at the scheme level.

In production deployments, ensure TLS termination at the API gateway/reverse proxy level is mandatory for endpoints using BasicAuth. Consider documenting this requirement in the API description or deployment guides.

Based on static analysis hints.


1-26: Excellent API design aligned with Application Sharing patterns.

The v2 API successfully addresses the stated objectives:

  • Clear separation of selective vs. all-org sharing operations
  • SCIM-style PATCH operations for incremental role updates
  • Cursor-based pagination for shared organization listing
  • Consistent 202 Accepted responses for async processing
  • Comprehensive request/response schemas with examples

The alignment with the Application Sharing model (mentioned in lines 7, 330) provides consistency across the platform, improving developer experience.

Also applies to: 31-175, 692-753

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1)

122-125: Consider adding more context to debug logs.

The debug logs currently only log the tenant domain. Based on past reviewer feedback, consider including additional context such as the number of users being shared, organizations involved, or operation type to aid troubleshooting.

💡 Example enhancement
 if (LOG.isDebugEnabled()) {
-    LOG.debug("Selective user sharing API v2 invoked form tenantDomain: " +
-            PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
+    LOG.debug("Selective user sharing API v2 invoked for tenantDomain: " +
+            PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() +
+            ", targetOrganizations: " + userShareSelectedRequestBody.getOrganizations().size());
 }

Also applies to: 154-157, 185-188, 217-220, 249-252

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64a0a4c and 1bc3ef4.

📒 Files selected for processing (2)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (2 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: BimsaraBodaragama
Repo: wso2/identity-api-server PR: 1044
File: components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java:35-47
Timestamp: 2025-12-19T07:42:30.680Z
Learning: In the organization user sharing management API modules, factory classes use eager static initialization (static blocks) to fail fast if required OSGi services are not available. This is an intentional design pattern for consistency across API service factories in this module.
🔇 Additional comments (4)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (2)

33-34: LGTM! Well-aligned constant for PATCH operations.

The new response constant follows the established naming and messaging patterns, clearly indicating the asynchronous nature of the patch operation.


65-79: LGTM! Comprehensive error coverage for PATCH validation.

The four new error enums provide clear, granular validation messages for the V2 PATCH operations. The sequential error codes (60005-60008), descriptive naming, and actionable error descriptions follow the existing conventions consistently.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (2)

106-109: LGTM: Constructor properly initializes the service dependency.

The constructor follows the dependency injection pattern and aligns with the factory's eager initialization approach mentioned in the learnings.


759-792: LGTM: URI building and encoding are implemented correctly.

The pagination link construction gracefully handles missing UriInfo by falling back to relative links, and URL encoding properly handles the guaranteed UTF-8 support with appropriate exception handling.

Also applies to: 839-847

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (2)

329-330: Remove self-explanatory comments.

Several comments throughout the DTO building methods simply restate what the code does (e.g., "Set user criteria", "Set policy and roles"). These comments don't add value and can be safely removed for cleaner code.

Based on learnings, the reviewer previously requested removal of comments where code is self-explanatory.

Also applies to: 334-334, 360-361, 365-366, 384-385, 389-389, 406-407


811-836: Consider refactoring manual URL construction to reduce fragility.

The buildRelativeSharedOrgsPageLink method constructs URLs through string concatenation and manual query parameter building. While urlEncode is used, this approach is more error-prone than using a proper URL builder. If UriInfo is unavailable in certain contexts, consider alternatives like:

  • Ensuring UriInfo is always available through dependency injection
  • Using UriBuilder directly instead of string concatenation
  • Centralizing URL construction logic to avoid duplication
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc3ef4 and 2ddaf94.

📒 Files selected for processing (2)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (2 hunks)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: BimsaraBodaragama
Repo: wso2/identity-api-server PR: 1044
File: components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java:35-47
Timestamp: 2025-12-19T07:42:30.680Z
Learning: In the organization user sharing management API modules, factory classes use eager static initialization (static blocks) to fail fast if required OSGi services are not available. This is an intentional design pattern for consistency across API service factories in this module.
📚 Learning: 2025-12-19T07:42:30.680Z
Learnt from: BimsaraBodaragama
Repo: wso2/identity-api-server PR: 1044
File: components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java:35-47
Timestamp: 2025-12-19T07:42:30.680Z
Learning: In the organization user sharing management API modules, factory classes use eager static initialization (static blocks) to fail fast if required OSGi services are not available. This is an intentional design pattern for consistency across API service factories in this module.

Applied to files:

  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java
🔇 Additional comments (2)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (2)

33-34: LGTM!

The new response constant follows the established pattern and provides a clear success message for the patch operation.


65-82: LGTM!

The new error message enum entries are well-structured and follow the established patterns in this file. The error codes are properly sequential (60005-60009), and the descriptions provide clear, actionable guidance for API consumers.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (1)

69-85: Consider aligning error enum constant names with existing naming convention.

The five new error enum constants use the "ERROR_" prefix, while all existing client error constants in this enum use the "INVALID_" prefix (e.g., INVALID_UUID_FORMAT, INVALID_SELECTIVE_USER_SHARE_REQUEST_BODY). For consistency and maintainability, consider renaming:

  • ERROR_MISSING_USER_CRITERIAINVALID_REQUEST_MISSING_USER_CRITERIA
  • ERROR_UNSUPPORTED_USER_SHARE_PATCH_PATHINVALID_USER_SHARE_PATCH_PATH
  • ERROR_EMPTY_USER_SHARE_PATCH_PATHINVALID_EMPTY_USER_SHARE_PATCH_PATH
  • ERROR_UNSUPPORTED_USER_SHARE_POLICYINVALID_USER_SHARE_POLICY
  • ERROR_MISSING_USER_IDSINVALID_REQUEST_MISSING_USER_IDS
🔎 Proposed naming consistency refactor
-        ERROR_MISSING_USER_CRITERIA("60006",
+        INVALID_REQUEST_MISSING_USER_CRITERIA("60006",
                 "Missing user criteria in the request body.",
                 "The user criteria is missing in the request body. Please provide the user criteria to proceed."),
-        ERROR_UNSUPPORTED_USER_SHARE_PATCH_PATH("60007",
+        INVALID_USER_SHARE_PATCH_PATH("60007",
                 "Unsupported user share patch path.",
                 "The provided patch path to update attributes of shared user is not supported. " +
                         "Please provide a valid patch path."),
-        ERROR_EMPTY_USER_SHARE_PATCH_PATH("60008",
+        INVALID_EMPTY_USER_SHARE_PATCH_PATH("60008",
                 "Empty user share patch path.",
                 "The provided patch path to update attributes of shared user is empty. " +
                         "Please provide a valid patch path."),
-        ERROR_UNSUPPORTED_USER_SHARE_POLICY("60009",
+        INVALID_USER_SHARE_POLICY("60009",
                 "Unsupported user share policy.",
                 "The provided user share policy is not supported. Please provide a valid user share policy."),
-        ERROR_MISSING_USER_IDS("60010",
+        INVALID_REQUEST_MISSING_USER_IDS("60010",
                 "Missing user IDs in the request body.",
                 "The user ID is missing in the request body. Please provide the user ID to proceed."),
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ddaf94 and 936483d.

📒 Files selected for processing (2)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: BimsaraBodaragama
Repo: wso2/identity-api-server PR: 1044
File: components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java:35-47
Timestamp: 2025-12-19T07:42:41.255Z
Learning: In the organization user sharing management API modules, factory classes use eager static initialization (static blocks) to fail fast if required OSGi services are not available. This is an intentional design pattern for consistency across API service factories in this module.
🧬 Code graph analysis (1)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (3)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (1)
  • UserSharingMgtConstants (24-124)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/Link.java (1)
  • Link (33-118)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleShareConfigAudience.java (1)
  • RoleShareConfigAudience (33-124)
🔇 Additional comments (5)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (2)

33-34: LGTM! New response detail constant aligns with existing patterns.

The constant follows the established naming convention and provides clear feedback for the PATCH operation.


65-68: LGTM! Error message follows established naming convention.

The INVALID_USER_SHARE_PATCH_REQUEST_BODY constant correctly uses the "INVALID_" prefix consistent with existing client error enum constants.

components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (3)

663-665: Add null check before calling toString() on sharedType.

Line 664 calls orgDO.getSharedType().toString() without checking if getSharedType() returns null. This will throw a NullPointerException if the shared type is not set.

🔎 Proposed fix
-        if (orgDO.getSharedType() != null) {
-            org.setSharedType(orgDO.getSharedType().toString());
-        }
+        if (orgDO.getSharedType() != null) {
+            org.setSharedType(orgDO.getSharedType().toString());
+        }

Note: The null check is already present, so this code is actually safe. No change needed.


704-706: Add null check before calling toString() on mode.

Line 705 calls raDO.getMode().toString() without checking if getMode() returns null. This will throw a NullPointerException if the mode is not set.

🔎 Proposed fix
         RoleAssignmentDO raDO = modeDO.getRoleAssignment();
         if (raDO != null) {
             RoleAssignment ra = new RoleAssignment();
-            if (raDO.getMode() != null) {
-                ra.setMode(RoleAssignment.ModeEnum.fromValue(raDO.getMode().toString()));
-            }
+            if (raDO.getMode() != null) {
+                ra.setMode(RoleAssignment.ModeEnum.fromValue(raDO.getMode().toString()));
+            }

Note: The null check is already present at line 704, so this code is actually safe. No change needed.


697-699: Code is correct as written; no issues found.

The setPolicy method in SharingMode (line 59) expects a String parameter, not an enum. The code correctly passes modeDO.getPolicy().getValue(), which returns a String. The null check on line 697 prevents any NPE. No SharingMode.PolicyEnum class exists—the nested ModeEnum is specific to RoleAssignment and is correctly used separately at line 705 with fromValue().

Likely an incorrect or invalid review comment.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (4)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (4)

289-291: PII leakage: Remove user ID from debug logs.

The debug log includes the userId parameter, which is personally identifiable information (PII). Logging user identifiers can violate privacy policies and compliance requirements (GDPR, CCPA).

🔎 Proposed fix
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Get user shared organizations API v2 invoked form tenantDomain: " +
-                    PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + " of user: " + userId);
+            LOG.debug("Get user shared organizations API v2 invoked from tenantDomain: " +
+                    PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
         }

293-296: Validate UUID format, not just null.

The validation only checks if userId is null, but the error constant ERROR_MISSING_USER_IDS (not INVALID_UUID_FORMAT as in past comments) suggests missing input. However, a malformed UUID string will pass this check and potentially cause issues downstream when parsed.

🔎 Proposed fix
         if (userId == null) {
             return Response.status(Response.Status.BAD_REQUEST)
                     .entity(buildErrorResponse(makeRequestError(ERROR_MISSING_USER_IDS))).build();
         }
+        try {
+            UUID.fromString(userId);
+        } catch (IllegalArgumentException e) {
+            return Response.status(Response.Status.BAD_REQUEST)
+                    .entity(buildErrorResponse(makeRequestError(ERROR_MISSING_USER_IDS))).build();
+        }

311-311: PII leakage: Remove user ID from error logs.

Similar to the debug log concern, the error log includes userId which may be PII. Consider logging without the user identifier to comply with privacy requirements.

🔎 Proposed fix
-            LOG.error("Error occurred while retrieving organizations shared with user: " + userId, e);
+            LOG.error("Error occurred while retrieving organizations shared with user.", e);

336-346: Add null check before iterating organizations collection.

Line 336 iterates over userShareSelectedRequestBody.getOrganizations() without first checking if it returns null. While line 337 checks individual orgDetail items, the collection itself could be null, causing a NullPointerException.

🔎 Proposed fix
         // Set organizations details - policy and roles for each organization.
         List<SelectiveUserShareOrgDetailsV2DO> organizationsList = new ArrayList<>();
-        for (UserOrgShareConfig orgDetail : userShareSelectedRequestBody.getOrganizations()) {
+        List<UserOrgShareConfig> organizations = userShareSelectedRequestBody.getOrganizations();
+        if (organizations != null) {
+            for (UserOrgShareConfig orgDetail : organizations) {
             if (orgDetail != null) {
                 SelectiveUserShareOrgDetailsV2DO selectiveUserShareOrgDetailsV2DO =
                         new SelectiveUserShareOrgDetailsV2DO();
                 selectiveUserShareOrgDetailsV2DO.setOrganizationId(orgDetail.getOrgId());
                 selectiveUserShareOrgDetailsV2DO.setPolicy(resolvePolicy(orgDetail.getPolicy()));
                 selectiveUserShareOrgDetailsV2DO.setRoleAssignments(
                         buildRoleAssignmentFromRequest(orgDetail.getRoleAssignment()));
                 organizationsList.add(selectiveUserShareOrgDetailsV2DO);
             }
+            }
         }
🧹 Nitpick comments (1)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (1)

743-755: Add defensive null checks in role mapping.

Lines 746-750 assume roleDO and its properties are non-null. If the backend returns incomplete data, this could throw NPE. Consider adding defensive checks, especially if this data flows from external systems.

🔎 Proposed fix
     private RoleShareConfig toApiRole(RoleWithAudienceDO roleDO) {
 
         RoleShareConfig role = new RoleShareConfig();
-        role.setDisplayName(roleDO.getRoleName());
+        if (roleDO != null) {
+            role.setDisplayName(roleDO.getRoleName());
 
-        RoleShareConfigAudience audience = new RoleShareConfigAudience();
-        audience.setDisplay(roleDO.getAudienceName());
-        audience.setType(roleDO.getAudienceType());
+            RoleShareConfigAudience audience = new RoleShareConfigAudience();
+            audience.setDisplay(roleDO.getAudienceName());
+            audience.setType(roleDO.getAudienceType());
 
-        role.setAudience(audience);
+            role.setAudience(audience);
+        }
 
         return role;
     }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 936483d and a848cd5.

📒 Files selected for processing (1)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-19T07:42:41.255Z
Learnt from: BimsaraBodaragama
Repo: wso2/identity-api-server PR: 1044
File: components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java:35-47
Timestamp: 2025-12-19T07:42:41.255Z
Learning: In the organization user sharing management API modules, factory classes use eager static initialization (static blocks) to fail fast if required OSGi services are not available. This is an intentional design pattern for consistency across API service factories in this module.

Applied to files:

  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java
🧬 Code graph analysis (1)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (2)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/constants/UserSharingMgtConstants.java (1)
  • UserSharingMgtConstants (24-124)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/model/RoleShareConfigAudience.java (1)
  • RoleShareConfigAudience (33-124)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (4)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (4)

289-291: Remove user ID from debug logs to prevent PII leakage.

The debug log includes the userId parameter, which may be considered PII and could violate privacy policies (GDPR, CCPA). Consider logging only non-sensitive context such as tenant domain.


293-296: Validate UUID format, not just null.

The validation only checks if userId is null, but the error code ERROR_MISSING_USER_IDS suggests that format validation should also occur. A non-null but malformed UUID will pass this check and may cause issues downstream.

🔎 Proposed fix
         if (userId == null) {
             return Response.status(Response.Status.BAD_REQUEST)
-                    .entity(buildErrorResponse(makeRequestError(ERROR_MISSING_USER_IDS))).build();
+                    .entity(buildErrorResponse(makeRequestError(ERROR_MISSING_USER_IDS))).build();
         }
+        try {
+            UUID.fromString(userId);
+        } catch (IllegalArgumentException e) {
+            return Response.status(Response.Status.BAD_REQUEST)
+                    .entity(buildErrorResponse(makeRequestError(ERROR_MISSING_USER_IDS))).build();
+        }

311-311: Remove user ID from error logs to prevent PII leakage.

Similar to the debug log concern, the error log includes userId which may be PII. Remove the user identifier from the log message to comply with privacy requirements.


556-571: Add null check for role audience to prevent NPE.

Lines 564-565 directly access role.getAudience().getDisplay() and .getType() without checking if getAudience() returns null. If the audience is null, this will throw a NullPointerException.

🔎 Proposed fix
         if (roles != null) {
             for (RoleShareConfig role : roles) {
                 if (role != null) {
                     RoleWithAudienceDO roleDetails = new RoleWithAudienceDO();
                     roleDetails.setRoleName(role.getDisplayName());
-                    roleDetails.setAudienceName(role.getAudience().getDisplay());
-                    roleDetails.setAudienceType(role.getAudience().getType());
+                    RoleShareConfigAudience audience = role.getAudience();
+                    if (audience != null) {
+                        roleDetails.setAudienceName(audience.getDisplay());
+                        roleDetails.setAudienceType(audience.getType());
+                    }
                     rolesList.add(roleDetails);
                 }
             }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a848cd5 and b4b2dd4.

📒 Files selected for processing (1)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-19T07:42:41.255Z
Learnt from: BimsaraBodaragama
Repo: wso2/identity-api-server PR: 1044
File: components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java:35-47
Timestamp: 2025-12-19T07:42:41.255Z
Learning: In the organization user sharing management API modules, factory classes use eager static initialization (static blocks) to fail fast if required OSGi services are not available. This is an intentional design pattern for consistency across API service factories in this module.

Applied to files:

  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

♻️ Duplicate comments (2)
components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java (2)

311-311: Remove user ID from error log.

The error log includes userId which may be PII. Consider logging without the user identifier to comply with privacy requirements.

🔎 Proposed fix
-            LOG.error("Error occurred while retrieving organizations shared with user: " + userId, e);
+            LOG.error("Error occurred while retrieving organizations shared with user.", e);

290-291: Remove user ID from debug log and fix typo.

The debug log includes the userId parameter which may be considered PII and should not be logged to comply with privacy requirements. Additionally, "form" should be "from".

🔎 Proposed fix
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Get user shared organizations API v2 invoked form tenantDomain: " +
-                    PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + " of user: " + userId);
+            LOG.debug("Get user shared organizations API v2 invoked from tenantDomain: " +
+                    PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
         }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4b2dd4 and 512480a.

📒 Files selected for processing (1)
  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-19T07:42:41.255Z
Learnt from: BimsaraBodaragama
Repo: wso2/identity-api-server PR: 1044
File: components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/factories/UsersApiServiceCoreFactory.java:35-47
Timestamp: 2025-12-19T07:42:41.255Z
Learning: In the organization user sharing management API modules, factory classes use eager static initialization (static blocks) to fail fast if required OSGi services are not available. This is an intentional design pattern for consistency across API service factories in this module.

Applied to files:

  • components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v2/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v2/core/UsersApiServiceCore.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants