jzheaux / spring-security

Spring Security
http://spring.io/spring-security
Apache License 2.0
4 stars 3 forks source link

Add authorities extraction #21

Open jzheaux opened 6 years ago

jzheaux commented 6 years ago

At times, it will be necessary to customize how scopes are derived from incoming JWTs.

In most cases, taking each scope from the "scope" or "scp" attribute and prepending "SCOPE_" on each will be sufficient; however, when that is not the case, then we should have a hook for users to customize this.

Three contracts have been proposed to this point:

Collection<? extends GrantedAuthority> extract(AbstractOAuth2Token token)
Authentication extract(AbstractOAuth2Token token)
Authentication extract(Authentication token)

The merits of each have been discussed in various threads [1] [2], and the final contract is still open for debate.

[1] - https://github.com/jzheaux/spring-security/issues/7 [2] - https://github.com/jzheaux/spring-security-oauth2-resource-server/issues/37

Thank you, by the way, for everyone's contribution to this discussion. Below, I'll summarize some of the thoughts from the above tickets (as well as add a couple more) and explain why I propose AuthoritiesPopulator: Authentication -> Collection<GrantedAuthorities>