Skip to content

Add constructor to JwtAuthenticationToken that takes a principal nameΒ #6865

Closed

Description

@jzheaux

OAuth2IntrospectionAuthenticationToken takes a name as a constructor parameter and otherwise defaults to the token's SUB claim for the principal name.

JwtAuthenticationToken, on the other hand, provides no way to customize this.

It'd be nice to do the same for JwtAuthenticationToken:

public JwtAuthenticationToken(Jwt jwt, Collection<? extends GrantedAuthority> authorities, String name) {
    // ...

This encourages composition over inheritance while also keeping the application from having to create a custom class to override this default behavior.

Activity

  1. added
    in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
    status: first-timers-onlyAn issue that can only be worked on by brand new contributors
    on May 13, 2019
  2. HaydenMeloche commented on May 16, 2019

    @HaydenMeloche
    Contributor

    I'd like to submit a PR for this issue. Taking a look at JwtAuthenticationToken it doesn't currently have a name value like OAuth2IntrospectionAuthenticationToken does. I also noticed that currently getName returns the tokens subject. Should I be creating a new name variable or setting something somewhere else?

    Sorry if silly question, first time around here :)

  3. rhamedy commented on May 17, 2019

    @rhamedy
    Contributor

    @HaydenMeloche if I understand correctly, you will be mimicking the OAuth2IntrospectionAuthenticationToken by adding name and introducing the suggested constructor.

    As far the getName question, if you look at OAuth2IntrospectionAuthenticationToken constructor the line this.name = name == null ? (String) attributes.get(SUBJECT) : name; does the trick of either setting the provided name (if not null) or defaulting to attributes.get(SUBJECT) so when the getName() returns this.name it is either of the two hence, functioning the same way as OAuth2IntrospectionAuthenticationToken.

    You might be able to provide a PR for this since it is tagged with first-timers-only and no one has claimed it yet πŸ‘

    I am not part of Spring team but, I felt like I could answer your questions and I hope I did not confuse you πŸ™‚

  4. jzheaux commented on May 20, 2019

    @jzheaux
    CollaboratorAuthor

    @HaydenMeloche welcome! Yes, @rhamedy's analysis is correct, and yes, it'd be great to see a PR from you.

  5. HaydenMeloche commented on May 23, 2019

    @HaydenMeloche
    Contributor

    I believe this issue can be closed now.
    #6893

  6. jzheaux commented on May 24, 2019

    @jzheaux
    CollaboratorAuthor

    Closed via f84ab3a

  7. self-assigned this
    on Jun 13, 2019
  8. added this to the 5.2.0.M3 milestone on Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions