Skip to content

Commit

Permalink
Merge pull request #113 from minseok1015/dev
Browse files Browse the repository at this point in the history
feat : security로 변경
  • Loading branch information
minseok1015 authored Aug 17, 2024
2 parents 796f513 + ccdb93a commit 00002e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
33 changes: 17 additions & 16 deletions src/main/java/store/itpick/backend/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package store.itpick.backend.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
Expand Down Expand Up @@ -33,25 +32,27 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http
.csrf(AbstractHttpConfigurer::disable)
// .cors(withDefaults()) // CORS 설정 추가
.cors(withDefaults()) // CORS 설정 추가
.formLogin(FormLoginConfigurer::disable)
.sessionManagement((sessionManagement) ->
.sessionManagement(sessionManagement ->
sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
);

return http.build();
}

// @Bean
// public CorsFilter corsFilter() {
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// CorsConfiguration config = new CorsConfiguration();
// config.setAllowCredentials(true);
// config.addAllowedOrigin("https://itpick.netlify.app");
// config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
// config.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token"));
// config.setExposedHeaders(Arrays.asList("set-cookie"));
// source.registerCorsConfiguration("/**", config);
// return new CorsFilter(source);
// }
}
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("https://itpick.netlify.app");
config.addAllowedOrigin("http://localhost:3000");
config.addAllowedOrigin("http://localhost:5173");
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
config.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token", "Accept", "X-Requested-With"));
config.setExposedHeaders(Arrays.asList("Authorization", "location"));
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}
20 changes: 10 additions & 10 deletions src/main/java/store/itpick/backend/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)



@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("http://localhost:3000", "http://localhost:5173", "https://localhost:5173",
"https://itpick.netlify.app")
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH","OPTIONS")
.exposedHeaders("location", "Authorization")
.allowedHeaders("Content-Type", "Authorization", "X-Requested-With", "Accept")
.allowCredentials(true);
}
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// registry.addMapping("/**")
// .allowedOriginPatterns("http://localhost:3000", "http://localhost:5173", "https://localhost:5173",
// "https://itpick.netlify.app")
// .allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH","OPTIONS")
// .exposedHeaders("location", "Authorization")
// .allowedHeaders("Content-Type", "Authorization", "X-Requested-With", "Accept")
// .allowCredentials(true);
// }



Expand Down

0 comments on commit 00002e6

Please sign in to comment.