Spring Security — authentication and authorization framework for Spring applications.
1@Configuration2@EnableWebSecurity3public class SecurityConfig {4 @Bean5 public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {6 http7 .authorizeHttpRequests(auth -> auth8 .requestMatchers("/public/**").permitAll()9 .requestMatchers("/admin/**").hasRole("ADMIN")10 .anyRequest().authenticated()11 )12 .oauth2Login(oauth -> oauth13 .userInfoEndpoint(info -> info14 .userService(oauth2UserService)15 )16 )17 .csrf(csrf -> csrf.disable());18 return http.build();19 }20}
Features: