Skip to content

Commit 08f68c9

Browse files
committed
Update JwtAuthenticationConverter Docs
Replaced usage of deprecated API Fixes gh-7062
1 parent 9639962 commit 08f68c9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

docs/manual/src/docs/asciidoc/_includes/servlet/preface/java-configuration.adoc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,17 +706,24 @@ public class DirectlyConfiguredJwkSetUri extends WebSecurityConfigurerAdapter {
706706
}
707707

708708
Converter<Jwt, AbstractAuthenticationToken> grantedAuthoritiesExtractor() {
709-
return new GrantedAuthoritiesExtractor();
709+
JwtAuthenticationConverter jwtAuthenticationConverter =
710+
new JwtAuthenticationConverter();
711+
jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter
712+
(new GrantedAuthoritiesExtractor());
713+
return jwtAuthenticationConveter;
710714
}
711715
```
712716

713717
which is responsible for converting a `Jwt` into an `Authentication`.
718+
As part of its configuration, we can supply a subsidiary converter to go from `Jwt` to a `Collection` of `GrantedAuthority`s.
714719

715-
We can override this quite simply to alter the way granted authorities are derived:
720+
That final converter might be something like `GrantedAuthoritiesExtractor` below:
716721

717722
```java
718-
static class GrantedAuthoritiesExtractor extends JwtAuthenticationConverter {
719-
protected Collection<GrantedAuthority> extractAuthorities(Jwt jwt) {
723+
static class GrantedAuthoritiesExtractor
724+
implements Converter<Jwt, Collection<GrantedAuthority>> {
725+
726+
public Collection<GrantedAuthority> convert(Jwt jwt) {
720727
Collection<String> authorities = (Collection<String>)
721728
jwt.getClaims().get("mycustomclaim");
722729

0 commit comments

Comments
 (0)