Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class JwtGrantedAuthoritiesConverter

  1. Object
  2. JwtGrantedAuthoritiesConverter

ImplementsConverter<Jwt, Collection<GrantedAuthority>>

Reads a token’s authorities out of one claim: each value, with a prefix in front.

Unless told otherwise the claim is scope – one text, the scopes separated by spaces, as RFC 8693 and most issuers write it – or else scp, and the prefix is SCOPE_. A token with "scope": "orders:read orders:write" is granted SCOPE_orders:read and SCOPE_orders:write, which is what hasAuthority("SCOPE_orders:read") asks for.

JwtGrantedAuthoritiesConverter roles = new JwtGrantedAuthoritiesConverter();
roles.setAuthoritiesClaimName("roles");     // ["ADMIN", "USER"]
roles.setAuthorityPrefix("ROLE_");          // so hasRole("ADMIN") matches

Constructors

public JwtGrantedAuthoritiesConverter()

Methods

public void setAuthorityPrefix(String authorityPrefix)What goes in front of every value; SCOPE_ unless set, and empty for none.
public void setAuthoritiesClaimName(String authoritiesClaimName)The claim to read, in place of scope and scp.
public Collection<GrantedAuthority> convert(Jwt jwt)What source becomes; null when it becomes nothing.

Inherited methods

Constructor details

JwtGrantedAuthoritiesConverter

public JwtGrantedAuthoritiesConverter()

Method details

setAuthorityPrefix

public void setAuthorityPrefix(String authorityPrefix)
What goes in front of every value; SCOPE_ unless set, and empty for none.

setAuthoritiesClaimName

public void setAuthoritiesClaimName(String authoritiesClaimName)
The claim to read, in place of scope and scp.

convert

public Collection<GrantedAuthority> convert(Jwt jwt)
What source becomes; null when it becomes nothing.