Advertisement
SneakyElf

SecurityConfig.java

Nov 27th, 2023
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package com.example.moviesandbooksrecommendationsservice.security;
  2.  
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.security.config.Customizer;
  6. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  7. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  8. import org.springframework.security.web.SecurityFilterChain;
  9.  
  10. @Configuration
  11. @EnableWebSecurity
  12. public class SecurityConfig {
  13.  
  14.     @Bean
  15.     public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
  16.         http
  17.                 .authorizeHttpRequests(auth -> auth
  18.                         .requestMatchers("/secure/**").authenticated()
  19.                         .anyRequest().permitAll()
  20.                 )
  21.                 .oauth2Login(Customizer.withDefaults())
  22.                 .logout(logout -> logout
  23.                         .logoutUrl("/logout")
  24.                         .logoutSuccessUrl("/main")
  25.                         .invalidateHttpSession(true)
  26.                 );
  27.  
  28.         return http.build();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement