sarvenyanik commited on
Commit
ae86bbc
·
1 Parent(s): eb42a5e

firebase config update

Browse files
src/main/java/com/artandscience/security/SecurityApplication.java CHANGED
@@ -2,10 +2,12 @@ package com.artandscience.security;
2
 
3
  import org.springframework.boot.SpringApplication;
4
  import org.springframework.boot.autoconfigure.SpringBootApplication;
 
5
  import org.springframework.scheduling.annotation.EnableScheduling;
6
 
7
  @SpringBootApplication
8
  @EnableScheduling
 
9
  public class SecurityApplication {
10
 
11
  public static void main(String[] args) {
 
2
 
3
  import org.springframework.boot.SpringApplication;
4
  import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+ import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
6
  import org.springframework.scheduling.annotation.EnableScheduling;
7
 
8
  @SpringBootApplication
9
  @EnableScheduling
10
+ @ConfigurationPropertiesScan("com.artandscience.security.configuration.properties")
11
  public class SecurityApplication {
12
 
13
  public static void main(String[] args) {
src/main/java/com/artandscience/security/configuration/FirebaseConfig.java CHANGED
@@ -1,26 +1,46 @@
1
  package com.artandscience.security.configuration;
2
 
 
 
3
  import com.google.auth.oauth2.GoogleCredentials;
4
  import com.google.firebase.FirebaseApp;
5
  import com.google.firebase.FirebaseOptions;
6
  import jakarta.annotation.PostConstruct;
 
7
  import org.springframework.stereotype.Component;
8
 
 
9
  import java.io.FileInputStream;
10
  import java.io.IOException;
 
 
11
 
12
  @Component
 
13
  public class FirebaseConfig {
 
 
 
14
  @PostConstruct
15
  public void init() throws IOException {
16
- FileInputStream serviceAccount = new FileInputStream("src/main/resources/firebase-service-account.json");
17
 
18
- FirebaseOptions options = FirebaseOptions.builder()
19
- .setCredentials(GoogleCredentials.fromStream(serviceAccount))
20
- .build();
21
 
22
- if (FirebaseApp.getApps().isEmpty()) {
23
- FirebaseApp.initializeApp(options);
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
25
  }
26
 
 
1
  package com.artandscience.security.configuration;
2
 
3
+ import com.artandscience.security.configuration.properties.FirebaseServiceAccountProperty;
4
+ import com.fasterxml.jackson.databind.ObjectMapper;
5
  import com.google.auth.oauth2.GoogleCredentials;
6
  import com.google.firebase.FirebaseApp;
7
  import com.google.firebase.FirebaseOptions;
8
  import jakarta.annotation.PostConstruct;
9
+ import lombok.RequiredArgsConstructor;
10
  import org.springframework.stereotype.Component;
11
 
12
+ import java.io.ByteArrayInputStream;
13
  import java.io.FileInputStream;
14
  import java.io.IOException;
15
+ import java.io.InputStream;
16
+ import java.nio.charset.StandardCharsets;
17
 
18
  @Component
19
+ @RequiredArgsConstructor
20
  public class FirebaseConfig {
21
+
22
+ private final FirebaseServiceAccountProperty accountProperty;
23
+
24
  @PostConstruct
25
  public void init() throws IOException {
26
+ if (FirebaseApp.getApps().isEmpty()) {
27
 
28
+ ObjectMapper mapper = new ObjectMapper();
 
 
29
 
30
+ String json = mapper.writeValueAsString(accountProperty);
31
+ json = json.replace("\\\\n", "\n")
32
+ .replace("\\n", "\n");
33
+
34
+
35
+ try (InputStream serviceAccount =
36
+ new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))) {
37
+
38
+ FirebaseOptions options = FirebaseOptions.builder()
39
+ .setCredentials(GoogleCredentials.fromStream(serviceAccount))
40
+ .build();
41
+
42
+ FirebaseApp.initializeApp(options);
43
+ }
44
  }
45
  }
46
 
src/main/java/com/artandscience/security/configuration/properties/FirebaseServiceAccountProperty.java ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.artandscience.security.configuration.properties;
2
+
3
+ import com.fasterxml.jackson.annotation.JsonProperty;
4
+ import lombok.AllArgsConstructor;
5
+ import lombok.Data;
6
+ import lombok.NoArgsConstructor;
7
+ import org.springframework.boot.context.properties.ConfigurationProperties;
8
+ import org.springframework.boot.context.properties.EnableConfigurationProperties;
9
+
10
+
11
+ @EnableConfigurationProperties
12
+ @ConfigurationProperties(prefix = "firebase-service-account-backoffice")
13
+ @Data
14
+ @AllArgsConstructor
15
+ @NoArgsConstructor
16
+ public class FirebaseServiceAccountProperty {
17
+ private String type;
18
+ @JsonProperty("project_id")
19
+ private String projectId;
20
+ @JsonProperty("private_key_id")
21
+ private String privateKeyId;
22
+ @JsonProperty("private_key")
23
+ private String privateKey;
24
+ @JsonProperty("client_email")
25
+ private String clientEmail;
26
+ @JsonProperty("client_id")
27
+ private String client_id;
28
+ @JsonProperty("auth_uri")
29
+ private String authUri;
30
+ @JsonProperty("token_uri")
31
+ private String tokenUri;
32
+ @JsonProperty("auth_provider_x509_cert_url")
33
+ private String authProviderCert;
34
+ @JsonProperty("client_x509_cert_url")
35
+ private String clientCertUrl;
36
+ @JsonProperty("universe_domain")
37
+ private String universeDomain;
38
+
39
+
40
+ }
src/main/resources/application.yml CHANGED
@@ -58,4 +58,18 @@ provider:
58
  security:
59
  jwt:
60
  secret-base64: NTFlZjJlMzIwNTRhYWQxOTI4ZWMzYzAzYWE4ZWM1ZjQ=
61
- messagebox-cache-expire-time: 3444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  security:
59
  jwt:
60
  secret-base64: NTFlZjJlMzIwNTRhYWQxOTI4ZWMzYzAzYWE4ZWM1ZjQ=
61
+ messagebox-cache-expire-time: 3444
62
+
63
+
64
+ firebase-service-account-backoffice:
65
+ type: ${ACCOUNT_TYPE}
66
+ projectId: ${ACCOUNT_PROJECT_ID}
67
+ privateKeyId: ${ACCOUNT_PRIVATE_KEY_ID}
68
+ privateKey: ${ACCOUNT_PRIVATE_KEY}
69
+ clientEmail: ${ACCOUNT_CLIENT_MAIL}
70
+ clientId: ${ACCOUNT_CLIENT_ID}
71
+ authUri: ${ACCOUNT_AUTH_URI}
72
+ tokenUri: ${ACCOUNT_TOKEN_URI}
73
+ authProviderCert: ${ACCOUNT_AUTH_PROVIDER}
74
+ clientCertUrl: ${ACCOUNT_CERT_URL}
75
+ universeDomain: ${ACCOUNT_UNIVERSE_DOMAIN}
src/main/resources/firebase-service-account.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "type": "service_account",
3
- "project_id": "artandscience-28bc1",
4
- "private_key_id": "301b97184ee1865fe8f1c5d51c4f356bcee8c9a4",
5
- "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDmZkfUWY4jrZ5D\nJV+SwVGQa1JOg+ttpgU8MbQF6irnBm0CQX12mTlFzkkqICLppeuLVzrnFM2f6vZy\naIPDfFRmkcp5StKacfx6CHJdcKl8ZgFNa4W0/jBy9pybQkrq8J4GvGTnHAGin2X4\nKO9ibHDRxknxTHRXpsRSKqX+ofglnDnaRlGK8Nui8lJ+0pslClrTEbiwz0EZuA+G\n4bExAofJCNyHDxs/uuW9rJRIRAzvKGtc5hpzyovDHhJVFTFF+Xdh6la10/+c6pLZ\nRbmZ7wqftLlXY4Kmqf8ijawx8znefRSnC8o1PSYSLt+G6Zta/6xHHInbmkOjHHav\nrncBLy6vAgMBAAECggEADXkZswJxqQbaffuBG6hDLsc3270j8H67rtakbyjpM8CE\nC2FTbUxuG8KBmmPUTTl72eNSxhFikBSoLyFX4zL+dIKkbNqO3XBtxTnm0vpnNUET\nZNJoa6CzQ8wsDq0Ei7lgyrmlmBliw+TyWSqu2C1jNsEtSpEGYXT9GGXDqaCrGpFs\nK9lAkrRSgHgmYH9mS5UHN7GHVLDFEsHSPvJuhZQPtzgvoeH3dFHNuqK0byShc52C\nT2V7WAUsQSBZtJaP7QuaCO6OfiRFvdQdVRFKDNLuzyXNX9EsyRigZAVGzoHmwkEj\nkP0PhjpHEaZrT29ZIpRvwiKtVYLpDxA5lAd6qm01gQKBgQD40841ULLEo5cCgTLp\nzXSiPvPISdz0NbkuuMM99IwV9AUB6DVZkpGpNVgNXsdDNKom+tXuaWMGXr7PyZEl\nlF2/NyD6t3ydehcIf03tAAqdtfmFIZkFzDLgiW5ncsZuxhJUCYZoOgnw+QwcpMrB\n5XTS5XNWt4QD03R5qb9/8uhTTwKBgQDtCn0op63v/M0wJrTolgUrE7utImd0YxFG\nPBP8Hqh77TrCWsTu0DaXzcx60XnBdKoQwPwi6LreImoh9u/ufSLLcyFbyVvacopU\n3C8q6eDemWzGH9FJo/8oA3z44K/7XgBk0z0m+oS/wDGiIoYpn2MYNuFtKcnfmIc2\nzPM/SPYWoQKBgQC8ssNao0wu23CVsa0OqYSd1efCKGGrwWIiEHPf9CiYLWnuvE5Z\nE1HrZEzWNt4eFT5EOU0rdDhoiElkApRUT2OYsxILkEKsmf4Fr6VE6hci6vHDCGun\nfefHZ/GV+fCJ6SPVHzQSrpEDcZrBzicFTCGAHgmN5bXzwNQ/v38+ZNPS+QKBgFyl\nn9uXBi3pog0y47yQfj6i/NSjwMnFuse3zZvaI8IkK7YxIg2xRdU5c7WBUFRjk+Du\nfN3sFrWhv9e8m3ScZlAclKo6XnNYF2cplCnytZhrYQ9i+jsNJTpvepYPw9i8mezO\nf3VPrzj/FqcnVUbJbELXmG5BSgzhod+yZVST4NNhAoGBAJvx73WmKVJp9nMULGRP\nILIh7pj0PzAlgCcvM1/Gxbb0E7Hk4hQKUBQ5ILMIrlvXOuzwfLnpclhRPsawtsp+\ncalOvpbgN2slfJqEa45mMA+CVNfNmPqiGEIQ6RcsBuYMQKw/WQ/TrRuBevj0s6FV\nb1pFnzG2/5w/4igCh8Ghd6J8\n-----END PRIVATE KEY-----\n",
6
- "client_email": "firebase-adminsdk-fbsvc@artandscience-28bc1.iam.gserviceaccount.com",
7
- "client_id": "118180198786448750544",
8
- "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
- "token_uri": "https://oauth2.googleapis.com/token",
10
- "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
- "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40artandscience-28bc1.iam.gserviceaccount.com",
12
- "universe_domain": "googleapis.com"
13
- }