Skip to content

Commit

Permalink
[#2]๐Ÿ›Fix: cors ์„ค์ •
Browse files Browse the repository at this point in the history
  • Loading branch information
sumin220 committed Nov 22, 2024
1 parent fa916e3 commit 9aedca3
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 55 deletions.
24 changes: 0 additions & 24 deletions src/main/java/univ/yesummit/global/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.OncePerRequestFilter;
import univ.yesummit.global.auth.util.JwtUtils;
import univ.yesummit.global.oauth.OAuth2MemberService;
Expand Down Expand Up @@ -56,9 +51,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
// csrf ์ฐจ๋‹จ
.csrf(AbstractHttpConfigurer::disable)

// cors ์„ค์ •
// .cors(cors -> cors.configurationSource(corsConfigurationSource()))

// ์‹œํ๋ฆฌํ‹ฐ ๊ธฐ๋ณธ ๋กœ๊ทธ์ธ ๋น„ํ™œ์„ฑํ™”
.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)
Expand Down Expand Up @@ -99,22 +91,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.build();
}

// @Value("${cors.allowed-origins")
// private List<String> allowOriginList;

// @Bean
// public CorsConfigurationSource corsConfigurationSource() {
// CorsConfiguration configuration = new CorsConfiguration();
// configuration.addAllowedOrigin("http://localhost:3000"); // ํด๋ผ์ด์–ธํŠธ ์ฃผ์†Œ
// configuration.addAllowedMethod("*");
// configuration.addAllowedHeader("*");
// configuration.setAllowCredentials(true);
// configuration.addExposedHeader("Authorization");
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// source.registerCorsConfiguration("/**", configuration);
// return source;
// }

public class JwtAuthenticationFilter extends OncePerRequestFilter {
private final JwtUtils jwtUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ public class WebMvcConfig implements WebMvcConfigurer {

private final AuthArgumentResolver authArgumentResolver;

// @Override
// public void addCorsMappings(final CorsRegistry registry ){
// registry.addMapping("/**")
// .allowedOriginPatterns("*")
// .allowedMethods("PATCH","GET","POST","PUT","DELETE","HEAD","OPTIONS")
// .allowedHeaders("*")
// .allowCredentials(true);
// }

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
WebMvcConfigurer.super.addArgumentResolvers(resolvers); // ๊ธฐ์กด Resolver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package univ.yesummit.global.auth.controller;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.RedirectView;


import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/v1/api/kakao")
public class AuthController {
Expand All @@ -22,18 +15,4 @@ public class AuthController {
public RedirectView login() {
return new RedirectView("/oauth2/authorization/kakao");
}

@GetMapping("/status")
@Operation(summary = "๋กœ๊ทธ์ธ ์ƒํƒœ ํ™•์ธ", description = "์‚ฌ์šฉ์ž์˜ ๋กœ๊ทธ์ธ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.")
public ResponseEntity<Map<String, Boolean>> getLoginStatus(HttpServletRequest request) {
// ์ฟ ํ‚ค ๋˜๋Š” ์„ธ์…˜์—์„œ ๋กœ๊ทธ์ธ ์ƒํƒœ๋ฅผ ํ™•์ธ
HttpSession session = request.getSession(false); // ์„ธ์…˜์ด ์—†์œผ๋ฉด null ๋ฐ˜ํ™˜
boolean loggedIn = session != null && session.getAttribute("user") != null;

// ์‘๋‹ต ๋ฐ์ดํ„ฐ ์ƒ์„ฑ
Map<String, Boolean> response = new HashMap<>();
response.put("loggedIn", loggedIn);

return ResponseEntity.ok(response);
}
}
}

0 comments on commit 9aedca3

Please sign in to comment.