Skip to content

Commit

Permalink
스프링 시큐리티 테스트용 셋팅
Browse files Browse the repository at this point in the history
  • Loading branch information
안승현 committed Dec 31, 2024
1 parent 00c0d75 commit 8aeca63
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

applicaion.properties

### IntelliJ IDEA ###
.idea
*.iws
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
8 changes: 8 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8aeca63

Please sign in to comment.