Created
November 13, 2021 22:11
-
-
Save baso53/03d44a169e03d128d673b8bb937b54d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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