-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6769b7c
commit 00009c9
Showing
5 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 57 additions & 2 deletions
59
src/main/java/com/mapeando/territory/TerritoryApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,69 @@ | ||
package com.mapeando.territory; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import com.google.gson.Gson; | ||
import com.mapeando.territory.config.FirebaseConfig; | ||
import com.mapeando.territory.config.FirebaseInterceptor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class TerritoryApplication { | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
// ... | ||
|
||
@SpringBootApplication | ||
@ComponentScan(basePackages = {"com.mapeando.territory", "com.mapeando.territory.config"}) | ||
public class TerritoryApplication implements WebMvcConfigurer { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(TerritoryApplication.class, args); | ||
|
||
} | ||
|
||
@Autowired | ||
private FirebaseConfig firebaseConfig; | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry){ | ||
registry.addInterceptor(new FirebaseInterceptor()).addPathPatterns("territory/create"); | ||
registry.addInterceptor(new FirebaseInterceptor()).addPathPatterns("territory/update/{territoryId}"); | ||
registry.addInterceptor(new FirebaseInterceptor()).addPathPatterns("territory/delete/{id}"); | ||
|
||
} | ||
|
||
@Bean | ||
public FirebaseOptions firebaseOptions() throws IOException { | ||
|
||
byte[] serviceAccountBytes = convertFirebaseConfigToJson(firebaseConfig).getBytes(); | ||
|
||
ByteArrayInputStream serviceAccountStream = new ByteArrayInputStream(serviceAccountBytes); | ||
|
||
return new FirebaseOptions.Builder() | ||
.setCredentials(GoogleCredentials.fromStream(serviceAccountStream)) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public FirebaseApp firebaseApp(FirebaseOptions firebaseOptions) { | ||
if (FirebaseApp.getApps().isEmpty()) { | ||
return FirebaseApp.initializeApp(firebaseOptions); | ||
} | ||
|
||
return FirebaseApp.getInstance(); | ||
} | ||
|
||
private String convertFirebaseConfigToJson(FirebaseConfig config) { | ||
Gson gson = new Gson(); | ||
config.setPrivate_key(config.getPrivate_key()); | ||
return gson.toJson(config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
spring.data.mongodb.uri=${MONGODB_URI} | ||
|
||
# Firebase Configuration | ||
firebase.type=${FIREBASE_TYPE} | ||
firebase.project_id=${FIREBASE_PROJECT_ID} | ||
firebase.private_key_id=${FIREBASE_PRIVATE_KEY_ID} | ||
firebase.private_key=${FIREBASE_PRIVATE_KEY} | ||
firebase.client_email=${FIREBASE_CLIENT_EMAIL} | ||
firebase.client_id=${FIREBASE_CLIENT_ID} | ||
firebase.auth_uri=${FIREBASE_AUTH_URI} | ||
firebase.token_uri=${FIREBASE_TOKEN_URI} | ||
firebase.auth_provider_x509_cert_url=${FIREBASE_AUTH_PROVIDER_X509_CERT_URL} | ||
firebase.client_x509_cert_url=${FIREBASE_CLIENT_X509_CERT_URL} | ||
firebase.universe_domain=${FIREBASE_UNIVERSE_DOMAIN} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters