Skip to content

Commit

Permalink
fix : SecurityConfig 생성 - swagger cors해결
Browse files Browse the repository at this point in the history
  • Loading branch information
genius00hwan committed Nov 28, 2024
1 parent 65b92ab commit 1d9e485
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ dependencies {
//swagger 설정
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

implementation 'org.springframework.boot:spring-boot-starter-security'



}

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/icurriculum/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package icurriculum.global.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

@EnableMethodSecurity
@RequiredArgsConstructor
@Configuration
public class SecurityConfig {

@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(request ->
request.requestMatchers("/api/**").permitAll()
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/swagger-resources/**")
.permitAll()
.anyRequest().permitAll()
)
.build();
}

}

0 comments on commit 1d9e485

Please sign in to comment.