Skip to content

Commit

Permalink
Merge pull request #100 from TravelCompass-UMC/feature/96
Browse files Browse the repository at this point in the history
[#96] swagger에서 https, http, local 테스트할 수 있도록
  • Loading branch information
persi0815 authored Jul 17, 2024
2 parents f2ef287 + 6051a59 commit 178d988
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/travelcompass/api/global/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.travelcompass.api.global.config;

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

@Configuration
@EnableWebMvc
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000", "http://localhost:8080", "https://travel-compass.netlify.app", "http://travel-compass.netlify.app", "https://travel-compass.persi0815.site", "http://travel-compass.persi0815.site")
.allowedMethods("*")
.allowCredentials(true)
.maxAge(3600);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.travelcompass.api.global.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand All @@ -8,9 +10,14 @@
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@OpenAPIDefinition(
servers = {
@Server(url = "https://travel-compass.persi0815.site", description = "umc https 서버입니다."),
@Server(url = "http://travel-compass.persi0815.site", description = "umc http 서버입니다."),
@Server(url = "http://localhost:8080", description = "umc local 서버입니다.")
}
)
@Configuration
public class SwaggerConfig {
@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ protected SecurityFilterChain securityFilterChain(
return http.build();
}

/*
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://localhost:8080", "https://travel-compass.netlify.app", "http://travel-compass.netlify.app", "https://travel-compass.persi0815.site", "http://travel-compass.persi0815.site"));
configuration.setAllowedOriginPatterns(Arrays.asList("http://localhost:3000", "http://localhost:8080", "https://travel-compass.netlify.app", "http://travel-compass.netlify.app", "https://travel-compass.persi0815.site", "http://travel-compass.persi0815.site"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type"));
configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

import java.util.Optional;

@Slf4j
@Service
public class JpaUserDetailsManager implements UserDetailsManager {
// UserDetailsManager의 구현체로 만들면, Spring Security Filter에서 사용자 정보 회수에 활요할 수 있음
private final UserRepository userRepository;

public JpaUserDetailsManager(
UserRepository userRepository,
PasswordEncoder passwordEncoder
UserRepository userRepository
) {
this.userRepository = userRepository;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -22,8 +21,6 @@
public class UserService {
private final UserRepository userRepository;
private final RefreshTokenRepository refreshTokenRepository;

private final PasswordEncoder passwordEncoder;
private final JpaUserDetailsManager manager;
private final JwtTokenUtils jwtTokenUtils;

Expand Down

0 comments on commit 178d988

Please sign in to comment.