Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Enforce the admin lock when deleting an integration config (#7850)

Anthony Stirlingb58f31f15d70
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/integration/service/IntegrationConfigService.java b/app/proprietary/src/main/java/stirling/software/proprietary/integration/service/IntegrationConfigService.java
index a29ac2c08f..ea95556155 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/integration/service/IntegrationConfigService.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/integration/service/IntegrationConfigService.java
@@ -167,6 +167,9 @@ public class IntegrationConfigService {
if (!ownership.canManage(TYPE, cfg, currentUser)) {
throw forbidden("You cannot manage this integration");
}
+ if (cfg.isLocked() && !ownership.isAdmin(currentUser)) {
+ throw forbidden("This integration is locked by an administrator");
+ }
// Refuse to pull a connection out from under whatever still references it.
List<String> usages =
usageChecks.stream()
diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/integration/service/IntegrationConfigServiceTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/integration/service/IntegrationConfigServiceTest.java
index 90842612d1..31a9a45339 100644
--- a/app/proprietary/src/test/java/stirling/software/proprietary/integration/service/IntegrationConfigServiceTest.java
+++ b/app/proprietary/src/test/java/stirling/software/proprietary/integration/service/IntegrationConfigServiceTest.java
@@ -195,6 +195,37 @@ class IntegrationConfigServiceTest {
verify(repository, org.mockito.Mockito.never()).delete(any(IntegrationConfig.class));
}
+ @Test
+ void deleteRefusedOnLockedConfigForNonAdmin() {
+ IntegrationConfig cfg = config(9L);
+ cfg.setLocked(true);
+ when(repository.findById(9L)).thenReturn(Optional.of(cfg));
+ when(ownership.canManage(any(), eq(cfg), any())).thenReturn(true);
+ when(ownership.isAdmin(any())).thenReturn(false);
+
+ assertThatThrownBy(() -> service.delete(9L, user(7)))
+ .isInstanceOf(ResponseStatusException.class)
+ .satisfies(
+ e ->
+ assertThat(((ResponseStatusException) e).getStatusCode())
+ .isEqualTo(HttpStatus.FORBIDDEN));
+ verify(repository, org.mockito.Mockito.never()).delete(any(IntegrationConfig.class));
+ }
+
+ @Test
+ void deleteAllowedOnLockedConfigForAdmin() {
+ IntegrationConfig cfg = config(9L);
+ cfg.setLocked(true);
+ when(repository.findById(9L)).thenReturn(Optional.of(cfg));
+ when(ownership.canManage(any(), eq(cfg), any())).thenReturn(true);
+ when(ownership.isAdmin(any())).thenReturn(true);
+ when(usageCheck.usagesOf(9L)).thenReturn(List.of());
+
+ service.delete(9L, user(7));
+
+ verify(repository).delete(cfg);
+ }
+
@Test
void createDelegatesOwnershipAndSanitizesConfig() {
when(secretMasker.sanitize(any())).thenReturn(Map.of("bucket", "b"));