Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#111 for prod #113

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading