Skip to content

Conversation

@vishalya
Copy link
Member

Description

The parsing of the user and query was happening at different places and at a later stages, this PR structures it to happen at a early stage and a single point in time.

Additional context and related issues

  • Early Request Parsing: New JAX-RS filters have been added to intercept incoming requests. This filter is responsible for parsing essential user and query information at the earliest stage of processing under the PRE_AUTHENTICATION and PRE_AUTHORIZATION.
  • Use of ContainerRequestContext: The implementation now uses ContainerRequestContext instead of HttpServletRequest to access request details, as this is the object available within the JAX-RS filter context.
  • Injecting Request Attributes: The extracted user and query information is now passed along via request attributes, making it easily accessible in the later stages of request routing

Release notes

(X) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required, with the following suggested text:

@vishalya
Copy link
Member Author

Addressed the review comments.

@vishalya vishalya force-pushed the parse-user-query branch 2 times, most recently from 239f66a to 68e1860 Compare August 29, 2025 20:45
@oneonestar
Copy link
Member

How about using a single filter to parse all the data instead of having multiple filters?
We can store all the necessary data in a single object.
I think this would simplify the code and also help avoid dependency or execution order issues between multiple filters in the future.

@vishalya
Copy link
Member Author

vishalya commented Sep 3, 2025

I would like to keep it separate as they are different and will be parsed at different priorities (user info might need to be parsed at pre-authentication and query might be parsed at pre-authorization), The query information may not be present for all the requests.

@vishalya vishalya force-pushed the parse-user-query branch 2 times, most recently from b97df7f to b202da0 Compare September 16, 2025 20:36
@vishalya
Copy link
Member Author

Added a new class PathFilter to reuse the logic in the filters.

@vishalya
Copy link
Member Author

@ebyhr - I have addressed the review comments.

@vishalya vishalya force-pushed the parse-user-query branch 2 times, most recently from 910492f to 1d71ebd Compare September 26, 2025 20:02
@xkrogen
Copy link
Member

xkrogen commented Oct 17, 2025

@vishalya are you still working on this? Would love to see it land -- this is a great cleanup

@vishalya
Copy link
Member Author

I’ll spend some time on the code comments this week

Copy link
Member

@Chaho12 Chaho12 left a comment

Choose a reason for hiding this comment

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

LGTM. Can you resolve comments if they are addressed :)

@Chaho12
Copy link
Member

Chaho12 commented Nov 3, 2025

Let's get this merged. This refactoring would affect others quite a bit.

@Chaho12 Chaho12 merged commit 5a36940 into trinodb:main Nov 3, 2025
3 checks passed
@github-actions github-actions bot added this to the 17 milestone Nov 3, 2025
Comment on lines +44 to +46
public PathFilter(
List<String> statementPaths,
List<String> extraWhitelistPaths)
Copy link
Member

Choose a reason for hiding this comment

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

Please inject HaGatewayConfiguration instead.

List<String> statementPaths,
List<String> extraWhitelistPaths)
{
this.statementPaths = Set.copyOf(requireNonNull(statementPaths, "Required configuration 'statementPaths' can't be null"));
Copy link
Member

Choose a reason for hiding this comment

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

Use ImmutableSet.copyOf and remove requireNonNull.

Comment on lines +151 to +152
this("", "", "", ImmutableList.of(), Optional.empty(), Optional.empty(),
ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), false, Optional.empty());
Copy link
Member

Choose a reason for hiding this comment

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

The convention is single line or separate lines.

        this(
                "",
                "",
                "",
                ImmutableList.of(),
                Optional.empty(),
                Optional.empty(),
                ImmutableSet.of(),
                ImmutableSet.of(),
                ImmutableSet.of(),
                false,
                Optional.empty());

private Optional<String> extractUserFromCookies(ContainerRequestContext requestContext, String userField)
{
if (request.getCookies() == null) {
Map<String, jakarta.ws.rs.core.Cookie> cookies = requestContext.getCookies();
Copy link
Member

Choose a reason for hiding this comment

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

Import jakarta.ws.rs.core.Cookie.

Comment on lines +44 to +45
private static final int MAX_QUERY_TEXT_LOG_LENGTH = 100;
private final boolean isAnalyzeRequest;
Copy link
Member

Choose a reason for hiding this comment

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

Add an empty line between constants and fields.

Comment on lines +97 to +102
try {
when(uriInfo.getRequestUri()).thenReturn(new URI("http://localhost" + HttpUtils.OAUTH_PATH));
}
catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Copy link
Member

Choose a reason for hiding this comment

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

Remove redundant try-catch.

Comment on lines +128 to +133
try {
when(uriInfo.getRequestUri()).thenReturn(new URI("http://localhost" + HttpUtils.V1_STATEMENT_PATH));
}
catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Copy link
Member

Choose a reason for hiding this comment

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

Remove redundant try-catch.

Comment on lines +157 to +162
try {
when(uriInfo.getRequestUri()).thenReturn(new URI("http://localhost" + HttpUtils.V1_STATEMENT_PATH));
}
catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Copy link
Member

Choose a reason for hiding this comment

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

Remove redundant try-catch.

Comment on lines +191 to +196
try {
when(uriInfo.getRequestUri()).thenReturn(new URI("http://localhost" + HttpUtils.V1_STATEMENT_PATH));
}
catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Copy link
Member

Choose a reason for hiding this comment

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

Remove redundant try-catch.


final class TestQueryUserInfoParser
{
private QueryUserInfoParser filter;
Copy link
Member

Choose a reason for hiding this comment

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

Make this field constant.

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

Development

Successfully merging this pull request may close these issues.

6 participants