Skip to content
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
5 changes: 4 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ jobs:
distribution: 'temurin'

- name: Set up Application Secret YML
run: echo "${{ secrets.APPLICATION_SECRET }}" | base64 --decode > src/main/resources/application-secret.yml
run: |
echo "${{ secrets.APPLICATION_SECRET }}" | base64 --decode > src/main/resources/application-secret.yml
echo "${{ secrets.APPLICATION_SECRET_LOCAL }}" | base64 --decode > src/main/resources/application-secret-local.yml
echo "${{ secrets.APPLICATION_SECRET_DEV }}" | base64 --decode > src/main/resources/application-secret-dev.yml

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ out/
.vscode/

### Properties ###
application-secret.yml
application-secret**
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package com.jobnote.auth.handler;

import com.jobnote.global.config.properties.FrontendProperties;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

@RequiredArgsConstructor
@Component
public class OAuth2LoginFailureHandler extends SimpleUrlAuthenticationFailureHandler {

@Value("${app.frontend.base-url}")
private String frontendBaseUrl;
private final FrontendProperties frontendProperties;

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
response.sendRedirect(frontendBaseUrl);
response.sendRedirect(frontendProperties.baseUrl() + frontendProperties.loginFailPage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import com.jobnote.auth.token.TokenProvider;
import com.jobnote.domain.user.domain.UserRole;
import com.jobnote.domain.user.service.AuthTokenService;
import com.jobnote.global.config.properties.FrontendProperties;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;

import java.io.IOException;

Expand All @@ -22,26 +23,33 @@ public class OAuth2LoginSuccessHandler extends SimpleUrlAuthenticationSuccessHan

private final TokenProvider tokenProvider;
private final AuthTokenService authTokenService;

@Value("${app.frontend.base-url}")
private String frontendBaseUrl;
private final FrontendProperties frontendProperties;

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
final CustomUserDetails principal = (CustomUserDetails) authentication.getPrincipal();

if (UserRole.GUEST.getKey().equals(principal.getRole())) {
response.sendRedirect(frontendBaseUrl + guestRedirectQueryString(principal.getEmail()));
response.sendRedirect(guestRedirectUrl(principal.getEmail()));
return;
}

final Token token = authTokenService.saveAndGetToken(principal.getUserId());
tokenProvider.addTokenToCookie(response, token);

response.sendRedirect(frontendBaseUrl);
response.sendRedirect(memberRedirectUrl());
}

private String guestRedirectUrl(final String email) {
return UriComponentsBuilder.fromUriString(frontendProperties.baseUrl())
.path(frontendProperties.mainPage())
.queryParam("sign-up-required", true)
.queryParam("email", email)
.build()
.toUriString();
}

private String guestRedirectQueryString(final String email) {
return String.format("?sign-up-required=true&email=%s", email);
private String memberRedirectUrl() {
return frontendProperties.baseUrl() + frontendProperties.mainPage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.jobnote.domain.email.service.VerificationEmailService;
import com.jobnote.global.common.ApiResponse;
import com.jobnote.global.common.ResponseCode;
import com.jobnote.global.config.properties.FrontendProperties;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -19,9 +19,7 @@
public class VerificationEmailController {

private final VerificationEmailService verificationEmailService;

@Value("${app.frontend.base-url}")
private String frontendBaseUrl;
private final FrontendProperties frontendProperties;

/* SEND VERIFICATION EMAIL */
@PostMapping
Expand All @@ -34,12 +32,12 @@ public ResponseEntity<ApiResponse<Void>> sendVerificationEmail(@RequestBody @Val
@GetMapping("/signup/verify")
public void verifySignUpEmail(@RequestParam("token") final String token, final HttpServletResponse response) throws IOException {
verificationEmailService.verifySignUp(token);
response.sendRedirect(frontendBaseUrl);
response.sendRedirect(frontendProperties.baseUrl() + frontendProperties.mainPage());
}

@GetMapping("/reset-password/verify")
public void verifyResetPasswordEmail(@RequestParam("token") final String token, final HttpServletResponse response) throws IOException {
verificationEmailService.verify(token);
response.sendRedirect(frontendBaseUrl);
response.sendRedirect(frontendProperties.baseUrl() + frontendProperties.resetPasswordPage());
}
}
9 changes: 5 additions & 4 deletions src/main/java/com/jobnote/global/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jobnote.global.config;

import org.springframework.beans.factory.annotation.Value;
import com.jobnote.global.config.properties.FrontendProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
Expand All @@ -9,11 +10,11 @@

import java.util.List;

@RequiredArgsConstructor
@Configuration
public class CorsConfig {

@Value("${app.frontend.base-url}")
private String frontendBaseUrl;
private final FrontendProperties frontendProperties;

@Bean
public CorsConfigurationSource corsConfigurationSource() {
Expand All @@ -24,7 +25,7 @@ public CorsConfigurationSource corsConfigurationSource() {

private CorsConfiguration corsConfiguration() {
final CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowedOrigins(List.of(frontendBaseUrl));
corsConfiguration.setAllowedOrigins(List.of(frontendProperties.baseUrl(), frontendProperties.localUrl()));
corsConfiguration.setAllowedMethods(List.of("*"));
corsConfiguration.setAllowedHeaders(List.of("*"));
corsConfiguration.setAllowCredentials(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.jobnote.global.config.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "frontend")
public record FrontendProperties(
String baseUrl,
String mainPage,
String socialSignUpPage,
String loginFailPage,
String resetPasswordPage,
String localUrl
) {

}
4 changes: 4 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app:
base-url: https://jobnote.p-e.kr
frontend:
base-url: https://job-note.vercel.app
4 changes: 2 additions & 2 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ logging:

app:
base-url: http://localhost:8080
frontend:
base-url: http://localhost:5173
frontend:
base-url: http://localhost:3000
12 changes: 10 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ spring:

profiles:
group:
local: secret
test: secret
local: local, secret, secret-local
dev: dev, secret, secret-dev
test: test

security:
oauth2:
Expand Down Expand Up @@ -47,3 +48,10 @@ app:
file:
quota:
per-user: 100MB

frontend:
local-url: http://localhost:3000
main-page: /dashboard
login-fail-page: /login/fail
social-sign-up-page: /join/nickname
reset-password-page: /reset-password
45 changes: 43 additions & 2 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,47 @@ spring:
hibernate:
format_sql: true

mail:
host: test
username: test
password: test
port: 1

security:
oauth2:
client:
registration:
naver:
client-id: test
client-secret: test
redirect-uri: test
google:
client-id: test
client-secret: test
redirect-uri: test
kakao:
client-id: test
client-secret: test
redirect-uri: test

jwt:
secret: q6we2uemsCYp3d4F4omkIy7MetsXW4rAxJX9In+D/tg=
access-token:
expiration-time: 3000
refresh-token:
expiration-time: 3000

cloud:
aws:
credentials:
access-key: test
secret-key: test
region:
static: test
s3:
bucket: test

app:
frontend:
base-url: http://localhost:5173
base-url: test
frontend:
base-url: test
Loading