Skip to content

Introduce Policy Management API component - #1146

Open
kaviska wants to merge 7 commits into
wso2:masterfrom
kaviska:policy-mgt-api
Open

Introduce Policy Management API component#1146
kaviska wants to merge 7 commits into
wso2:masterfrom
kaviska:policy-mgt-api

Conversation

@kaviska

@kaviska kaviska commented Jul 6, 2026

Copy link
Copy Markdown

Purpose

This PR introduces a new Policy Management REST API (/api/server/v1/policies) to the Identity Server API Server layer. It exposes the underlying PolicyManagementService OSGi component over HTTP so that policies — and their attached rule-based resources — can be managed by API clients.

Goals

Provide full CRUD + listing capability for policies through a versioned (v1) REST API:

  • Create, retrieve, update, and delete a policy.
  • List policies with pagination (limit/offset) and name-based filtering.
  • Represent OR-combined / AND-grouped rule expressions in request and response bodies.
  • Enrich response expressions with human-readable field display names from rule metadata.

Approach

A new Maven component org.wso2.carbon.identity.api.server.policy is added with two modules, following the established API-server conventions:

  • .common – shared Constants (error codes with the PM- prefix) and PolicyServiceHolder, which resolves the PolicyManagementService and RuleMetadataService OSGi services from the Carbon context.
  • .v1 – the versioned API:
    • policy.yaml – the OpenAPI 3.0 contract; the src/gen interfaces and models are generated from it.
    • PoliciesApiServiceImpl – JAX-RS delegate; builds the Location header on create and maps to the correct HTTP status codes (201/200/204).
    • PolicyService (core) – orchestrates each operation, resolves the tenant domain from context, and delegates to PolicyManagementService.
    • Translator functions PolicyRequestToPolicy / PolicyToPolicyResponse – convert between the API models and the backend domain models (Policy, PolicyResource, ORCombinedRule, ANDCombinedRule, Expression).
    • PolicyManagementAPIErrorBuilder – centralizes exception handling, mapping backend client exceptions to 400/404/409 and server errors to 500.

Request validation (required fields, minItems, etc.) is enforced by the bean-validation annotations generated into the models from the OpenAPI spec.

User stories

  • As a tenant admin, I want to create a policy with rule-based resources so that I can define conditional policy logic.
  • As a tenant admin, I want to list, filter, and paginate policies so that I can browse them a scale.
  • As a tenant admin, I want to retrieve, update, and delete an individual policy by its ID.

Developer Checklist (Mandatory)

  • Complete the Developer Checklist in the related product-is issue to track any behavioral change or migration impact.

Release note

N/A

Documentation

N/A

Training

N/A

Certification

N/A

Marketing

N/A

Automation tests

N/A

Security checks

Samples

N/A

Related PRs

wso2/carbon-identity-framework#8158

Migrations (if applicable)

N/A – new API, no migration required.

Test environment

N/A

Learning

N/A

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Summary

  • Introduces a Policy Management REST API under /api/server/v1/policies in the Identity Server API Server layer.
  • Implements policy CRUD and listing with pagination and name-based filtering, returning rule-based policy structures with OR-combined and AND-grouped expressions, including rule/field mapping in responses.
  • Adds OpenAPI contract (policy.yaml), generated models, JAX-RS implementation (PoliciesApiServiceImpl), request/response orchestration, and centralized API error handling (PolicyManagementAPIErrorBuilder), with shared constants and standardized error codes.
  • Provides model translation utilities to build domain policies and rule expressions from API requests, and to translate domain policies back into API responses (e.g., PolicyBuilder, PolicyRuleBuilder, PolicyResponseBuilder, RuleResponseBuilder).
  • Adds OSGi-backed service resolution helpers (PolicyServiceHolder) and wiring for the v1 API (PolicyServiceFactory), plus a dedicated PolicyService for tenant-scoped operations and pagination link construction.
  • Keeps policy names immutable during updates by intentionally omitting name changes when building update payloads (buildUpdatingPolicy).
  • Registers new Maven modules: org.wso2.carbon.identity.api.server.policy (aggregator), ...policy.common, and ...policy.v1, including updated root pom.xml dependencies.

