Skip to content

Instantly share code, notes, and snippets.

@baso53
Created November 13, 2021 22:11
Show Gist options
  • Save baso53/03d44a169e03d128d673b8bb937b54d6 to your computer and use it in GitHub Desktop.
Save baso53/03d44a169e03d128d673b8bb937b54d6 to your computer and use it in GitHub Desktop.
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(jwtAuthenticationConverter());
}
public JwtAuthenticationConverter jwtAuthenticationConverter() {
JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
converter.setJwtGrantedAuthoritiesConverter(jwt ->
Optional.ofNullable(jwt.getClaimAsStringList("custom_claims"))
.stream()
.flatMap(Collection::stream)
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList())
);
return converter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment