-
Notifications
You must be signed in to change notification settings - Fork 19
feat(auth): send from: on connect and reuse its challenge #410
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1ddc23c
feat(auth): send from: on connect and reuse its challenge
gkc ea9d8e3
refactor: attempt 1 to change impl as per @akafredperry review
gkc 6c37158
refactor(auth): issue from: via onReady and reuse its challenge acros…
gkc fcd4f8d
fix(build): drop Javadoc @link to Lombok-generated getters
gkc ec3989a
refactor(auth): single-source onboarding context, drop redundant buil…
gkc 1fca712
chore: weird formatting, my IDE went abit mad
gkc dc9a26f
chore: moar formatign
gkc fd01dad
fix: fixed challenge staleness bug which I introduced by this latest …
gkc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
at_client/src/main/java/org/atsign/client/api/AtCommandExecutorContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package org.atsign.client.api; | ||
|
|
||
| import lombok.*; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| /** | ||
| * The identity a connection authenticates as (its {@code atSign}, {@code keys} and {@code config}) | ||
| * together with the single-use challenge from the {@code from:} that is issued as the first command | ||
| * once the connection is ready. | ||
| * | ||
| * <p> | ||
| * The context is created by the builder (see | ||
| * {@code AtCommandExecutors#createCommandExecutor}) and closed over by the {@code onReady} | ||
| * consumers it wires, so the {@code from:} sender can retain the challenge and the authentication | ||
| * that follows on the same connection can reuse it rather than issuing a second {@code from:}. | ||
| * The command executor itself is pure transport and knows nothing about this context. | ||
| * | ||
| * <p> | ||
| * The identity fields are fixed for the life of the context. The challenge is per-connection state: | ||
| * {@link #setChallenge(String) retained} when the initial {@code from:} completes and | ||
| * {@link #consumeChallenge() consumed} at most once (the server's {@code from:} challenge is | ||
| * single-use). On reconnect the ready sequence re-runs, so a fresh challenge overwrites any | ||
| * previous | ||
| * one before it is consumed. | ||
| */ | ||
| @Value | ||
| public class AtCommandExecutorContext { | ||
|
|
||
| AtSign atSign; | ||
|
|
||
| AtKeys keys; | ||
|
|
||
| Map<String, Object> config; | ||
|
|
||
| @Getter(AccessLevel.NONE) | ||
| @EqualsAndHashCode.Exclude | ||
| @ToString.Exclude | ||
| AtomicReference<String> challenge = new AtomicReference<>(); | ||
|
|
||
| /** | ||
| * Retains the challenge returned by the initial {@code from:}, so the authentication that follows | ||
| * on the same connection can reuse it. | ||
| * | ||
| * @param challenge the challenge from the server's {@code from:} response | ||
| */ | ||
| public void setChallenge(String challenge) { | ||
| this.challenge.set(challenge); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the retained {@code from:} challenge and clears it, so it is consumed at most once. | ||
| * Whichever authentication (CRAM or PKAM) sends its digest first consumes it; anything else on the | ||
| * same connection gets {@code null} and must issue its own {@code from:}. | ||
| * | ||
| * @return the retained challenge, or {@code null} if none is available | ||
| */ | ||
| public String consumeChallenge() { | ||
| return challenge.getAndSet(null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are using Lombok, I would recommend for this class too (as will remove boiler plate). Something like this...