Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -26,13 +27,11 @@ public void initialize() {
return;
}

Path path = Path.of(keyPath);
if (!Files.exists(path)) {
log.warn("FCM service account key file not found at: {}", keyPath);
return;
}
try (InputStream serviceAccount = getServiceAccountInputStream()) {
if (serviceAccount == null) {
return;
}

try (InputStream serviceAccount = Files.newInputStream(path)) {
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.build();
Expand All @@ -46,4 +45,23 @@ public void initialize() {
log.error("FCM initialization failed", e);
}
}

private InputStream getServiceAccountInputStream() throws Exception {
if (keyPath.startsWith("classpath:")) {
String resourcePath = keyPath.substring("classpath:".length());
ClassPathResource resource = new ClassPathResource(resourcePath);
if (!resource.exists()) {
log.warn("FCM service account resource not found in classpath: {}", keyPath);
return null;
}
return resource.getInputStream();
}

Path path = Path.of(keyPath);
if (!Files.exists(path)) {
log.warn("FCM service account key file not found at: {}", keyPath);
return null;
}
return Files.newInputStream(path);
}
}
Loading