Skip to content

Commit

Permalink
[MERGE] hotfix/#25 -> dev
Browse files Browse the repository at this point in the history
[HOTFIX/#25] 속성 파일 인식 불가 이슈 해결 및 외부 파일 주입 방식 적용
  • Loading branch information
yummygyudon authored Dec 7, 2024
2 parents 8d671ad + 8f8452b commit 7b9a101
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ COPY --from=builder /app-build/build/libs/authentication.jar /app-run/authentica

EXPOSE 8080
ENTRYPOINT ["java"]
CMD ["-jar", "authentication.jar"]
CMD ["-Dspring.config.additional-location=file:/app-run/", "-jar", "authentication.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import sopt.makers.authentication.support.exception.external.ClientRequestException;
import sopt.makers.authentication.support.exception.external.ClientResponseException;
import sopt.makers.authentication.support.util.*;
import sopt.makers.authentication.support.value.AppleProperty;
import sopt.makers.authentication.support.value.AppleOAuthProperty;

import java.io.IOException;
import java.security.PrivateKey;
Expand All @@ -46,7 +46,7 @@
@RequiredArgsConstructor
@Slf4j
public class AppleAuthService implements OAuthService {
private final AppleProperty appleProperty;
private final AppleOAuthProperty appleOAuthProperty;
private final Gson gson;
private final OkHttpClient client;

Expand All @@ -60,7 +60,7 @@ public IdTokenResponse getIdTokenByCode(final String code) {
}

private FormBody createTokenRequestFormBody(final String code) {
String clientId = appleProperty.apple().sub();
String clientId = appleOAuthProperty.sub();
String clientSecret = createClientSecret();
return new FormBody.Builder()
.add(CLIENT_ID, clientId)
Expand All @@ -73,18 +73,17 @@ private FormBody createTokenRequestFormBody(final String code) {
private String createClientSecret() {
Date now = new Date();
PrivateKey privateKey =
KeyFileUtil.getPrivateKey(appleProperty.apple().key().path())
KeyFileUtil.getPrivateKey(appleOAuthProperty.key().path())
.orElseThrow(() -> new ClientRequestException(FAIL_READ_APPLE_PRIVATE_KEY_FILE));

return Jwts.builder() // 토큰 생성 로직은 tokenProvider? 근데 얘는 parse는 없음
.setHeaderParam(APPLE_KEY_ID_HEADER, appleProperty.apple().key().id())
.setHeaderParam(APPLE_KEY_ID_HEADER, appleOAuthProperty.key().id())
.setHeaderParam(APPLE_ALGORITHM_HEADER, APPLE_ALGORITHM_VALUE)
.setIssuedAt(now)
.setExpiration(
new Date(now.getTime() + appleProperty.apple().expiration().tokenExpiration()))
.setIssuer(appleProperty.apple().team().id())
.setAudience(appleProperty.apple().aud())
.setSubject(appleProperty.apple().sub())
.setExpiration(new Date(now.getTime() + appleOAuthProperty.expiration().tokenExpiration()))
.setIssuer(appleOAuthProperty.team().id())
.setAudience(appleOAuthProperty.aud())
.setSubject(appleOAuthProperty.sub())
.signWith(privateKey, SignatureAlgorithm.ES256)
.compact();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sopt.makers.authentication.external.oauth.dto.IdTokenResponse;
import sopt.makers.authentication.support.exception.external.ClientRequestException;
import sopt.makers.authentication.support.exception.external.ClientResponseException;
import sopt.makers.authentication.support.value.GoogleProperty;
import sopt.makers.authentication.support.value.GoogleOAuthProperty;

import java.io.IOException;

Expand All @@ -35,7 +35,7 @@
@Component
@RequiredArgsConstructor
public class GoogleAuthService implements OAuthService {
private final GoogleProperty googleProperty;
private final GoogleOAuthProperty googleOAuthProperty;
private final Gson gson;
private final OkHttpClient client;

Expand All @@ -50,11 +50,11 @@ public IdTokenResponse getIdTokenByCode(String code) {

private FormBody createTokenRequestFormBody(String code) {
return new FormBody.Builder()
.add(CLIENT_ID, googleProperty.google().client().id())
.add(CLIENT_SECRET, googleProperty.google().client().secret())
.add(CLIENT_ID, googleOAuthProperty.client().id())
.add(CLIENT_SECRET, googleOAuthProperty.client().secret())
.add(CODE, code)
.add(GRANT_TYPE, GRANT_TYPE_VALUE)
.add(REDIRECT_URI, googleProperty.google().redirect().url())
.add(REDIRECT_URI, googleOAuthProperty.redirect().url())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
@Configuration(value = "CustomApplicationConfig")
@ConfigurationPropertiesScan(basePackages = {"sopt.makers.authentication.support.value"})
@EnableConfigurationProperties({
AuthProperty.class,
GabiaProperty.class,
JwtProperty.class,
MakersProperty.class,
AppleProperty.class,
GoogleProperty.class
AppleOAuthProperty.class,
GoogleOAuthProperty.class
})
public class ApplicationConfig {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package sopt.makers.authentication.support.config;

import static sopt.makers.authentication.support.constant.SystemConstant.PATTERN_ALL;
import static sopt.makers.authentication.support.constant.SystemConstant.PATTERN_ACTUATOR;
import static sopt.makers.authentication.support.constant.SystemConstant.PATTERN_AUTH;
import static sopt.makers.authentication.support.constant.SystemConstant.PATTERN_ERROR_PATH;
import static sopt.makers.authentication.support.constant.SystemConstant.PATTERN_TEST;

import sopt.makers.authentication.support.security.filter.JwtAuthenticationFilter;
import sopt.makers.authentication.support.security.filter.JwtExceptionFilter;
import sopt.makers.authentication.support.value.AuthProperty;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -21,9 +20,6 @@
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import lombok.RequiredArgsConstructor;

Expand All @@ -36,7 +32,6 @@ public class SecurityConfig {

private final JwtAuthenticationFilter jwtAuthenticationFilter;
private final JwtExceptionFilter jwtExceptionFilter;
private final AuthProperty authProperty;

@Bean
public static PasswordEncoder passwordEncoder() {
Expand Down Expand Up @@ -75,7 +70,7 @@ private void setDefaultHttp(HttpSecurity http) throws Exception {
http.httpBasic(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)
.formLogin(AbstractHttpConfigurer::disable)
.cors(configurer -> configurer.configurationSource(corsConfigurationSource()))
.cors(AbstractHttpConfigurer::disable)
.sessionManagement(
configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
Expand All @@ -92,23 +87,9 @@ private void setSecuredHttp(HttpSecurity http) throws Exception {
.permitAll()
.requestMatchers(new AntPathRequestMatcher(PATTERN_ERROR_PATH))
.permitAll()
.requestMatchers(new AntPathRequestMatcher(PATTERN_ACTUATOR))
.permitAll()
.anyRequest()
.authenticated());
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

configuration.addAllowedOrigin(authProperty.client().url());
configuration.addAllowedHeader(ALL);
configuration.addAllowedMethod(ALL);
configuration.setAllowCredentials(true);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

source.registerCorsConfiguration(PATTERN_ALL, configuration);

return source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ private SystemConstant() {}

public static final String API_DEFAULT_PREFIX = API_PATH_PREFIX + API_VERSION;

public static final String PATH_ACTUATOR = "/actuator";
public static final String PATH_AUTH = "/auth";
public static final String PATH_ERROR = "/error";
public static final String PATH_TEST = "/test";

public static final String PATTERN_ALL = "/**";
public static final String PATTERN_ERROR_PATH = "/error";
public static final String PATTERN_AUTH = API_DEFAULT_PREFIX + "/auth" + PATTERN_ALL;
public static final String PATTERN_TEST = API_DEFAULT_PREFIX + "/test" + PATTERN_ALL;
public static final String PATTERN_ERROR_PATH = PATH_ERROR + PATTERN_ALL;
public static final String PATTERN_ACTUATOR = PATH_ACTUATOR + PATTERN_ALL;
public static final String PATTERN_AUTH = API_DEFAULT_PREFIX + PATH_AUTH + PATTERN_ALL;
public static final String PATTERN_TEST = API_DEFAULT_PREFIX + PATH_TEST + PATTERN_ALL;
public static final String PATTERN_ROOT_PATH = "/";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package sopt.makers.authentication.support.security.filter;

import static sopt.makers.authentication.support.constant.SystemConstant.PATH_ACTUATOR;
import static sopt.makers.authentication.support.constant.SystemConstant.PATH_AUTH;
import static sopt.makers.authentication.support.constant.SystemConstant.PATH_ERROR;
import static sopt.makers.authentication.support.constant.SystemConstant.PATH_TEST;

import sopt.makers.authentication.support.constant.JwtConstant;
import sopt.makers.authentication.support.jwt.provider.JwtAuthAccessTokenProvider;
import sopt.makers.authentication.support.security.authentication.CustomAuthentication;
Expand Down Expand Up @@ -42,7 +47,15 @@ protected void doFilterInternal(

@Override
public boolean shouldNotFilter(HttpServletRequest request) {
return isJwksRequest(request);
return isWhiteRequest(request) || isJwksRequest(request);
}

private boolean isWhiteRequest(final HttpServletRequest request) {
String url = request.getRequestURL().toString();
return url.contains(PATH_ACTUATOR)
|| url.contains(PATH_AUTH)
|| url.contains(PATH_ERROR)
|| url.contains(PATH_TEST);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "external.oauth.apple")
public record AppleProperty(Apple apple) {
public record Apple(String aud, String sub, Key key, Team team, Expiration expiration) {}
public record AppleOAuthProperty(
String aud, String sub, Key key, Team team, Expiration expiration) {

public record Key(String id, String path) {}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "external.oauth.google")
public record GoogleProperty(Google google) {
public record Google(Redirect redirect, Client client) {}

public record GoogleOAuthProperty(Redirect redirect, Client client) {
public record Redirect(String url) {}

public record Client(String id, String secret) {}
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ spring.config.activate.on-profile:
- local
external:
makers:
url: ${PLAYGROUND_URL}
token: ${PLAYGROUND_TOKEN}
playground:
url: ${PLAYGROUND_URL}
token: ${PLAYGROUND_TOKEN}
gabia:
sms:
id: ${GABIA_SMS_ID}
Expand Down Expand Up @@ -34,8 +35,9 @@ spring.config.activate.on-profile:
- test
external:
makers:
url: test
token: test
playground:
url: test
token: test
gabia:
sms:
id: test
Expand Down

0 comments on commit 7b9a101

Please sign in to comment.