Skip to content
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

JwtParserBuilder NestedCollection overrides #961

Open
lhazlewood opened this issue Jul 29, 2024 · 3 comments · May be fixed by #970
Open

JwtParserBuilder NestedCollection overrides #961

lhazlewood opened this issue Jul 29, 2024 · 3 comments · May be fixed by #970
Labels
Milestone

Comments

@lhazlewood
Copy link
Contributor

Per #521 (comment), a nested collection .add call will not currently replace an existing algorithm with the same identifer (as the JavaDoc says it should). This issue represents the work to ensure this behavior works as documented.

For those needing this behavior, until this issue is fixed, the current workaround is to explicitly call .remove before calling .add:

var alg = new MyCustomAlgorithm();
Jwts.parser().sig()
        .remove(alg) // <-- 1.
        .add(alg)    // <-- 2.
        .and()// ... etc ...
@lhazlewood lhazlewood added the bug label Jul 29, 2024
@lhazlewood lhazlewood added this to the 0.12.7 milestone Jul 30, 2024
@lhy-hoyin
Copy link

Hi @lhazlewood, I would like to create a PR (as part of hacktoberfest) to resolve this bug. I propose to implement DefaultCollectionMutator.replace(E e) which internally call remove(E e) then doAdd(E e), something like:

public M replace(E e) {
    this.collection.remove(e);
    doAdd(e);

    // triger changed() callback accordingly
    if (...) changed();

    return self();
}

I have decided that DefaultCollectionMutator would be a good place to implement this since:

  • DefaultJwtParserBuilder.sig() returns new DefaultNestedCollection
  • DefaultNestedCollection extends DefaultCollectionMutator
  • DefaultCollectionMutator contains add(E e) and remove(E e) called in your sample code.

I am also running my idea through as I am not confident if it might bring about any security concerns.

I would appreciate any comments on (the feasibility of) my proposed solution, Thank you.

@lhazlewood
Copy link
Contributor Author

@lhy-hoyin Sorry for the delay, I had a minor family emergency and haven't been able to look at this, but I will be able to in about a week. @bdemers would you be able to look? Thanks for the Hacktobertest work!

@bdemers
Copy link
Member

bdemers commented Oct 15, 2024

@lhy-hoyin Sounds good, please send a pull request!

My suggestion would be to think about the unit tests too.
The proposed functionality is very similar to the current add method, though likely may need to handle a null item differently.

Let us know when you have a PR ready and we will take a look!

Tip

Add Fixes: #961 as the last line in your commit message, to automatically link it to this issue.

@lhy-hoyin lhy-hoyin linked a pull request Oct 16, 2024 that will close this issue
lhy-hoyin added a commit to lhy-hoyin/jjwt that referenced this issue Oct 19, 2024
add() is used instead of the previous replace(), but behaviour should still be the same.
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 a pull request may close this issue.

3 participants