Walkthrough

Adds a Device Policy Management REST API with common and versioned Maven modules. The OpenAPI specification defines policy CRUD, pagination, security schemes, request/response models, and errors. Builders translate API requests and domain policies, rules, and expressions. The service layer delegates tenant-scoped operations to PolicyManagementService, translates exceptions, and the JAX-RS implementation returns HTTP responses.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant PoliciesApiServiceImpl
  participant PolicyService
  participant PolicyManagementService
  Client->>PoliciesApiServiceImpl: POST /policies
  PoliciesApiServiceImpl->>PolicyService: addPolicy(PolicyRequest)
  PolicyService->>PolicyManagementService: addPolicy(Policy, tenant)
  PolicyManagementService-->>PolicyService: created Policy
  PolicyService-->>PoliciesApiServiceImpl: PolicyResponse
  PoliciesApiServiceImpl-->>Client: 201 Created
Loading

Suggested reviewers: thisara-welmilla

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.37% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the new Policy Management API component added in this PR.
Description check ✅ Passed The PR description follows the required template and covers the main sections with only minor placeholders left as N/A.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (2)
components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/resources/policy.yaml (1)

284-288: 🚀 Performance & Scalability | 🔵 Trivial

Consider bounding the resources array size.

Static analysis flags the missing maxItems on this array. Adding an upper bound would guard against unbounded request payloads.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/resources/policy.yaml`
around lines 284 - 288, The Policy schema’s resources array is unbounded, so add
a maxItems constraint to the resources definition in policy.yaml to cap request
payload size. Update the resources array within the PolicyRequest/Policy schema
near the PolicyResourceRequest items reference, keeping the existing description
and ref intact while introducing a reasonable upper limit.

Source: Linters/SAST tools

components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java (1)

147-156: 🧹 Nitpick | 🔵 Trivial

Separate count and list calls may yield inconsistent pagination totals.

getPolicyCount and getPolicies are independent backend calls; concurrent writes between the two could produce a mismatched totalResults versus actual returned items. This is a common pagination tradeoff, but worth confirming is acceptable for this API.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java`
around lines 147 - 156, The pagination response in PolicyService may report a
totalResults value that does not match the returned items because getPolicyCount
and getPolicies are separate backend calls. Update the logic to either obtain
both values from a single consistent backend read/snapshot or explicitly handle
and document the eventual-consistency tradeoff in this method. Keep the change
centered around getPolicyCount, getPolicies, and the pagination response
construction in PolicyService so the total and items are aligned as much as the
API supports.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/pom.xml`:
- Around line 102-105: The pom.xml for the policy API server module still
inherits commons-beanutils version 1.9.4 from the shared
commons.beanutils.version property in the root build. Update that shared
property to 1.11.0 or later so the commons-beanutils dependency declared in this
module and all other consumers pick up the newer version consistently.

In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java`:
- Around line 69-80: `addPolicy` and `updatePolicy` are returning
`PolicyResponse` without resolved field display names, unlike `getPolicyById`,
so the same resource is mapped inconsistently. Update the response mapping in
`PolicyService` to use `PolicyToPolicyResponse` with the same display-name
loading path as `getPolicyById` (via `loadFieldDisplayNamesMap()` or a shared
helper), and apply the same fix in both `addPolicy` and `updatePolicy` so
create/update/get all populate `displayName` consistently.

