Skip to content

chore: refactor authentication failure redirect and retry#34899

Merged
nsarupr merged 3 commits intoreleasefrom
feat/auth-fail-retry-infra
Jul 16, 2024
Merged

chore: refactor authentication failure redirect and retry#34899
nsarupr merged 3 commits intoreleasefrom
feat/auth-fail-retry-infra

Conversation

@nsarupr
Copy link
Contributor

@nsarupr nsarupr commented Jul 12, 2024

Description

Add infrastructure for Authentication failure to retry and redirect.
An additional change has been made to make the Sentry's doLog() method public for others to use it for logging additional errors to Sentry.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Sanity,@tag.Authentication"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9955550436
Commit: 4204a44
Cypress dashboard.
Tags: @tag.Sanity,@tag.Authentication
Spec:


Tue, 16 Jul 2024 11:19:25 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced authentication failure handling with improved retry and redirection logic.
    • Simplified and streamlined exception logging using a new SentryLogger.
  • Improvements

    • More efficient and consistent handling of authentication failures.
  • Bug Fixes

    • Improved exception handling to ensure standardized error responses.
  • Chores

    • Cleaned up unused imports in the GlobalExceptionHandler to improve code maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Walkthrough

The recent code changes introduced a new mechanism for handling authentication failures in the server application. An AuthenticationFailureRetryHandler interface and its implementation were added to streamline retry and redirection logic. The AuthenticationFailureHandler and its CE version were updated to use this new handler. Additionally, a SentryLogger class was created to centralize exception logging, and imports in GlobalExceptionHandler were cleaned up.

Changes

File(s) Change Summary
AuthenticationFailureHandler.java Added a constructor to initialize AuthenticationFailureRetryHandler.
AuthenticationFailureHandlerCE.java Refactored to delegate authentication failure logic to AuthenticationFailureRetryHandler.
AuthenticationFailureRetryHandler.java, AuthenticationFailureRetryHandlerCE.java Introduced new interfaces for handling authentication failure retries.
AuthenticationFailureRetryHandlerCEImpl.java, AuthenticationFailureRetryHandlerImpl.java Implemented the retry and redirection logic for authentication failures.
GlobalExceptionHandler.java Streamlined imports and focused on handling AppsmithException types.
SentryLogger.java Created for centralized exception logging using Sentry.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Server
    participant AuthHandler as AuthenticationFailureHandler
    participant RetryHandler as AuthenticationFailureRetryHandler

    User->>Server: Login Attempt
    Server->>AuthHandler: Authentication Failed
    AuthHandler->>RetryHandler: Delegate Failure Handling
    RetryHandler->>AuthHandler: Retry and Redirect Logic
    RetryHandler->>User: Redirect with Error Message
Loading

Poem

In a world of code so bright,
Authentication finds its fight.
With handlers new, it retries,
And logs its woes up to the skies.
Errors now with grace, they flow,
Thanks to Sentry's watchful glow.
Onward, onward, the system grows! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jul 12, 2024
@github-actions
Copy link

Failed server tests

  • com.appsmith.server.solutions.ce.ActionExecutionSolutionCETest#testActionExecuteDbQuery

@nsarupr nsarupr marked this pull request as ready for review July 16, 2024 10:55
@nsarupr nsarupr added the ok-to-test Required label for CI label Jul 16, 2024
Copy link
Contributor

@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: 0

Outside diff range, codebase verification and nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandlerCEImpl.java (1)

1-114: Potential security issues in URL construction and redirect logic.

The constructRedirectUrl and getOriginFromState methods in AuthenticationFailureRetryHandlerCEImpl do not validate or sanitize the redirectUrl and originHeader parameters. This could potentially allow open redirect vulnerabilities if an attacker can control these parameters.

  • Location:
    • AuthenticationFailureRetryHandlerCEImpl.java, constructRedirectUrl method
    • AuthenticationFailureRetryHandlerCEImpl.java, getOriginFromState method

Recommendation: Validate and sanitize the redirectUrl and originHeader parameters to prevent open redirect vulnerabilities.

Analysis chain

Implementation of AuthenticationFailureRetryHandlerCEImpl is approved.

The class implements the AuthenticationFailureRetryHandler interface and includes comprehensive logic for handling different types of authentication failures.

Verify the security of URL construction and redirect logic.

Ensure that the URL construction and redirect logic in AuthenticationFailureRetryHandlerCEImpl do not introduce security vulnerabilities, such as open redirects.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the security of URL construction and redirect logic.

# Test: Search for potential security vulnerabilities in URL handling.
rg --type java -A 5 $'AuthenticationFailureRetryHandlerCEImpl'

Length of output: 1671


Script:

#!/bin/bash
# Description: Verify the handling of `redirectUrl` and `originHeader` in URL construction and redirect logic.

# Search for the usage of `redirectUrl` in the codebase.
rg --type java 'redirectUrl'

# Search for the usage of `originHeader` in the codebase.
rg --type java 'originHeader'

Length of output: 27195


Script:

#!/bin/bash
# Description: Extract implementations of `constructRedirectUrl` and `getOriginFromState` methods in `AuthenticationFailureRetryHandlerCEImpl`.

# Extract `constructRedirectUrl` method implementation.
ast-grep --lang java --pattern $'class AuthenticationFailureRetryHandlerCEImpl {
  $$$
  private String constructRedirectUrl(AuthenticationException exception, String originHeader, String redirectUrl) {
    $$$
  }
  $$$
}' -A 20

