Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook Authentication For WebRTC Play #6281

Merged
merged 10 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/io/antmedia/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,13 @@ public boolean isWriteStatsToDatastore() {
@Value("${webhookRetryAttemptDelay:1000}")
private long webhookRetryDelay = 1000;

/**
* Webhook webrtc play authentication url.
*/
@Value("${webhookPlayAuthUrl:#{null}}")
private String webhookPlayAuthUrl;


public void setWriteStatsToDatastore(boolean writeStatsToDatastore) {
this.writeStatsToDatastore = writeStatsToDatastore;
}
Expand Down Expand Up @@ -3694,6 +3701,18 @@ public void setWebhookRetryDelay(long webhookRetryDelay) {
this.webhookRetryDelay = webhookRetryDelay;
}

public boolean isWebhookPlayAuthEnabled() {
return getWebhookPlayAuthUrl() != null && !getWebhookPlayAuthUrl().isEmpty();
}

public String getWebhookPlayAuthUrl() {
return webhookPlayAuthUrl;
}

public void setWebhookPlayAuthUrl(String webhookPlayAuthUrl) {
this.webhookPlayAuthUrl = webhookPlayAuthUrl;
}

public boolean isSecureAnalyticEndpoint() {
return secureAnalyticEndpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public synchronized boolean isPublishAllowed(IScope scope, String streamId, Stri
if (appSettings == null){
appSettings = (AppSettings) scope.getContext().getBean(AppSettings.BEAN_NAME);
}
final String webhookAuthURL = appSettings.getWebhookAuthenticateURL();
if (webhookAuthURL != null && !webhookAuthURL.isEmpty())
final String publishWebhookAuthURL = appSettings.getWebhookAuthenticateURL();
if (publishWebhookAuthURL != null && !publishWebhookAuthURL.isEmpty())
{
try (CloseableHttpClient client = getHttpClient())
{
Expand All @@ -61,7 +61,7 @@ public synchronized boolean isPublishAllowed(IScope scope, String streamId, Stri

RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(2 * 1000).setSocketTimeout(5*1000).build();

HttpRequestBase post = (HttpRequestBase) RequestBuilder.post().setUri(webhookAuthURL)
HttpRequestBase post = (HttpRequestBase) RequestBuilder.post().setUri(publishWebhookAuthURL)
.setHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.setEntity(new StringEntity(instance.toString())).build();
post.setConfig(requestConfig);
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/io/antmedia/test/AppSettingsUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ public void testSettings() {
appSettings.setWebhookRetryDelay(webHookRetryDelay);
assertEquals(webHookRetryDelay, appSettings.getWebhookRetryDelay());

String webhookPlayAuthUrl = "playAuthUrl";
appSettings.setWebhookPlayAuthUrl(webhookPlayAuthUrl);
assertEquals(webhookPlayAuthUrl, appSettings.getWebhookPlayAuthUrl());

}


Expand Down Expand Up @@ -532,7 +536,7 @@ public void testUnsetAppSettings(AppSettings appSettings) {
assertNull(appSettings.getTimeTokenSecretForPublish());
assertNull(appSettings.getTimeTokenSecretForPlay());

assertEquals(true, appSettings.isHwScalingEnabled());
assertTrue(appSettings.isHwScalingEnabled());

assertNotNull(appSettings.getSubscriberAuthenticationKey());
assertNull(appSettings.getFirebaseAccountKeyJSON());
Expand All @@ -549,12 +553,15 @@ public void testUnsetAppSettings(AppSettings appSettings) {
assertFalse(appSettings.isSecureAnalyticEndpoint());
assertEquals("mpegts", appSettings.getHlsSegmentType());

assertFalse(appSettings.isWebhookPlayAuthEnabled());
assertNull(appSettings.getWebhookPlayAuthUrl());

//if we add a new field, we just need to check its default value in this test
//When a new field is added or removed please update the number of fields and make this test pass
//by also checking its default value.

assertEquals("New field is added to settings. PAY ATTENTION: Please CHECK ITS DEFAULT VALUE and fix the number of fields.",
180, numberOfFields);
181, numberOfFields);


}
Expand Down