Skip to content

[CALCITE-6135] BEARER authentication support#299

Open
richardantal wants to merge 2 commits intoapache:mainfrom
richardantal:BEARER_Rebased
Open

[CALCITE-6135] BEARER authentication support#299
richardantal wants to merge 2 commits intoapache:mainfrom
richardantal:BEARER_Rebased

Conversation

@richardantal
Copy link

No description provided.

@richardantal
Copy link
Author

richardantal commented Feb 3, 2026

This is the rebase and clean up version of #232


void init(ConnectionConfig config) throws IOException;

String obtain(String username);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please document this method?
What is the result?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I'll do that

It returns the Token used for Authentication.

if (null == username) {
username = System.getProperty("user.name");
}
((BearerAuthenticateable) client).setTokenProvider(username, tokenProvider);
Copy link
Contributor

Choose a reason for hiding this comment

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

can userName by null here?
The method that follows does not expect them.

Copy link
Author

Choose a reason for hiding this comment

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

The userName can not be null when calling setTokenProvider
We need it later when we get the JWT token:
new BearerToken(tokenProvider.obtain(username))

Copy link
Contributor

Choose a reason for hiding this comment

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

But can't System.getProperty return null?

/** Bearer token to use to perform Bearer authentication. */
BEARER_TOKEN("bearer_token", Type.STRING, null, false),

/** File containing bearer tokens to use to perform Bearer authentication. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Not obvious how the file is represented using a string, presumably it's some kind of path or URI.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, a path
With this I would like to add the possibility to add an other implementation for BearerTokenProvider In the future.
Where instead of storing the Token, we can store the token file's location and load the token(s) from a file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add this information to JavaDoc?

int getInt();

/**
* Returns the int value of this property. Throws if not set and no
Copy link
Contributor

Choose a reason for hiding this comment

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

No default means defaultValue is null?

Copy link
Author

Choose a reason for hiding this comment

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

Probably You are right it can only happen if the defaultValue is set to null

String getString(String defaultValue);

/**
* Returns the int value of this property. Throws if not set and no
Copy link
Contributor

Choose a reason for hiding this comment

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

What does "default" mean here?
Is this a per-property notion?

Copy link
Author

Choose a reason for hiding this comment

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

It has been copied from PropEnv, the same applies to all similar functions.
Should I remove the trows if not set and no default part?
Do you think a comment like this would be better?
Returns the long value of this property or the defaultValue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it's not "long"
And I still don't know where the default value is coming from.

Copy link
Author

Choose a reason for hiding this comment

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

property is a ConnectionProperty which has a defaultValue functions.

* Returns the string value of this property, or null if not specified and
* no default.
*/
String getString(String defaultValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the only one that never throws, why this asymmetry?

Copy link
Author

Choose a reason for hiding this comment

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

I think either getString methods Throw.
It has been copied from PropEnv which is the implementation of this ConnectionPropertyValue interface

Copy link
Contributor

Choose a reason for hiding this comment

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

I know you didn't write that documentation, but is there a way to check whether this is correct?
If not, maybe you can fix it there too.

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class BearerTokenProviderFactoryTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

are all tests in this file negative?

Copy link
Author

Choose a reason for hiding this comment

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

Can you please be more specific?

In testCustomBearerToken and testConstantBearerToken I test the happy path to validate the correct behavior of tokenProvider.obtain.
There is message property provided if the expected value is different from the actual.

Co-authored-by: Aron Meszaros <meszaros.aron.attila@gmail.com>
@mihaibudiu
Copy link
Contributor

Please avoid force-pushing until the review is finished; it makes it harder to see what is changed.
Once the PR is accepted you can squash all the commits into one.

BearerToken edge case handling, user is null, bearer token is null
more tests added for tokenProvider and setTokenProvider
Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

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

Now you can squash the commits for merging.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants