File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
src/main/java/org/terning/user/config Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -22,15 +22,20 @@ public class FcmConfig {
2222 @ PostConstruct
2323 public void init () {
2424 try {
25- String serviceKeyJson = fcmProperties .getServiceKey ();
26-
27- try (ByteArrayInputStream serviceAccountStream =
28- new ByteArrayInputStream (serviceKeyJson .getBytes (Encoding .UTF_8 ))) {
29-
25+ String base64EncodedServiceKey = fcmProperties .getServiceKey ();
26+
27+ if (base64EncodedServiceKey == null || base64EncodedServiceKey .isBlank ()) {
28+ throw new IllegalStateException ("Firebase service key is missing or blank." );
29+ }
30+
31+ byte [] decoded = java .util .Base64 .getDecoder ().decode (base64EncodedServiceKey );
32+
33+ try (ByteArrayInputStream serviceAccountStream = new ByteArrayInputStream (decoded )) {
34+
3035 FirebaseOptions options = FirebaseOptions .builder ()
3136 .setCredentials (GoogleCredentials .fromStream (serviceAccountStream ))
3237 .build ();
33-
38+
3439 if (FirebaseApp .getApps ().isEmpty ()) {
3540 FirebaseApp .initializeApp (options );
3641 log .info (FcmLogMessages .INIT_SUCCESS );
@@ -40,4 +45,4 @@ public void init() {
4045 throw new RuntimeException (FcmLogMessages .INIT_FAILED + e .getMessage (), e );
4146 }
4247 }
43- }
48+ }
You can’t perform that action at this time.
0 commit comments