Skip to content

[ISSUE-4322][Bug] Fix OpenAPI token authentication#4361

Open
hutiefang76 wants to merge 1 commit into
apache:devfrom
hutiefang76:codex/fix-openapi-token-auth
Open

[ISSUE-4322][Bug] Fix OpenAPI token authentication#4361
hutiefang76 wants to merge 1 commit into
apache:devfrom
hutiefang76:codex/fix-openapi-token-auth

Conversation

@hutiefang76

Copy link
Copy Markdown

What changes were proposed in this pull request?

This PR fixes OpenAPI token authentication for generated access tokens.

The OpenAPI token is stored as an encrypted JWT. During authentication the request token is already decrypted by JWTFilter, so the realm should compare the decrypted stored token with the current credential instead of encrypting the credential again.

Because token encryption uses a random IV, encrypting the same JWT again does not produce the same stored token string, which caused valid OpenAPI requests to be rejected with 401.

Brief change log

  • Compare the decrypted stored OpenAPI token with the current credential in ShiroRealm.
  • Add a regression test that creates an OpenAPI access token and requests /openapi/app/start, verifying the authentication layer no longer returns 401.

Verifying this change

  • Red check before the fix: AccessTokenServiceTest#testOpenApiTokenCanAuthenticate failed with expected: not equal but was: <401>.
  • JAVA_HOME=$(/usr/libexec/java_home -v 17) ./mvnw -pl streampark-console/streampark-console-service -am -Dtest=AccessTokenServiceTest,JWTTest -Dsurefire.failIfNoSpecifiedTests=false test
  • git diff --check

Closes #4322

@sonarqubecloud

Copy link
Copy Markdown

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[openAPI] open api always return 401

1 participant