In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/PolicyToPolicyResponse.java`:
- Around line 93-102: The toRuleResponse method in PolicyToPolicyResponse
performs an unchecked cast to ORCombinedRule, which can fail with a
ClassCastException if a different Rule implementation is passed in. Add an
instanceof guard before the cast, and handle the unexpected type with a clear
error or log message so the method fails safely; use toRuleResponse and
ORCombinedRule as the key symbols when updating the logic.

In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/resources/policy.yaml`:
- Around line 299-303: The OpenAPI schema for resourceType documents a RULE
default but does not declare one, so the generated model will not initialize it
automatically. Update the resourceType definition in policy.yaml to include a
default of RULE alongside the existing enum and description, keeping the
documented behavior aligned with the generated getters/models.
- Around line 202-233: Add a 404 Not Found response to the delete operation for
/policies/{policy-id} in the delete block with operationId deletePolicy,
matching the GET and PUT contracts. Update the responses section alongside 204,
400, 401, 403, and 500 so DELETE documents the not-found case consistently with
the other operations on the same path.

---

Nitpick comments:
In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java`:
- Around line 147-156: The pagination response in PolicyService may report a
totalResults value that does not match the returned items because getPolicyCount
and getPolicies are separate backend calls. Update the logic to either obtain
both values from a single consistent backend read/snapshot or explicitly handle
and document the eventual-consistency tradeoff in this method. Keep the change
centered around getPolicyCount, getPolicies, and the pagination response
construction in PolicyService so the total and items are aligned as much as the
API supports.

In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/resources/policy.yaml`:
- Around line 284-288: The Policy schema’s resources array is unbounded, so add
a maxItems constraint to the resources definition in policy.yaml to cap request
payload size. Update the resources array within the PolicyRequest/Policy schema
near the PolicyResourceRequest items reference, keeping the existing description
and ref intact while introducing a reasonable upper limit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 864c706f-4346-4d2d-99c8-629df9d6e8d8

📥 Commits

Reviewing files that changed from the base of the PR and between bb56735 and e442bab.

