-
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.
Co-authored-by: Tim Ortel <[email protected]> Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e62d918
commit c5cf7e3
Showing
24 changed files
with
816 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM openjdk:17 | ||
WORKDIR /. | ||
COPY hermes/build/libs/hermes-0.0.1-SNAPSHOT.jar ./app.jar | ||
|
||
ENTRYPOINT ["java", "-jar", "./app.jar"] |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' | ||
id 'io.spring.dependency-management' | ||
} | ||
|
||
group = 'de.tum.cit.artemis.push.artemispushnotificationrelay' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '17' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
|
||
implementation 'com.eatthepath:pushy:0.15.2' | ||
|
||
implementation 'javax.annotation:javax.annotation-api:1.3.2' | ||
|
||
implementation(project(":common")) | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} |
101 changes: 101 additions & 0 deletions
101
.../main/java/de/tum/cit/artemis/push/artemispushnotificationrelay/apns/ApnsSendService.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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package de.tum.cit.artemis.push.artemispushnotificationrelay.apns; | ||
|
||
import com.eatthepath.pushy.apns.*; | ||
import com.eatthepath.pushy.apns.util.SimpleApnsPayloadBuilder; | ||
import com.eatthepath.pushy.apns.util.SimpleApnsPushNotification; | ||
import com.eatthepath.pushy.apns.util.concurrent.PushNotificationFuture; | ||
import de.tum.cit.artemis.push.artemispushnotificationrelay.common.NotificationRequest; | ||
import de.tum.cit.artemis.push.artemispushnotificationrelay.common.SendService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
@Service | ||
public class ApnsSendService implements SendService<NotificationRequest> { | ||
|
||
@Value("${APNS_CERTIFICATE_PATH: #{null}}") | ||
private String apnsCertificatePath; | ||
@Value("${APNS_CERTIFICATE_PWD: #{null}}") | ||
private String apnsCertificatePwd; | ||
|
||
@Value("${APNS_PROD_ENVIRONMENT: #{false}}") | ||
private Boolean apnsProdEnvironment = false; | ||
|
||
private final Logger log = LoggerFactory.getLogger(ApnsSendService.class); | ||
private ApnsClient apnsClient; | ||
|
||
@PostConstruct | ||
public void initialize() { | ||
log.info("apnsCertificatePwd: " + apnsCertificatePwd); | ||
log.info("apnsCertificatePath: " + apnsCertificatePath); | ||
log.info("apnsProdEnvironment: " + apnsProdEnvironment); | ||
if (apnsCertificatePwd == null || apnsCertificatePath == null || apnsProdEnvironment == null) { | ||
log.error("Could not init APNS service. Certificate information missing."); | ||
return; | ||
} | ||
try { | ||
apnsClient = new ApnsClientBuilder() | ||
.setApnsServer(apnsProdEnvironment ? ApnsClientBuilder.PRODUCTION_APNS_HOST : ApnsClientBuilder.DEVELOPMENT_APNS_HOST) | ||
.setClientCredentials(new File(apnsCertificatePath), apnsCertificatePwd) | ||
.build(); | ||
log.info("Started APNS client successfully!"); | ||
} catch (IOException e) { | ||
log.error("Could not init APNS service", e); | ||
} | ||
} | ||
|
||
@Override | ||
public ResponseEntity<Void> send(NotificationRequest request) { | ||
return sendApnsRequest(request); | ||
} | ||
|
||
@Async | ||
ResponseEntity<Void> sendApnsRequest(NotificationRequest request) { | ||
String payload = new SimpleApnsPayloadBuilder() | ||
.setContentAvailable(true) | ||
.addCustomProperty("iv", request.getInitializationVector()) | ||
.addCustomProperty("payload", request.getPayloadCipherText()) | ||
.build(); | ||
|
||
SimpleApnsPushNotification notification = new SimpleApnsPushNotification(request.getToken(), | ||
"de.tum.cit.artemis", | ||
payload, | ||
Instant.now().plus(Duration.ofDays(7)), | ||
DeliveryPriority.getFromCode(5), | ||
PushType.BACKGROUND); | ||
|
||
|
||
PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> responsePushNotificationFuture = apnsClient.sendNotification(notification); | ||
try { | ||
final PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse = | ||
responsePushNotificationFuture.get(); | ||
if (pushNotificationResponse.isAccepted()) { | ||
log.info("Send notification to " + request.getToken()); | ||
return ResponseEntity.ok().build(); | ||
} else { | ||
log.error("Notification rejected by the APNs gateway: " + | ||
pushNotificationResponse.getRejectionReason()); | ||
|
||
pushNotificationResponse.getTokenInvalidationTimestamp().ifPresent(timestamp -> { | ||
log.error("\t…and the token is invalid as of " + timestamp); | ||
}); | ||
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).build(); | ||
} | ||
} catch (ExecutionException | InterruptedException e) { | ||
log.error("Failed to send push notification."); | ||
e.printStackTrace(); | ||
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).build(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
} | ||
|
||
plugins { | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
mavenCentral() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' | ||
id 'io.spring.dependency-management' | ||
} | ||
|
||
group = 'de.tum.cit.artemis.push.artemispushnotificationrelay' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '17' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} |
25 changes: 25 additions & 0 deletions
25
...java/de/tum/cit/artemis/push/artemispushnotificationrelay/common/NotificationRequest.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package de.tum.cit.artemis.push.artemispushnotificationrelay.common; | ||
|
||
public class NotificationRequest { | ||
private final String initializationVector; | ||
private final String payloadCipherText; | ||
private final String token; | ||
|
||
public NotificationRequest(String initializationVector, String payloadCipherText, String token) { | ||
this.initializationVector = initializationVector; | ||
this.payloadCipherText = payloadCipherText; | ||
this.token = token; | ||
} | ||
|
||
public String getInitializationVector() { | ||
return initializationVector; | ||
} | ||
|
||
public String getPayloadCipherText() { | ||
return payloadCipherText; | ||
} | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...rc/main/java/de/tum/cit/artemis/push/artemispushnotificationrelay/common/SendService.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package de.tum.cit.artemis.push.artemispushnotificationrelay.common; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
|
||
public interface SendService<T> { | ||
|
||
ResponseEntity<Void> send(T request); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: '3' | ||
services: | ||
hermes: | ||
# either build image with run.sh before running or adapt image to point to Docker Hub: e.g. sven0311tum/hermes:latest | ||
image: hermes | ||
container_name: hermes | ||
ports: | ||
- "17333:8080" | ||
environment: | ||
- APNS_CERTIFICATE_PATH=/key/artemis-apns.p12 | ||
# adapt the following line | ||
- APNS_CERTIFICATE_PWD=<pwd_for_certificate> | ||
- APNS_PROD_ENVIRONMENT=false | ||
- GOOGLE_APPLICATION_CREDENTIALS=/firebase.json | ||
volumes: | ||
# adapt the following lines | ||
- <path_to_apns_certificate>:/key/artemis-apns.p12 | ||
- <path_to_google_credentials_json>:/firebase.json | ||
restart: on-failure |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' | ||
id 'io.spring.dependency-management' | ||
} | ||
|
||
group = 'de.tum.cit.artemis.push.artemispushnotificationrelay' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '17' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
|
||
implementation "com.google.firebase:firebase-admin:9.1.1" | ||
implementation(project(":common")) | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} |
10 changes: 10 additions & 0 deletions
10
...emis/push/artemispushnotificationrelay/firebase/FirebaseSendPushNotificationsRequest.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.tum.cit.artemis.push.artemispushnotificationrelay.firebase; | ||
|
||
import de.tum.cit.artemis.push.artemispushnotificationrelay.common.NotificationRequest; | ||
|
||
import java.util.List; | ||
|
||
public record FirebaseSendPushNotificationsRequest( | ||
List<NotificationRequest> notificationRequest | ||
) { | ||
} |
Oops, something went wrong.