SecurityConfig.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2020-2022 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package sample.config;
  17. import org.springframework.context.annotation.Bean;
  18. import org.springframework.context.annotation.Configuration;
  19. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  20. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  21. import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
  22. import org.springframework.security.web.SecurityFilterChain;
  23. import static org.springframework.security.config.Customizer.withDefaults;
  24. /**
  25. * @author Joe Grandja
  26. * @since 0.0.1
  27. */
  28. @EnableWebSecurity
  29. @Configuration(proxyBeanMethods = false)
  30. public class SecurityConfig {
  31. @Bean
  32. WebSecurityCustomizer webSecurityCustomizer() {
  33. return (web) -> web.ignoring().requestMatchers("/webjars/**");
  34. }
  35. // @formatter:off
  36. @Bean
  37. SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
  38. http
  39. .authorizeHttpRequests(authorize ->
  40. authorize.anyRequest().authenticated()
  41. )
  42. .oauth2Login(oauth2Login ->
  43. oauth2Login.loginPage("/oauth2/authorization/messaging-client-oidc"))
  44. .oauth2Client(withDefaults());
  45. return http.build();
  46. }
  47. // @formatter:on
  48. }