From 8aeca637756e1dd6d0485b730a0345bb37c561e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=8A=B9=ED=98=84?= Date: Tue, 31 Dec 2024 23:34:08 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8A=A4=ED=94=84=EB=A7=81=20=EC=8B=9C?= =?UTF-8?q?=ED=81=90=EB=A6=AC=ED=8B=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EC=85=8B=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ .../stayfinder/config/SecurityConfig.java | 36 +++++++++++++++++++ src/main/resources/application.properties | 8 +++++ 3 files changed, 46 insertions(+) create mode 100644 src/main/java/com/vacation/platform/stayfinder/config/SecurityConfig.java diff --git a/.gitignore b/.gitignore index c2065bc..0e0fa44 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ bin/ !**/src/main/**/bin/ !**/src/test/**/bin/ +applicaion.properties + ### IntelliJ IDEA ### .idea *.iws diff --git a/src/main/java/com/vacation/platform/stayfinder/config/SecurityConfig.java b/src/main/java/com/vacation/platform/stayfinder/config/SecurityConfig.java new file mode 100644 index 0000000..3b7734d --- /dev/null +++ b/src/main/java/com/vacation/platform/stayfinder/config/SecurityConfig.java @@ -0,0 +1,36 @@ +package com.vacation.platform.stayfinder.config; + + +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration +@EnableWebSecurity +public class SecurityConfig { + + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http + .csrf(AbstractHttpConfigurer::disable); + http + .headers((headerConfig) -> + headerConfig.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)); + + http + .authorizeHttpRequests((authorizationManagerRequestMatcherRegistry) -> + authorizationManagerRequestMatcherRegistry + .requestMatchers(PathRequest.toH2Console()).permitAll() +// .requestMatchers("**/**").permitAll() +// .anyRequest().authenticated() // 위에 패턴 이외에는 인증해야한다. + .anyRequest().permitAll() + ); + return http.build(); + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cb73064..27be42f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,9 @@ spring.application.name=stayfinder + + +spring.h2.console.path=/h2-console +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=123 +spring.h2.console.enabled=true \ No newline at end of file