diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c1cdaa1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM amazoncorretto:17-alpine +WORKDIR /app +COPY build/libs/*.jar app.jar +EXPOSE 8080 +ENV SPRING_PROFILES_ACTIVE=prod +ENTRYPOINT ["java","-jar","-Dspring.profiles.active=prod","app.jar"] \ No newline at end of file diff --git a/src/main/java/com/wooribound/global/security/DeletedUserFilter.java b/src/main/java/com/wooribound/global/security/DeletedUserFilter.java index f9bb3b7..048fcc3 100644 --- a/src/main/java/com/wooribound/global/security/DeletedUserFilter.java +++ b/src/main/java/com/wooribound/global/security/DeletedUserFilter.java @@ -6,11 +6,15 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; + +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; @Component public class DeletedUserFilter extends OncePerRequestFilter { + @Value("${targetIp}") + private String targetIp; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) @@ -19,7 +23,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse filterChain.doFilter(request, response); } catch (DeletedUserException e) { System.out.println("deleteduserfilter에서 잡아냄"); - response.sendRedirect("http://localhost:8080/deleted/user"); + response.sendRedirect("http://"+ targetIp +":8080/deleted/user"); } } } \ No newline at end of file diff --git a/src/main/java/com/wooribound/global/security/SecurityConfig.java b/src/main/java/com/wooribound/global/security/SecurityConfig.java index d8529ba..deb91de 100644 --- a/src/main/java/com/wooribound/global/security/SecurityConfig.java +++ b/src/main/java/com/wooribound/global/security/SecurityConfig.java @@ -16,6 +16,7 @@ import java.util.Collections; import java.util.Map; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; @@ -45,6 +46,10 @@ public class SecurityConfig { private final WbUserDetailService wbUserDetailService; private final AdminUserDetailService adminUserDetailService; private final EnterpriseUserDetailService enterpriseUserDetailService; + @Value("${targetIp}") + private String targetIp; + @Value("${targetPort}") + private String targetPort; @Bean public PasswordEncoder passwordEncoder() { @@ -95,8 +100,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(Arrays.asList( - "http://localhost:8080", - "http://127.0.0.1:8080", + "http://"+targetIp+":"+targetPort, "https://nid.naver.com", // 네이버 로그인 "https://openapi.naver.com" )); @@ -118,7 +122,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { if (exception instanceof OAuth2AuthenticationException) { Throwable authException = ((OAuth2AuthenticationException) exception).getCause(); if (authException instanceof DeletedUserException) { - response.sendRedirect("http://localhost:8080/deleted/user"); + response.sendRedirect("http://"+targetIp+":"+targetPort+"/deleted/user"); return; } } diff --git a/src/main/java/com/wooribound/global/security/successhandler/WbUserSuccessHandler.java b/src/main/java/com/wooribound/global/security/successhandler/WbUserSuccessHandler.java index 391aca1..d4b858b 100644 --- a/src/main/java/com/wooribound/global/security/successhandler/WbUserSuccessHandler.java +++ b/src/main/java/com/wooribound/global/security/successhandler/WbUserSuccessHandler.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.time.Duration; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; @@ -21,6 +22,11 @@ public class WbUserSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { private final JWTUtil jwtUtil; private final RedisUtil redisUtil; + @Value("${targetIp}") + private String targetIp; + @Value("${targetPort}") + private String targetPort; + @@ -49,13 +55,13 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo // 응답 // 응답 String redirectUrl_oldUser = UriComponentsBuilder - .fromUriString("http://localhost:8080") + .fromUriString("http://"+targetIp+":"+targetPort) .fragment("accessToken=" + accessToken) // Bearer 접두사 추가 .build() .toUriString(); String redirectUrl_newUser = UriComponentsBuilder - .fromUriString("http://localhost:8080/individual-user/register") + .fromUriString("http://"+targetIp+":"+targetPort+"/individual-user/register") .fragment("accessToken=" + accessToken) // fragment로 accesstoken 전송 .build() .toUriString(); diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 5fee248..33e21e8 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,10 +1,5 @@ -server.port=8081 - -# .env ?? -spring.config.import=optional:file:.env-prod[.properties] - targetIp = ${TARGET_IP} - +targetPort = ${TARGET_PORT} # Mysql spring.datasource.url=jdbc:mysql://${MYSQL_IP}:${MYSQL_PORT}/${MYSQL_DATABASE_NAME}?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul spring.datasource.username=${MYSQL_USERNAME} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 64f2230..9bb2bc6 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,7 @@ server.port=8081 spring.config.import=optional:file:.env[.properties] targetIp = ${TARGET_IP} +targetPort = ${TARGET_PORT} # Oracle ?? ?? #spring.datasource.url=jdbc:oracle:thin:@${ORACLE_IP}:${ORACLE_PORT}:${DATABASE_NAME}