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

Authorities Extraction #37

Closed
jzheaux opened this issue May 15, 2018 · 3 comments
Closed

Authorities Extraction #37

jzheaux opened this issue May 15, 2018 · 3 comments
Assignees
Labels
enhancement New feature or request Keycloak Issues identified from integration with Keycloak

Comments

@jzheaux
Copy link
Owner

jzheaux commented May 15, 2018

There are myriad ways to represent authorities in OAuth2 that go beyond scope. We need a hook so code can transform any custom representation of roles in access tokens into Spring Security roles:

Collection<? extend GrantedAuthority> extractAuthorities(AbstractOAuth2Token token)
@jzheaux jzheaux added enhancement New feature or request Keycloak Issues identified from integration with Keycloak labels May 15, 2018
@rwinch
Copy link
Collaborator

rwinch commented May 15, 2018

I'd prefer to make this a bit more generic. Accepting an Authentication and returning an Authentication would be ideal. This allows for more powerful transformations. We can always provide an abstract class that supports extracting the authorities only.

@jzheaux
Copy link
Owner Author

jzheaux commented May 15, 2018

Yes, I like that. Actually, I had that originally, but was a bit worried about it being too generic. I'll play with that a bit more and see what comes out.

Also, I experienced some heartburn over which Authentication to send in the case of something like JwtAccessTokenAuthenticationProvider. This works:

public Authentication authenticate(Authentication auth) {
    // ... verify JWT, etc.

    Collection<? extends GrantedAuthority> authorities =
        this.authoritiesExtractor.extractAuthorities(new JwtAuthenticationToken(jwt));

    return new JwtAuthenticationToken(jwt, authorities);
}

But the above code feels a bit icky since I end up constructing an authentication for the sole purpose of calling extractAuthorities. Not really a problem, but an indication that maybe there is another way to look at it.

jzheaux added a commit that referenced this issue May 15, 2018
A need that has come up multiple times now is to extract the roles
(or scopes) from an OAuth2 token in some custom way. This isn't
authority mapping since we aren't taking a list of GrantedAuthorities
and converting them into another list.

So, this commit introduces the concept of authority extraction into
the resource server.

Issue: gh-37
jzheaux added a commit that referenced this issue May 15, 2018
This sample is an enhancement of a sample from Thomas Darimont to
which I've simply added new Resource Server configuration.

Also, I made an attempt at reducing some of the code necessary to
extract authorities from the Keycloak token, but will need to do some
more searching.

Truthfully, I didn't test the OAuth Client piece just yet, just the
resource server integration, but will.

Issue: gh-37
jzheaux added a commit that referenced this issue May 15, 2018
Playing around with having the AuthoritiesExtractor take an
Authentication instead of an AbstractOAuth2Token.

Also, renamed to AuthoritiesExtractor since it is now a bit more
generic.

Issue: gh-37
jzheaux added a commit that referenced this issue May 15, 2018
Playing around with having the AuthoritiesExtractor take an
Authentication instead of an AbstractOAuth2Token.

Also, renamed to AuthoritiesExtractor since it is now a bit more
generic.

Issue: gh-37
@jzheaux jzheaux self-assigned this May 17, 2018
@jzheaux
Copy link
Owner Author

jzheaux commented May 30, 2018

Ah, I just reread your comment, and I missed that you prefer a contract that returns an Authentication as well. Will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Keycloak Issues identified from integration with Keycloak
Projects
None yet
Development

No branches or pull requests

2 participants