Skip to content

Commit

Permalink
Merge pull request #113 from WooRibound/feature/#111-for-prod
Browse files Browse the repository at this point in the history
Feature/#111 for prod
  • Loading branch information
soljjang777 authored Nov 20, 2024
2 parents 9961ea3 + a020067 commit 5ff529a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");
}
}
}
10 changes: 7 additions & 3 deletions src/main/java/com/wooribound/global/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
));
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;




Expand Down Expand Up @@ -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();
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 5ff529a

Please sign in to comment.