From 45eb5ca1185928eb95ac47d4805c223d68f6186f Mon Sep 17 00:00:00 2001 From: suyeon Date: Wed, 15 Jan 2025 00:49:10 +0900 Subject: [PATCH] =?UTF-8?q?hotfix/notificationToken-nullable-1:=20deviceId?= =?UTF-8?q?,=20pushToken=20nullable=20=EC=B2=98=EB=A6=AC=ED=95=B4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=95=88=EB=90=A8=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dife/api/config/ApnsJwtGenerator.java | 57 ------------------- .../dife/api/service/NotificationService.java | 3 - src/main/resources/application-local.yml | 5 -- src/main/resources/application.yml | 5 -- .../java/com/dife/api/config/TestConfig.java | 5 -- src/test/resources/application.yml | 7 +-- 6 files changed, 1 insertion(+), 81 deletions(-) delete mode 100644 src/main/java/com/dife/api/config/ApnsJwtGenerator.java diff --git a/src/main/java/com/dife/api/config/ApnsJwtGenerator.java b/src/main/java/com/dife/api/config/ApnsJwtGenerator.java deleted file mode 100644 index e9463e19..00000000 --- a/src/main/java/com/dife/api/config/ApnsJwtGenerator.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.dife.api.config; - -import com.auth0.jwt.JWT; -import com.auth0.jwt.algorithms.Algorithm; -import java.security.KeyFactory; -import java.security.PrivateKey; -import java.security.interfaces.RSAPrivateKey; -import java.security.spec.PKCS8EncodedKeySpec; -import java.util.Date; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("!test") -public class ApnsJwtGenerator { - - @Value("${apn.team-id}") - private String teamId; - - @Value("${apn.key-id}") - private String keyId; - - @Value("${apn.private-key}") - private String privateKey; - - private String cachedJwt; - - public String generateJwt() throws Exception { - if (cachedJwt == null || isJwtExpired()) { - cachedJwt = createJwt(); - } - return cachedJwt; - } - - private boolean isJwtExpired() { - return false; - } - - private String createJwt() throws Exception { - PrivateKey privateKey = loadPrivateKey(); - - return JWT.create() - .withIssuer(teamId) - .withKeyId(keyId) - .withIssuedAt(new Date()) - .withExpiresAt(new Date(System.currentTimeMillis() + 86400000)) - .sign(Algorithm.RSA256(null, (RSAPrivateKey) privateKey)); - } - - private PrivateKey loadPrivateKey() throws Exception { - PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKey.getBytes()); - - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - return keyFactory.generatePrivate(keySpec); - } -} diff --git a/src/main/java/com/dife/api/service/NotificationService.java b/src/main/java/com/dife/api/service/NotificationService.java index ef06c4e5..6300f79e 100644 --- a/src/main/java/com/dife/api/service/NotificationService.java +++ b/src/main/java/com/dife/api/service/NotificationService.java @@ -2,7 +2,6 @@ import static java.util.stream.Collectors.toList; -import com.dife.api.config.ApnsJwtGenerator; import com.dife.api.exception.MemberNotFoundException; import com.dife.api.exception.NotificationAuthorizationException; import com.dife.api.exception.NotificationException; @@ -22,7 +21,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.modelmapper.ModelMapper; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -39,7 +37,6 @@ public class NotificationService { private final MemberRepository memberRepository; private final NotificationTokenRepository notificationTokenRepository; private final NotificationRepository notificationRepository; - @Autowired private final ApnsJwtGenerator apnsJwtGenerator; public NotificationTokenResponseDto sendNotificationToken( String memberEmail, NotificationTokenRequestDto requestDto) { diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index e52d5c0c..5667c380 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -24,8 +24,3 @@ logging: socket: trace translation: api-key: ${DEEPL_TRANSLATE_API_KEY} - -apn: - key-id: ${APN_TEAM_ID} - team-id: ${APN_KEY_ID} - private-key: ${APN_PRIVATE_KEY} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b6140485..04233433 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -43,11 +43,6 @@ spring: translation: api-key: ${DEEPL_TRANSLATE_API_KEY} -apn: - key-id: ${APN_TEAM_ID} - team-id: ${APN_KEY_ID} - private-key: ${APN_PRIVATE_KEY} - logging: level: org: diff --git a/src/test/java/com/dife/api/config/TestConfig.java b/src/test/java/com/dife/api/config/TestConfig.java index 27c64902..cd8ebe03 100644 --- a/src/test/java/com/dife/api/config/TestConfig.java +++ b/src/test/java/com/dife/api/config/TestConfig.java @@ -18,9 +18,4 @@ public JavaMailSender javaMailSender() { public FileService fileService() { return mock(FileService.class); } - - @Bean - public ApnsJwtGenerator apnsJwtGenerator() { - return mock(ApnsJwtGenerator.class); - } } diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 9736bc15..309257b7 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -24,9 +24,4 @@ jwt: secret: 001b8ec844c5353413ba8b8c0025c94499eb25ae7486652efb2a89535b2d1a4f translation: - api-key: test - -apn: - key-id: test - team-id: test - private-key: test \ No newline at end of file + api-key: test \ No newline at end of file