Skip to content

Instantly share code, notes, and snippets.

@baso53
Last active August 23, 2023 08:56
Show Gist options
  • Save baso53/5d672dce9bd7bc6baacea83af4c9235a to your computer and use it in GitHub Desktop.
Save baso53/5d672dce9bd7bc6baacea83af4c9235a to your computer and use it in GitHub Desktop.
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest()
.authenticated();
http.oauth2ResourceServer()
.jwt();
}
}
@DeyvidDimitrov
Copy link

Just in case someone is coming from the article in Spring Security 6.1.x it will look like:

@RequiredArgsConstructor
@Configuration
public class WebSecurityConfiguration  {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http, AuthenticationConfiguration authenticationConfiguration) throws Exception {
        http.authorizeHttpRequests(auth -> auth.anyRequest().authenticated()).oauth2ResourceServer((oauth2) -> oauth2.jwt(Customizer.withDefaults()));

        return http.build();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment