Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a config to continue backend JWT generation on user claim retrieval failure #13051

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RusJaI
Copy link
Contributor

@RusJaI RusJaI commented Mar 20, 2025

Fixes wso2/api-manager#3816

Config

apim.jwt.continue_on_claim_retrieval_failure was newly introduced. This is true by default.
Following is a sample usage :

[apim.jwt]
enable = true
enable_user_claims = true
gateway_generator.enable_claim_retrieval=true
continue_on_claim_retrieval_failure = false

Response Codes

When the config enabled,
invocations providing JWT token when exception is thrown during user claim retrieval. (HTTP status code - 401):

  "code": "900900",
  "message": "Unclassified Authentication Failure",
  "description": "Unclassified Authentication Failure"
}

Invocations providing Opaque token :

{
  "code": "900900",
  "message": "Unclassified Authentication Failure",
  "description": "Resource forbidden"
}

Copy link

coderabbitai bot commented Mar 20, 2025

📝 Walkthrough

Walkthrough

The changes update the JWT handling logic by modifying method signatures and error handling in the JWT validator and token generation components. New exceptions may now be thrown if user claim retrieval fails, depending on a configuration flag. Additionally, a new constant and configuration option are introduced, supported by updates in the configuration DTO and external configuration files, to control behavior when retrieving custom claims fails.

Changes

File(s) Change Summary
components/.../JWTValidator.java
components/.../AbstractKeyValidationHandler.java
Updated method signatures to throw JWTGeneratorException and modified error handling. Now, on claim retrieval failure, the control flow checks a configuration flag: either throwing an exception or logging the issue and returning a status.
components/.../APIConstants.java
components/.../APIManagerConfiguration.java
components/.../ExtendedJWTConfigurationDto.java
Introduced a new constant (CONTINUE_ON_CLAIM_RETRIEVAL_FAILURE), added a corresponding boolean field (with getter/setter) in the extended JWT configuration DTO, and updated the configuration setup to read the new claim retrieval flag.
features/.../org.wso2.carbon.apimgt.core.default.json
features/.../api-manager.xml.j2
Added a new configuration option for JWT processing. The JSON file now includes "apim.jwt.continue_on_claim_retrieval_failure": true and the XML template includes a <ContinueOnClaimRetrievalFailure> element that injects the corresponding variable.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant H as AbstractKeyValidationHandler
    participant V as JWTValidator
    participant CFG as JWTConfiguration
    C->>H: generateConsumerToken()
    H->>V: getUserClaimsFromKeyManager(jwtInfoDto)
    alt Claim retrieval succeeds
        V-->>H: Return user claims
        H->>H: Set endUserToken
        H-->>C: Return true (token generated)
    else Claim retrieval fails
        V-->>H: Throws JWTGeneratorException
        H->>CFG: Check continueOnClaimRetrievalFailure
        alt Not allowed to continue
            H-->>C: Throw APIKeyMgtException
        else Allowed to continue
            H->>H: Log error and return false
            H-->>C: Return false (failure handled)
        end
    end
Loading
sequenceDiagram
    participant XML as Config XML (api-manager.xml.j2)
    participant AC as APIManagerConfiguration
    participant DTO as ExtendedJWTConfigurationDto
    XML->>AC: Provide <ContinueOnClaimRetrievalFailure> element
    AC->>DTO: Set continueOnClaimRetrievalFailure flag
Loading

Assessment against linked issues

Objective Addressed Explanation
Introduce a config to decide whether to proceed with backend JWT generation when user claim retrieval fails (#3816)

Suggested reviewers

  • tgtshanika
  • chamilaadhi
  • dushaniw
  • Arshardh
  • AnuGayan
  • tharindu1st

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9de2f82 and 065ab44.

📒 Files selected for processing (9)
  • components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/jwt/JWTValidator.java (3 hunks)
  • components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/keys/APIKeyValidatorClient.java (1 hunks)
  • components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/keys/WSAPIKeyDataStore.java (2 hunks)
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java (2 hunks)
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java (1 hunks)
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/ExtendedJWTConfigurationDto.java (2 hunks)
  • components/apimgt/org.wso2.carbon.apimgt.keymgt/src/main/java/org/wso2/carbon/apimgt/keymgt/handlers/AbstractKeyValidationHandler.java (1 hunks)
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/org.wso2.carbon.apimgt.core.default.json (1 hunks)
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/templates/repository/conf/api-manager.xml.j2 (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/keys/APIKeyValidatorClient.java
  • components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/keys/WSAPIKeyDataStore.java
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/org.wso2.carbon.apimgt.core.default.json
  • components/apimgt/org.wso2.carbon.apimgt.keymgt/src/main/java/org/wso2/carbon/apimgt/keymgt/handlers/AbstractKeyValidationHandler.java
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/ExtendedJWTConfigurationDto.java
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/templates/repository/conf/api-manager.xml.j2
  • components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/jwt/JWTValidator.java
🧰 Additional context used
🧬 Code Definitions (1)
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java (1)
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java (1)
  • APIConstants (32-3340)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-product (2, group2)
  • GitHub Check: build-product (1, group1)
  • GitHub Check: run-benchmark-test
  • GitHub Check: build-product (3, group3)
  • GitHub Check: build-carbon
  • GitHub Check: build-product (4, group4)
🔇 Additional comments (1)
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java (1)

1848-1853: Implementation correctly handles the new configuration parameter.

The added code properly retrieves and sets the continueOnClaimRetrievalFailure configuration, which aligns with the PR objective to introduce a config that allows backend JWT generation to continue even when user claim retrieval fails.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Introduce a config to decide whether to proceed with backend JWT generation when userclaim retrieval fails
1 participant