⛔ Files ignored due to path filters (18)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/PoliciesApi.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/PoliciesApiService.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/factories/PoliciesApiServiceFactory.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/ANDRuleRequest.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/ANDRuleResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/Error.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/ExpressionRequest.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/ExpressionResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/ExpressionValue.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/PolicyListItem.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/PolicyListLink.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/PolicyListResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/PolicyRequest.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/PolicyResourceRequest.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/PolicyResourceResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/PolicyResponse.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/RuleRequest.java is excluded by !**/gen/**
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/RuleResponse.java is excluded by !**/gen/**
📒 Files selected for processing (13)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.common/pom.xml
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.common/src/main/java/org/wso2/carbon/identity/api/server/policy/common/Constants.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.common/src/main/java/org/wso2/carbon/identity/api/server/policy/common/PolicyServiceHolder.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/pom.xml
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/factories/PolicyServiceFactory.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/PolicyRequestToPolicy.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/PolicyToPolicyResponse.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/impl/PoliciesApiServiceImpl.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/util/PolicyManagementAPIErrorBuilder.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/resources/policy.yaml
  • components/org.wso2.carbon.identity.api.server.policy/pom.xml
  • pom.xml

Comment on lines +102 to +105
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

What is the latest stable version of commons-beanutils and is it a drop-in replacement for 1.9.4?

💡 Result:

The latest stable version of Apache Commons BeanUtils is 1.11.0, released on May 25, 2025 [1][2]. Regarding whether it is a drop-in replacement for version 1.9.4: 1. Compatibility: While versions 1.10.0, 1.10.1, and 1.11.0 are maintenance releases intended to address security and bug fixes within the 1.x line, they are not strictly identical in their requirements. Most notably, starting with version 1.10.0, the minimum Java requirement was increased from Java 6 to Java 8 [1][3][4]. 2. Drop-in Replacement: For projects already running on Java 8 or higher, these versions are generally intended to be compatible replacements for 1.9.4 [5][6]. However, because they include deprecations and internal changes (such as changes to raw types and dependencies like commons-logging), you should thoroughly test your application's specific usage of the library before upgrading [3][4]. For users requiring a drop-in replacement that strictly maintains binary compatibility or avoids specific API changes, thorough regression testing is recommended, especially given the transition to a higher Java runtime requirement [1][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate all commons-beanutils references and the root dependency management entry.
git ls-files '*pom.xml' | while read -r f; do
  if grep -nH 'commons-beanutils' "$f" >/dev/null 2>&1; then
    echo "### $f"
    grep -nH 'commons-beanutils' "$f" || true
  fi
done

echo
echo "### Root pom dependencyManagement context"
root_pom="$(git ls-files 'pom.xml' | head -n 1)"
if [ -n "$root_pom" ]; then
  grep -nH -A3 -B3 'commons-beanutils' "$root_pom" || true
fi

Repository: wso2/identity-api-server

Length of output: 5643


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target module pom around the dependency.
target='components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/pom.xml'
nl -ba "$target" | sed -n '85,115p'

echo
echo "### Search for managed version property/value"
rg -n 'commons-beanutils|beanutils' -g 'pom.xml' .

Repository: wso2/identity-api-server

Length of output: 202


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "### All commons-beanutils references"
git ls-files '*pom.xml' | xargs rg -n 'commons-beanutils' || true

echo
echo "### Root pom.xml managed version context"
root_pom='pom.xml'
if [ -f "$root_pom" ]; then
  rg -n -A4 -B4 'commons-beanutils|commons\.beanutils|beanutils' "$root_pom" || true
fi

echo
echo "### Target module dependency block"
target='components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/pom.xml'
nl -ba "$target" | sed -n '94,112p'

Repository: wso2/identity-api-server

Length of output: 5481


Bump the shared commons.beanutils.version
This module inherits 1.9.4 from the root pom.xml; updating the shared property to 1.11.0 or later will cover every current consumer.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/pom.xml`
around lines 102 - 105, The pom.xml for the policy API server module still
inherits commons-beanutils version 1.9.4 from the shared
commons.beanutils.version property in the root build. Update that shared
property to 1.11.0 or later so the commons-beanutils dependency declared in this
module and all other consumers pick up the newer version consistently.

Source: Linters/SAST tools

kaviska added 2 commits July 7, 2026 10:09
@@ -0,0 +1,510 @@
openapi: 3.0.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing WSO2 header

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Do we Add Header in Yaml file ex:rule-metadata, flow-execution


private static class PolicyManagementServiceHolder {

static final PolicyManagementService SERVICE = (PolicyManagementService) PrivilegedCarbonContext

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why we are having block capitals here SERVICE.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Follow the pattern used in RuleMetadataServiceHolder

@Thisara-Welmilla

Copy link
Copy Markdown
Contributor

For now, let's make policy name immutable.

* Gets the OSGi service from ServiceHolder and injects it into PolicyService.
* Created once at startup — singleton pattern using static initializer.
*/
public class PolicyServiceFactory {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We do not need this factory class, move the content to the policyService class

@kaviska kaviska Jul 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Almost all the modules in the api layer used this factory class ex:rule, flow

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/RuleResponseBuilder.java (1)

74-87: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Do not emit an empty value object for null expression values.

ExpressionValue is created unconditionally and attached to the response even when expression.getValue() is null. This produces an empty value object instead of omitting the field or preserving null.

Proposed fix
-        ExpressionValue expressionValue = new ExpressionValue();
         if (expression.getValue() != null) {
+            ExpressionValue expressionValue = new ExpressionValue();
             expressionValue.setType(
                     ExpressionValue.TypeEnum.fromValue(expression.getValue().getType().name()));
             expressionValue.setValue(expression.getValue().getFieldValue());
+            expressionResponse.setValue(expressionValue);
         }
         ExpressionResponse expressionResponse = new ExpressionResponse();
         expressionResponse.setField(expression.getField());
         expressionResponse.setOperator(expression.getOperator());
-        expressionResponse.setValue(expressionValue);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/RuleResponseBuilder.java`
around lines 74 - 87, Update toExpressionResponse so ExpressionValue is only
created and assigned when expression.getValue() is non-null; otherwise leave the
response value unset or null. Preserve the existing type and fieldValue mapping
for non-null expression values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/PolicyBuilder.java`:
- Around line 47-50: Update PolicyBuilder.buildPolicy so policy names remain
immutable when policyId is non-null: preserve the existing stored name or reject
a request name that differs before constructing the update model. Keep
policyRequest.getName() for new policies where policyId is null, and ensure the
Policy constructor receives the validated name.

---

Outside diff comments:
In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/RuleResponseBuilder.java`:
- Around line 74-87: Update toExpressionResponse so ExpressionValue is only
created and assigned when expression.getValue() is non-null; otherwise leave the
response value unset or null. Preserve the existing type and fieldValue mapping
for non-null expression values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b9ae41c2-6e18-487e-9ac1-9535f138f7f8

📥 Commits

Reviewing files that changed from the base of the PR and between 791f8f9 and 670a291.

⛔ Files ignored due to path filters (1)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/gen/java/org/wso2/carbon/identity/api/server/policy/v1/model/PolicyResourceResponse.java is excluded by !**/gen/**
📒 Files selected for processing (7)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/PolicyBuilder.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/PolicyResponseBuilder.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/PolicyRuleBuilder.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/function/RuleResponseBuilder.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/impl/PoliciesApiServiceImpl.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/resources/policy.yaml
💤 Files with no reviewable changes (1)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/resources/policy.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/impl/PoliciesApiServiceImpl.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java

@kaviska
kaviska requested a review from Thisara-Welmilla July 25, 2026 05:54

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/factories/PolicyServiceFactory.java`:
- Around line 32-38: Move the PolicyManagementService null check out of the
static initializer and into PolicyServiceFactory.getPolicyService(), throwing
the existing IllegalStateException when unavailable. Keep class loading free of
service-availability failures so PoliciesApiServiceImpl can handle the expected
exception directly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e37e2811-7148-46fd-b414-6128d41f635a

📥 Commits

Reviewing files that changed from the base of the PR and between 92e2530 and 47e01c4.

📒 Files selected for processing (3)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/factories/PolicyServiceFactory.java
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/impl/PoliciesApiServiceImpl.java
💤 Files with no reviewable changes (1)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/core/PolicyService.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/org.wso2.carbon.identity.api.server.policy/org.wso2.carbon.identity.api.server.policy.v1/src/main/java/org/wso2/carbon/identity/api/server/policy/v1/impl/PoliciesApiServiceImpl.java

* @param filter Name substring filter; null or blank returns all policies.
* @return Paginated policy list response.
*/
public PolicyListResponse getPolicies(Integer limit, Integer offset, String filter) {

@Thisara-Welmilla Thisara-Welmilla Jul 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

getPolicies -> getPoliciesBasicInfo

* addPolicy → no ID yet, pass null
* updatePolicy → ID comes from the URL path param
*/
public class PolicyBuilder {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does other components also use function name as the component name? If not, use consistence component name.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There is no one pattern in the code base some component use function folder (ex:extension mgt) some component use util folder


List<PolicyResource> resources = buildPolicyResources(policyRequest.getResources(), tenantDomain);
return new Policy.Builder()
.id(policyId)

@Thisara-Welmilla Thisara-Welmilla Jul 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you check in other component, do set the ID at any new creation, whether it is from service layer or API layer?

private static void validateResourceType(PolicyResourceRequest.ResourceTypeEnum resourceType) {

// resourceType is optional in the API and defaults to RULE; RULE is the only supported type.
if (resourceType != null && resourceType != PolicyResourceRequest.ResourceTypeEnum.RULE) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make resourceType required from the API definition.

tags:
- Policy Management
summary: List policies.
operationId: getPolicies

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Normally we mention the required scopes per endpoint.

@@ -0,0 +1,512 @@
openapi: 3.0.0
info:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

2 participants