-
Notifications
You must be signed in to change notification settings - Fork 582
Allow pluggable means of acquiring the username and password for authentication #350
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
Conversation
implementation that simply tracks a static username and password. Useful for reconnect scenarios where the username or password might have changed between the connect & reconnect.
Unfortunately I am not able to log in to concourse-ci to see what failed a check or why it failed. If someone can copy/paste for me, I can look into it more thoroughly. |
Here's the most relevant output:
We can dig up a log archive if needed. |
I think it's a good idea. @acogoluegnes can this also go into 4.5.0? |
Thanks, @michaelklishin. Most likely I just need to update those tests, especially if they're doing anything reflectiony to get/set values. I'll look at that now. |
(and immutable) strings, a .clone() operation needs to specifically return a clone of the CredentialsProvider that can be modified with setUsername/setPassword without affecting the original instance.
@spatula75 CI failed somewhere else, here's the output:
@michaelklishin It can go into 4.5.0, we'll release a milestone once we're done with this PR. |
@spatula75 Failure is reproductible in NIO mode, digging further. |
@spatula75 username is used in |
CredentialsProvider interface is reduced to the bare minimum of methods (getting username and password). Test in connection recovery test suite is fixed, as NIO mode can retrieve username several times for logging. References #350
@spatula75 Thanks for this! You can have a look at the polish commit. This will be released in 4.5.0.RC2 in the next days. |
Thanks for fixing my bug, @acogoluegnes! I likely missed it by not running the test in NIO mode. And thanks for the amazingly fast turnaround on the PR! |
@acogoluegnes incidentally, I like your solution for setting the username/password in the DefaultCredentialsProvider... did a bit of a face-palm "why didn't I think of that," and I'm tucking it away in the back of my brain for use again later, so thanks for that! Makes the interface more like how I really wanted it to be (with just the getters). |
Use a CredentialsProvider to pass usernames & passwords into AMQConnection with default
implementation that simply tracks a static username and password. Useful
for reconnect scenarios where the username or password might have
changed between the connect & reconnect. Doesn't break the existing API,
which uses the DefaultCredentialsProvider unless otherwise configured
with setCredentialsProvider.
Proposed Changes
Rationale: in some customized AuthC/AuthZ scenarios, especially where someone may be using auth_backend_http, a username or a password might change between the time it was first used and the time it was needed to reconnect for a connection recovery.
By passing a CredentialsProvider (in a ConnectionParameters) to AMQConnection instead of a static username and password, and by requesting the username and password of the CredentialsProvider just prior to using them to connect, it is possible to provide a custom instance which knows how to go and fetch new credentials if necessary prior to making the connection.
So for example, if a custom token-based oauth scheme is used, and the token is short-lived, this custom implementation could request a new oauth token to be provided as the 'password', which then gets validated on the other side of the request by auth_backend_http.
Without some mechanism to refresh credentials, a recovery would continue to use the original token, which may no longer be valid.
It's also conceivable that it may be useful in some cases to have a username provided to a dumb client by some API call in a manner which is semi-random or at least changeable. That, too, would be supportable by a custom CredentialsProvider (and then again handled by a custom server with auth_backend_http).
Types of Changes
What types of changes does your code introduce to this project?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creatingthe PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.
CONTRIBUTING.md
documentFurther Comments
I'm still finding my way around in the test infrastructure, but I will try to add some tests for a custom CredentialsProvider as well once I figure it out. Existing tests with the new DefaultCredentialsProvider are working in my local environment, so I'm reasonably confident.
Apologies for hitting cmd-shift-O (force of habit) once in ConnectionFactory and creating some spurious differences where Eclipse did an "organize imports". I can try to revert that if it's important.
I selfishly made these changes on the 4.4 branch because we're stuck with 4.4 until we can end our Java 7 support in the wild.