# Extract `getOriginFromState` method implementation.
ast-grep --lang java --pattern $'class AuthenticationFailureRetryHandlerCEImpl {
  $$$
  private String getOriginFromState(String state) {
    $$$
  }
  $$$
}' -A 20

Length of output: 397


Script:

#!/bin/bash
# Description: Extract implementations of `constructRedirectUrl` and `getOriginFromState` methods in `AuthenticationFailureRetryHandlerCEImpl`.

# Search for `constructRedirectUrl` method definition and its context.
rg --type java 'private String constructRedirectUrl' -A 20

# Search for `getOriginFromState` method definition and its context.
rg --type java 'private String getOriginFromState' -A 20

Length of output: 7569

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f6d62e5 and 4204a44.

Files selected for processing (8)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/AuthenticationFailureHandler.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/ce/AuthenticationFailureHandlerCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandler.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandlerCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandlerCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandlerImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/util/SentryLogger.java (1 hunks)
Additional comments not posted (7)
app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/ce/AuthenticationFailureHandlerCE.java (1)

3-19: Refactoring to use AuthenticationFailureRetryHandler is approved.

The changes align with the PR objectives to centralize authentication failure handling. This should improve maintainability and clarity of the authentication failure process.

Verify the implementation and integration of AuthenticationFailureRetryHandler.

Ensure that the AuthenticationFailureRetryHandler is correctly implemented and integrated, and that it handles all edge cases appropriately.

Verification successful

Verify the implementation of retryAndRedirectOnAuthenticationFailure in AuthenticationFailureRetryHandlerCEImpl.

Ensure that the retryAndRedirectOnAuthenticationFailure method is correctly implemented and handles all edge cases appropriately.


Retrieve the complete implementation of retryAndRedirectOnAuthenticationFailure in AuthenticationFailureRetryHandlerCEImpl.

Ensure that the method is fully implemented and handles all necessary edge cases appropriately.


The implementation of retryAndRedirectOnAuthenticationFailure is verified and correct.

The method in AuthenticationFailureRetryHandlerCEImpl handles authentication failures effectively by logging the error, determining the origin, constructing the redirect URL, and redirecting the user. The implementation covers necessary edge cases and aligns with the objective of centralizing the retry and redirection logic.

  • AuthenticationFailureRetryHandlerCEImpl class handles authentication failures and redirects appropriately.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and integration of `AuthenticationFailureRetryHandler`.

# Test: Search for the implementation and usage of `AuthenticationFailureRetryHandler`.
rg --type java -A 5 $'AuthenticationFailureRetryHandler'

Length of output: 6412


Script:

#!/bin/bash
# Description: Verify the implementation of `retryAndRedirectOnAuthenticationFailure` in `AuthenticationFailureRetryHandlerCEImpl`.

# Test: Search for the implementation of `retryAndRedirectOnAuthenticationFailure` method.
rg --type java -A 10 'Mono<Void> retryAndRedirectOnAuthenticationFailure' app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandlerCEImpl.java

Length of output: 991


Script:

#!/bin/bash
# Description: Retrieve the complete implementation of `retryAndRedirectOnAuthenticationFailure` in `AuthenticationFailureRetryHandlerCEImpl`.

# Test: Search for the complete implementation of `retryAndRedirectOnAuthenticationFailure` method.
rg --type java -A 50 'Mono<Void> retryAndRedirectOnAuthenticationFailure' app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandlerCEImpl.java

Length of output: 2472

app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/util/SentryLogger.java (1)

1-55: Creation of SentryLogger to centralize exception logging is approved.

Centralizing exception logging in SentryLogger is a good practice and should help maintain consistency in how exceptions are logged and handled across the application.

Verify handling of sensitive data in Sentry logging.

Ensure that sensitive data is not being inadvertently logged or exposed through Sentry.

app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java (1)

36-36: Streamlining imports and using SentryLogger for logging in GlobalExceptionHandler is approved.

The changes help reduce clutter and centralize logging, which is beneficial for maintaining clean and efficient code.

Verify that functionality is not adversely affected by changes in imports.

Ensure that the removal of imports and the integration of SentryLogger do not affect the functionality of the GlobalExceptionHandler.

app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandler.java (1)

3-3: Interface setup looks good.

The interface AuthenticationFailureRetryHandler correctly extends AuthenticationFailureRetryHandlerCE, allowing for specialized implementations in different contexts.

app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandlerImpl.java (1)

5-7: Class setup is correct.

The AuthenticationFailureRetryHandlerImpl class is properly annotated with @Component, making it a Spring-managed bean. It also correctly extends AuthenticationFailureRetryHandlerCEImpl and implements AuthenticationFailureRetryHandler.

app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/helpers/AuthenticationFailureRetryHandlerCE.java (1)

7-10: Interface and method setup are correct.

The AuthenticationFailureRetryHandlerCE interface and its method retryAndRedirectOnAuthenticationFailure are appropriately defined for handling authentication failures in a reactive manner.

app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/AuthenticationFailureHandler.java (1)

10-12: Constructor setup is correct.

The new constructor in AuthenticationFailureHandler correctly takes an AuthenticationFailureRetryHandler parameter and passes it to its superclass, ensuring proper dependency injection and use within the class.

@nsarupr nsarupr merged commit daaaa93 into release Jul 16, 2024
@nsarupr nsarupr deleted the feat/auth-fail-retry-infra branch July 16, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants