Skip to content

Commit

Permalink
sercurity config 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yooonwodyd committed Feb 20, 2024
1 parent c7d0ac9 commit 6e1e189
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
38 changes: 19 additions & 19 deletions src/main/java/com/gdsc/pikpet/config/WebMvcConfig.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.gdsc.pikpet.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
//모든 경로에 대해
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("GET","POST","PUT","PATCH","DELETE","OPTIONS")
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(3600);
}
}
//package com.gdsc.pikpet.config;
//
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.CorsRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
//@Configuration
//public class WebMvcConfig implements WebMvcConfigurer {
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// //모든 경로에 대해
// registry.addMapping("/**")
// .allowedOriginPatterns("*")
// .allowedMethods("GET","POST","PUT","PATCH","DELETE","OPTIONS")
// .allowedHeaders("*")
// .allowCredentials(true)
// .maxAge(3600);
// }
//}
34 changes: 18 additions & 16 deletions src/main/java/com/gdsc/pikpet/config/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public SecurityFilterChain securityFilterChain(
);

http.csrf(cr -> cr.disable());
http.formLogin(
http.
cors(cors -> cors.configurationSource(corsConfigurationSource()))
.formLogin(
formLogin ->
formLogin.loginPage("/loginPage/formLogin")
.loginProcessingUrl("/login")
Expand All @@ -49,21 +51,21 @@ public SecurityFilterChain securityFilterChain(
return http.build();
}

// @Bean
// public CorsConfigurationSource corsConfigurationSource() {
// CorsConfiguration config = new CorsConfiguration();
// config.setAllowedOrigins(List.of("*", "http://localhost:5173"));
// config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
// config.setAllowedHeaders(List.of("*"));
// config.setExposedHeaders(List.of("*"));
//
// // 쿠키를 포함한 요청을 허용하기 위해 true로 설정
// config.setAllowCredentials(true);
//
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// source.registerCorsConfiguration("/**", config);
// return source;
// }
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOriginPatterns(List.of("*"));
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
config.setAllowedHeaders(List.of("*"));
config.setExposedHeaders(List.of("*"));

// 쿠키를 포함한 요청을 허용하기 위해 true로 설정
config.setAllowCredentials(true);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return source;
}

@Bean
public PasswordEncoder passwordEncoder() {
Expand Down

0 comments on commit 6e1e189

Please sign in to comment.